ÎļþÃû´Ó server/company/src/main/java/com/doumee/config/shiro/ShiroRealm.java ÐÞ¸Ä |
| | |
| | | import com.doumee.core.exception.BusinessException; |
| | | import com.doumee.core.model.LoginUserInfo; |
| | | import com.doumee.core.utils.Constants; |
| | | import com.doumee.core.utils.DateUtil; |
| | | import com.doumee.dao.business.model.Company; |
| | | import com.doumee.dao.business.model.CompanyPermission; |
| | | import com.doumee.dao.system.model.SystemPermission; |
| | | import com.doumee.dao.system.model.SystemRole; |
| | | import com.doumee.dao.system.model.SystemUser; |
| | | import com.doumee.service.business.CompanyService; |
| | | import com.doumee.service.business.CompanyPermissionService; |
| | | import com.doumee.service.business.impl.CompanyServiceImpl; |
| | | import com.doumee.service.system.SystemDataPermissionService; |
| | | import com.doumee.service.system.SystemPermissionService; |
| | | import com.doumee.service.system.SystemRoleService; |
| | |
| | | import org.springframework.context.annotation.Lazy; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.util.Date; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | /** |
| | |
| | | @Lazy |
| | | @Autowired |
| | | private SystemUserService systemUserService; |
| | | @Lazy |
| | | @Autowired |
| | | private CompanyPermissionService companyPermissionService; |
| | | @Lazy |
| | | @Autowired |
| | | private CompanyServiceImpl companyService; |
| | | |
| | | @Lazy |
| | | @Autowired |
| | |
| | | @Lazy |
| | | @Autowired |
| | | private SystemPermissionService systemPermissionService; |
| | | |
| | | @Lazy |
| | | @Autowired |
| | | private CompanyService companyService; |
| | | |
| | | /** |
| | | * æéå¤ç |
| | |
| | | * @date 2022/03/15 09:54 |
| | | */ |
| | | @Override |
| | | protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException{ |
| | | protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException { |
| | | // è·åç¨æ·å |
| | | ShiroToken authenticationToken = (ShiroToken)token; |
| | | String username = authenticationToken.getPrincipal().toString(); |
| | | // æ ¹æ®ç¨æ·åæ¥è¯¢ç¨æ·å¯¹è±¡ |
| | | SystemUser queryDto = new SystemUser(); |
| | | queryDto.setUsername(username); |
| | | if(authenticationToken.isNeedPassword()){ |
| | | //è´¦å·å¯ç ç»å½ |
| | | queryDto.setUsername(username); |
| | | }else{ |
| | | //ææºå·éªè¯ç ç»å½ |
| | | queryDto.setMobile(username); |
| | | } |
| | | queryDto.setType(authenticationToken.getUserType()); |
| | | queryDto.setDeleted(Boolean.FALSE); |
| | | SystemUser user = systemUserService.findOne(queryDto); |
| | | if(user == null){ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"对ä¸èµ·ï¼è´¦å·æå¯ç 䏿£ç¡®ï¼"); |
| | | } |
| | | if(!Constants.equalsInteger(user.getType(),Constants.UserType.COMPANY.getKey())){ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"对ä¸èµ·ï¼éä¼ä¸è´¦æ·èº«ä»½ï¼æ æ³ç»å½è¯¥å¹³å°ï¼ï¼"); |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"对ä¸èµ·ï¼è´¦å·ä¿¡æ¯ä¸æ£ç¡®ï¼"); |
| | | } |
| | | if(!Constants.equalsInteger(user.getStatus(),Constants.ZERO)){ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"对ä¸èµ·ï¼è´¦å·ä¿¡æ¯å·²è¢«ç¦ç¨ï¼å¦æçé®è¯·è系系ç»ç®¡çåï¼"); |
| | | } |
| | | if(!user.getType().equals(Constants.UserType.SYSTEM)){ |
| | | Company company = companyService.findById(user.getCompanyId()); |
| | | if(company.getStatus().equals(Constants.ONE)){ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"对ä¸èµ·ï¼ä¼ä¸ä¿¡æ¯å·²è¢«ç¦ç¨ï¼å¦æçé®è¯·è系系ç»ç®¡çåï¼"); |
| | | } |
| | | user.setCompany(company); |
| | | } |
| | | // è·åç»å½ç¨æ·ä¿¡æ¯ |
| | | List<SystemRole> roles = systemRoleService.findByUserId(user.getId()); |
| | | List<SystemPermission> permissions = systemPermissionService.findByUserId(user.getId()); |
| | | LoginUserInfo userInfo = LoginUserInfo.from(user, roles, permissions); |
| | | if(authenticationToken.getUserType() == 0){ |
| | | CompanyPermission c = new CompanyPermission(); |
| | | c.setUserId(user.getId()); |
| | | c.setIsdeleted(Constants.ZERO); |
| | | List<CompanyPermission> pList = companyPermissionService.findList(c); |
| | | if(pList!=null){ |
| | | for (CompanyPermission cc : pList){ |
| | | if(user.getCompanyIdList() == null){ |
| | | user.setCompanyIdList(new ArrayList<>()); |
| | | } |
| | | user.getCompanyIdList().add(cc.getCompanyId()); |
| | | } |
| | | } |
| | | }else{ |
| | | Company company = companyService.findById(user.getCompanyId()); |
| | | if(company == null){ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"对ä¸èµ·ï¼ä¼ä¸è´¦å·ä¿¡æ¯ä¸æ£ç¡®ï¼"); |
| | | } |
| | | user.setCompany(company); |
| | | } |
| | | |
| | | // éªè¯ç¨æ· |
| | | return new SimpleAuthenticationInfo(userInfo, user.getPassword(), this.getName()); |
| | | } |