|  |  |  | 
|---|
|  |  |  | import doumeemes.core.exception.BusinessException; | 
|---|
|  |  |  | import doumeemes.core.model.LoginUserInfo; | 
|---|
|  |  |  | import doumeemes.core.utils.Constants; | 
|---|
|  |  |  | import doumeemes.dao.business.model.Company; | 
|---|
|  |  |  | import doumeemes.dao.business.model.CompanyUser; | 
|---|
|  |  |  | import doumeemes.dao.business.model.Department; | 
|---|
|  |  |  | import doumeemes.dao.ext.dto.QueryCompanyUserExtDTO; | 
|---|
|  |  |  | import doumeemes.dao.ext.vo.CompanyExtListVO; | 
|---|
|  |  |  | import doumeemes.dao.ext.vo.CompanyUserExtListVO; | 
|---|
|  |  |  | 
|---|
|  |  |  | import doumeemes.dao.system.model.SystemPermission; | 
|---|
|  |  |  | import doumeemes.dao.system.model.SystemRole; | 
|---|
|  |  |  | import doumeemes.dao.system.model.SystemUser; | 
|---|
|  |  |  | import doumeemes.service.business.CompanyUserService; | 
|---|
|  |  |  | import doumeemes.service.ext.CompanyExtService; | 
|---|
|  |  |  | import doumeemes.service.ext.CompanyUserExtService; | 
|---|
|  |  |  | import doumeemes.service.ext.DepartmentExtService; | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.util.Date; | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  | import java.util.Objects; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 自定义Realm,处理认证和权限 | 
|---|
|  |  |  | * @author Eva.Caesar Liu | 
|---|
|  |  |  | * @date 2022/04/18 18:12 | 
|---|
|  |  |  | * @date 2022/03/15 09:54 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Component | 
|---|
|  |  |  | public class ShiroRealm extends AuthorizingRealm { | 
|---|
|  |  |  | 
|---|
|  |  |  | private DepartmentExtService departmentExtService; | 
|---|
|  |  |  | @Lazy | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private SystemDataPermissionService  systemDataPermissionService; | 
|---|
|  |  |  | private SystemDataPermissionService systemDataPermissionService; | 
|---|
|  |  |  | @Lazy | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private CompanyExtService companyExtService; | 
|---|
|  |  |  | 
|---|
|  |  |  | @Lazy | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private SystemPermissionService systemPermissionService; | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 重写supports方法,使 Shiro 能够识别自定义的 Token | 
|---|
|  |  |  | * @param token | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public boolean supports(AuthenticationToken token) { | 
|---|
|  |  |  | return token instanceof ShiroToken; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 权限处理 | 
|---|
|  |  |  | * @author Eva.Caesar Liu | 
|---|
|  |  |  | * @date 2022/04/18 18:12 | 
|---|
|  |  |  | * @date 2022/03/15 09:54 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) { | 
|---|
|  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 认证处理 | 
|---|
|  |  |  | * @author Eva.Caesar Liu | 
|---|
|  |  |  | * @date 2022/04/18 18:12 | 
|---|
|  |  |  | * @date 2022/03/15 09:54 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException,BusinessException { | 
|---|
|  |  |  | protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException { | 
|---|
|  |  |  | // 获取用户名 | 
|---|
|  |  |  | ShiroToken authenticationToken =(ShiroToken) token; | 
|---|
|  |  |  | String username = authenticationToken.getPrincipal().toString(); | 
|---|
|  |  |  | 
|---|
|  |  |  | per.setType(Constants.PlatType.admin); | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | if(authenticationToken.getCompanyId() == null){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,该账户异常!"); | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,该账户删除!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | com = companyExtService.getModelById(authenticationToken.getCompanyId()); | 
|---|
|  |  |  | if(com == null){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"对不起,该账户异常!"); | 
|---|
|  |  |  | if(com == null || Constants.equalsInteger( com.getDeleted(),Constants.ONE)){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"对不起,该账户删除!请联系管理员"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(Constants.equalsInteger( com.getStatus(),Constants.ZERO) ){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"对不起,该企业已禁用!"); | 
|---|