|
|
@@ -1,6 +1,16 @@
|
|
|
package com.railway.framework.shiro.realm;
|
|
|
|
|
|
-import java.util.HashSet;
|
|
|
+import com.railway.common.core.domain.entity.SysUser;
|
|
|
+import com.railway.common.exception.user.CaptchaException;
|
|
|
+import com.railway.common.exception.user.RoleBlockedException;
|
|
|
+import com.railway.common.exception.user.UserBlockedException;
|
|
|
+import com.railway.common.exception.user.UserNotExistsException;
|
|
|
+import com.railway.common.exception.user.UserPasswordNotMatchException;
|
|
|
+import com.railway.common.exception.user.UserPasswordRetryLimitExceedException;
|
|
|
+import com.railway.common.utils.ShiroUtils;
|
|
|
+import com.railway.framework.shiro.service.SysLoginService;
|
|
|
+import com.railway.system.service.ISysMenuService;
|
|
|
+import com.railway.system.service.ISysRoleService;
|
|
|
import java.util.Set;
|
|
|
import org.apache.shiro.authc.AuthenticationException;
|
|
|
import org.apache.shiro.authc.AuthenticationInfo;
|
|
|
@@ -20,17 +30,6 @@ import org.apache.shiro.subject.SimplePrincipalCollection;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import com.railway.common.core.domain.entity.SysUser;
|
|
|
-import com.railway.common.exception.user.CaptchaException;
|
|
|
-import com.railway.common.exception.user.RoleBlockedException;
|
|
|
-import com.railway.common.exception.user.UserBlockedException;
|
|
|
-import com.railway.common.exception.user.UserNotExistsException;
|
|
|
-import com.railway.common.exception.user.UserPasswordNotMatchException;
|
|
|
-import com.railway.common.exception.user.UserPasswordRetryLimitExceedException;
|
|
|
-import com.railway.common.utils.ShiroUtils;
|
|
|
-import com.railway.framework.shiro.service.SysLoginService;
|
|
|
-import com.railway.system.service.ISysMenuService;
|
|
|
-import com.railway.system.service.ISysRoleService;
|
|
|
|
|
|
/**
|
|
|
* 自定义Realm 处理登录 权限
|
|
|
@@ -57,9 +56,9 @@ public class UserRealm extends AuthorizingRealm {
|
|
|
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection arg0) {
|
|
|
SysUser user = ShiroUtils.getSysUser();
|
|
|
// 角色列表
|
|
|
- Set<String> roles = new HashSet<String>();
|
|
|
+ Set<String> roles;
|
|
|
// 功能列表
|
|
|
- Set<String> menus = new HashSet<String>();
|
|
|
+ Set<String> menus;
|
|
|
SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
|
|
|
// 管理员拥有所有权限
|
|
|
if (user.isAdmin()) {
|
|
|
@@ -89,7 +88,7 @@ public class UserRealm extends AuthorizingRealm {
|
|
|
password = new String(upToken.getPassword());
|
|
|
}
|
|
|
|
|
|
- SysUser user = null;
|
|
|
+ SysUser user;
|
|
|
try {
|
|
|
user = loginService.login(username, password);
|
|
|
} catch (CaptchaException e) {
|
|
|
@@ -100,16 +99,13 @@ public class UserRealm extends AuthorizingRealm {
|
|
|
throw new IncorrectCredentialsException(e.getMessage(), e);
|
|
|
} catch (UserPasswordRetryLimitExceedException e) {
|
|
|
throw new ExcessiveAttemptsException(e.getMessage(), e);
|
|
|
- } catch (UserBlockedException e) {
|
|
|
- throw new LockedAccountException(e.getMessage(), e);
|
|
|
- } catch (RoleBlockedException e) {
|
|
|
+ } catch (UserBlockedException | RoleBlockedException e) {
|
|
|
throw new LockedAccountException(e.getMessage(), e);
|
|
|
} catch (Exception e) {
|
|
|
log.info("对用户[" + username + "]进行登录验证..验证未通过{}", e.getMessage());
|
|
|
throw new AuthenticationException(e.getMessage(), e);
|
|
|
}
|
|
|
- SimpleAuthenticationInfo info = new SimpleAuthenticationInfo(user, password, getName());
|
|
|
- return info;
|
|
|
+ return new SimpleAuthenticationInfo(user, password, getName());
|
|
|
}
|
|
|
|
|
|
/**
|