Pārlūkot izejas kodu

优化shiro配置

zhouhao 8 gadi atpakaļ
vecāks
revīzija
24f4753cd4

+ 4 - 5
hsweb-authorization/hsweb-authorization-shiro/src/main/java/org/hswebframework/web/authorization/shiro/ListenerAuthorizingRealm.java

@@ -41,7 +41,7 @@ import java.util.stream.Collectors;
 public class ListenerAuthorizingRealm extends AuthorizingRealm implements UserAuthorizationListener {
 
     public ListenerAuthorizingRealm() {
-        setAuthenticationTokenClass(CustomAuthenticationToken.class);
+        setAuthenticationTokenClass(SimpleAuthenticationToken.class);
     }
 
     @Override
@@ -53,7 +53,7 @@ public class ListenerAuthorizingRealm extends AuthorizingRealm implements UserAu
 
     @Override
     protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
-        if (token instanceof CustomAuthenticationToken) {
+        if (token instanceof SimpleAuthenticationToken) {
             return this.<String, AuthenticationInfo>getCache((String) token.getPrincipal())
                     .get(AuthenticationInfo.class.getName());
         }
@@ -63,8 +63,7 @@ public class ListenerAuthorizingRealm extends AuthorizingRealm implements UserAu
     private AuthenticationInfo createAuthenticationInfo(Authorization authorization) {
         return new SimpleAuthenticationInfo(
                 authorization.getUser().getUsername(),
-                authorization.getUser().getId(),
-                authorization.getUser().getName());
+                authorization.getUser().getId(), ListenerAuthorizingRealm.class.getName());
     }
 
     @Override
@@ -96,7 +95,7 @@ public class ListenerAuthorizingRealm extends AuthorizingRealm implements UserAu
                 .put(AuthenticationInfo.class.getName(), createAuthenticationInfo(authorization));
 
         Subject subject = SecurityUtils.getSubject();
-        subject.login(new CustomAuthenticationToken(authorization, isRemembered));
+        subject.login(new SimpleAuthenticationToken(authorization, isRemembered));
         subject.getSession().setAttribute(Authorization.class.getName(), authorization);
     }
 

+ 2 - 2
hsweb-authorization/hsweb-authorization-shiro/src/main/java/org/hswebframework/web/authorization/shiro/CustomAuthenticationToken.java

@@ -27,14 +27,14 @@ import org.hswebframework.web.authorization.Authorization;
  *
  * @author zhouhao
  */
-public class CustomAuthenticationToken implements AuthenticationToken, HostAuthenticationToken, RememberMeAuthenticationToken {
+public class SimpleAuthenticationToken implements AuthenticationToken, HostAuthenticationToken, RememberMeAuthenticationToken {
     private Authorization authorization;
 
     private boolean rememberMe;
 
     private String host;
 
-    public CustomAuthenticationToken(Authorization authorization, boolean rememberMe) {
+    public SimpleAuthenticationToken(Authorization authorization, boolean rememberMe) {
         this.authorization = authorization;
         this.rememberMe = rememberMe;
     }