Commit 983011c5 authored by xc's avatar xc

shiro 登录报错

parent a74e8884
package cn.wisenergy.service.shir.util; package cn.wisenergy.service.shir.util;
import cn.wisenergy.service.util.UserToken; import cn.wisenergy.service.util.UserToken;
import com.itextpdf.text.log.Logger; import lombok.extern.slf4j.Slf4j;
import com.itextpdf.text.log.LoggerFactory;
import org.apache.shiro.authc.AuthenticationException; import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.AuthenticationInfo; import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken; import org.apache.shiro.authc.AuthenticationToken;
...@@ -12,13 +11,13 @@ import org.apache.shiro.realm.Realm; ...@@ -12,13 +11,13 @@ import org.apache.shiro.realm.Realm;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
@Slf4j
public class UserModularRealmAuthenticator extends ModularRealmAuthenticator { public class UserModularRealmAuthenticator extends ModularRealmAuthenticator {
private static final Logger logger = LoggerFactory.getLogger(UserModularRealmAuthenticator.class);
@Override @Override
protected AuthenticationInfo doAuthenticate(AuthenticationToken authenticationToken) protected AuthenticationInfo doAuthenticate(AuthenticationToken authenticationToken)
throws AuthenticationException { throws AuthenticationException {
logger.info("UserModularRealmAuthenticator:method doAuthenticate() execute "); log.info("UserModularRealmAuthenticator:method doAuthenticate() execute ");
// 判断getRealms()是否返回为空 // 判断getRealms()是否返回为空
assertRealmsConfigured(); assertRealmsConfigured();
// 强制转换回自定义的CustomizedToken // 强制转换回自定义的CustomizedToken
...@@ -30,17 +29,17 @@ public class UserModularRealmAuthenticator extends ModularRealmAuthenticator { ...@@ -30,17 +29,17 @@ public class UserModularRealmAuthenticator extends ModularRealmAuthenticator {
// 登录类型对应的所有Realm // 登录类型对应的所有Realm
Collection<Realm> typeRealms = new ArrayList<>(); Collection<Realm> typeRealms = new ArrayList<>();
for (Realm realm : realms) { for (Realm realm : realms) {
if (realm.getName().contains(loginType)); if (realm.getName().toLowerCase().contains(loginType.toLowerCase())){
typeRealms.add(realm); typeRealms.add(realm);
}
} }
// 判断是单Realm还是多Realm // 判断是单Realm还是多Realm
if (typeRealms.size() == 1){ if (typeRealms.size() == 1){
logger.info("doSingleRealmAuthentication() execute "); log.info("doSingleRealmAuthentication() execute ");
return doSingleRealmAuthentication(((ArrayList<Realm>) typeRealms).get(0), userToken); return doSingleRealmAuthentication(((ArrayList<Realm>) typeRealms).get(0), userToken);
} }else{
else{ log.info("doMultiRealmAuthentication() execute ");
logger.info("doMultiRealmAuthentication() execute ");
return doMultiRealmAuthentication(typeRealms, userToken); return doMultiRealmAuthentication(typeRealms, userToken);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment