Search in sources :

Example 11 with SysUser

use of com.hccake.ballcat.system.model.entity.SysUser in project ballcat by ballcat-projects.

the class SysUserDetailsServiceImpl method getUserDetailsByUserInfo.

/**
 * 根据UserInfo 获取 UserDetails
 * @param userInfoDTO 用户信息DTO
 * @return UserDetails
 */
public UserDetails getUserDetailsByUserInfo(UserInfoDTO userInfoDTO) {
    SysUser sysUser = userInfoDTO.getSysUser();
    Collection<String> roleCodes = userInfoDTO.getRoleCodes();
    Collection<String> permissions = userInfoDTO.getPermissions();
    Collection<String> dbAuthsSet = new HashSet<>();
    if (CollectionUtil.isNotEmpty(roleCodes)) {
        // 获取角色
        dbAuthsSet.addAll(roleCodes);
        // 获取资源
        dbAuthsSet.addAll(permissions);
    }
    Collection<? extends GrantedAuthority> authorities = AuthorityUtils.createAuthorityList(dbAuthsSet.toArray(new String[0]));
    // 默认将角色和权限放入属性中
    HashMap<String, Object> attributes = new HashMap<>(8);
    attributes.put(UserAttributeNameConstants.ROLE_CODES, roleCodes);
    attributes.put(UserAttributeNameConstants.PERMISSIONS, permissions);
    // 用户额外属性
    userInfoCoordinator.coordinateAttribute(userInfoDTO, attributes);
    return new User(sysUser.getUserId(), sysUser.getUsername(), sysUser.getPassword(), sysUser.getNickname(), sysUser.getAvatar(), sysUser.getStatus(), sysUser.getOrganizationId(), sysUser.getType(), authorities, attributes);
}
Also used : User(com.hccake.ballcat.common.security.userdetails.User) SysUser(com.hccake.ballcat.system.model.entity.SysUser) SysUser(com.hccake.ballcat.system.model.entity.SysUser) HashMap(java.util.HashMap) HashSet(java.util.HashSet)

Example 12 with SysUser

use of com.hccake.ballcat.system.model.entity.SysUser in project ballcat by ballcat-projects.

the class SysUserDetailsServiceImpl method loadUserByUsername.

@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
    SysUser sysUser = sysUserService.getByUsername(username);
    if (sysUser == null) {
        log.error("登陆:用户名错误,用户名:{}", username);
        throw new UsernameNotFoundException("username error!");
    }
    UserInfoDTO userInfoDTO = sysUserService.findUserInfo(sysUser);
    return getUserDetailsByUserInfo(userInfoDTO);
}
Also used : UsernameNotFoundException(org.springframework.security.core.userdetails.UsernameNotFoundException) SysUser(com.hccake.ballcat.system.model.entity.SysUser) UserInfoDTO(com.hccake.ballcat.system.model.dto.UserInfoDTO)

Aggregations

SysUser (com.hccake.ballcat.system.model.entity.SysUser)12 Transactional (org.springframework.transaction.annotation.Transactional)3 User (com.hccake.ballcat.common.security.userdetails.User)2 UserAnnouncement (com.hccake.ballcat.notify.model.entity.UserAnnouncement)2 Operation (io.swagger.v3.oas.annotations.Operation)2 HashMap (java.util.HashMap)2 EventListener (org.springframework.context.event.EventListener)2 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)2 BusinessException (com.hccake.ballcat.common.core.exception.BusinessException)1 CreateOperationLogging (com.hccake.ballcat.common.log.operation.annotation.CreateOperationLogging)1 MailDetails (com.hccake.ballcat.common.mail.model.MailDetails)1 NotifyChannelEnum (com.hccake.ballcat.notify.enums.NotifyChannelEnum)1 NotifyInfo (com.hccake.ballcat.notify.model.domain.NotifyInfo)1 Announcement (com.hccake.ballcat.notify.model.entity.Announcement)1 RecipientHandler (com.hccake.ballcat.notify.recipient.RecipientHandler)1 AnnouncementService (com.hccake.ballcat.notify.service.AnnouncementService)1 UserAnnouncementService (com.hccake.ballcat.notify.service.UserAnnouncementService)1 UserCreatedEvent (com.hccake.ballcat.system.event.UserCreatedEvent)1 UserOrganizationChangeEvent (com.hccake.ballcat.system.event.UserOrganizationChangeEvent)1 UserInfoDTO (com.hccake.ballcat.system.model.dto.UserInfoDTO)1