Ver código fonte

扩展AccessEntity增加getLogName方法,方便应用扩展修改日志中的CALLER信息记录内容

Signed-off-by: luoshi <luoshi@qmth.com.cn>
luoshi 2 anos atrás
pai
commit
8a25950901

+ 9 - 0
core-security/src/main/java/com/qmth/boot/core/security/model/AccessEntity.java

@@ -21,6 +21,15 @@ public interface AccessEntity {
      */
     String getSecret();
 
+    /**
+     * 记录到日志中的访问者信息,默认取identity内容
+     *
+     * @return
+     */
+    default String getLogName() {
+        return getIdentity();
+    }
+
     /**
      * 允许访问的IP
      *

+ 1 - 1
starter-api/src/main/java/com/qmth/boot/api/interceptor/impl/AuthorizationInterceptor.java

@@ -43,7 +43,7 @@ public class AuthorizationInterceptor extends AbstractInterceptor implements Log
                 request.setAttribute(StringUtils.uncapitalize(entity.getClass().getSimpleName()), entity);
                 // 默认取签名标识作为接口访问者标识
                 if (request.getAttribute(ATTRIBUTE_CALLER) == null) {
-                    request.setAttribute(ATTRIBUTE_CALLER, entity.getIdentity());
+                    request.setAttribute(ATTRIBUTE_CALLER, entity.getLogName());
                 }
             } catch (AuthorizationException ae) {
                 log.warn("Authorization faile: path={}, reason={}", request.getServletPath(), ae.getMessage());