Search in sources :

Example 1 with EcAuthorityUserDTO

use of com.easy.cloud.core.authority.pojo.dto.EcAuthorityUserDTO in project dq-easy-cloud by dq-open-cloud.

the class EcAuthorityRealm method doGetAuthorizationInfo.

@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
    SimpleAuthorizationInfo authorizationInfo = new SimpleAuthorizationInfo();
    EcAuthorityUserDTO<Long> authorityUserDTO = (EcAuthorityUserDTO) principals.getPrimaryPrincipal();
    List<SysRoleDTO> roleList = sysRoleService.findByUserId(authorityUserDTO.getAuthorityUserId());
    Set<Integer> roleNos = new HashSet<>();
    for (SysRoleDTO role : roleList) {
        authorizationInfo.addRole(role.getName());
        roleNos.add(role.getRoleNo());
    }
    List<SysResourceDTO> roleResourceDTOs = sysResourceService.findByRoleNos(new ArrayList<>(roleNos));
    for (SysResourceDTO resourceDTO : roleResourceDTOs) {
        authorizationInfo.addStringPermission(resourceDTO.getPermission());
    }
    return authorizationInfo;
}
Also used : EcAuthorityUserDTO(com.easy.cloud.core.authority.pojo.dto.EcAuthorityUserDTO) SimpleAuthorizationInfo(org.apache.shiro.authz.SimpleAuthorizationInfo) SysRoleDTO(com.easy.cloud.core.operator.sysrole.pojo.dto.SysRoleDTO) SysResourceDTO(com.easy.cloud.core.operator.sysresource.pojo.dto.SysResourceDTO)

Example 2 with EcAuthorityUserDTO

use of com.easy.cloud.core.authority.pojo.dto.EcAuthorityUserDTO in project dq-easy-cloud by dq-open-cloud.

the class EcAuthorityRealm method doGetAuthenticationInfoPassword.

/**
 * <p>
 * 使用账号密码的方式登录
 * </p>
 *
 * @param token
 * @return org.apache.shiro.authc.AuthenticationInfo
 * @author daiqi
 * @date 2018/6/29 17:50
 */
protected AuthenticationInfo doGetAuthenticationInfoPassword(AuthenticationToken token) {
    // 获取用户的输入的账号.
    String username = (String) token.getPrincipal();
    EcAuthorityUserDTO authorityUserDTO = sysUserService.findByUsername(username);
    // 账户冻结
    if (authorityUserDTO.getLocked() == 1) {
        throw new LockedAccountException();
    }
    SimpleAuthenticationInfo authenticationInfo = new SimpleAuthenticationInfo(authorityUserDTO, authorityUserDTO.getPassword(), ByteSource.Util.bytes(authorityUserDTO.getSalt()), authorityUserDTO.getAuthCacheKey());
    return authenticationInfo;
}
Also used : EcAuthorityUserDTO(com.easy.cloud.core.authority.pojo.dto.EcAuthorityUserDTO)

Aggregations

EcAuthorityUserDTO (com.easy.cloud.core.authority.pojo.dto.EcAuthorityUserDTO)2 SysResourceDTO (com.easy.cloud.core.operator.sysresource.pojo.dto.SysResourceDTO)1 SysRoleDTO (com.easy.cloud.core.operator.sysrole.pojo.dto.SysRoleDTO)1 SimpleAuthorizationInfo (org.apache.shiro.authz.SimpleAuthorizationInfo)1