use of com.besscroft.aurora.mall.common.domain.UserDto in project aurora-mall by besscroft.
the class UserServiceImpl method loadUserByUsername.
@Override
public UserDto loadUserByUsername(String username) {
AuthUser authUser = this.baseMapper.selectAuthUserByUsername(username);
if (authUser != null) {
List<AuthRole> authRoles = authRoleMapper.selectAuthRoleListByAdminId(authUser.getId());
UserDto userDto = new UserDto();
BeanUtils.copyProperties(authUser, userDto);
if (CollUtil.isNotEmpty(authRoles)) {
List<String> roleStrList = authRoles.stream().map(item -> item.getId() + "_" + item.getName()).collect(Collectors.toList());
userDto.setRoles(roleStrList);
}
return userDto;
}
return null;
}
use of com.besscroft.aurora.mall.common.domain.UserDto in project aurora-mall by besscroft.
the class UserServiceImpl method getCurrentAdmin.
@Override
public AuthUser getCurrentAdmin() {
String header = request.getHeader(AuthConstants.USER_TOKEN_HEADER);
if (StrUtil.isEmpty(header)) {
log.error("暂未登录或token已经过期");
}
UserDto userDto = JSONUtil.toBean(header, UserDto.class);
return this.baseMapper.selectById(userDto.getId());
}
use of com.besscroft.aurora.mall.common.domain.UserDto in project aurora-mall by besscroft.
the class UserDetailsServiceImpl method loadUserByUsername.
@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
String clientId = request.getParameter(AuthConstants.JWT_CLIENT_ID_KEY);
UserDto userDto = null;
switch(clientId) {
case // 后台用户
AuthConstants.ADMIN_CLIENT_ID:
userDto = adminFeignClient.loadUserByUsername(username);
break;
case // 前台会员
AuthConstants.PORTAL_CLIENT_ID:
userDto = userFeignClient.loadUserByUsername(username);
break;
}
if (userDto == null) {
throw new UsernameNotFoundException(MessageConstant.USERNAME_PASSWORD_ERROR);
}
userDto.setClientId(clientId);
User user = new User(userDto);
if (!user.isEnabled()) {
throw new DisabledException(MessageConstant.ACCOUNT_DISABLED);
} else if (!user.isAccountNonLocked()) {
throw new LockedException(MessageConstant.ACCOUNT_LOCKED);
} else if (!user.isAccountNonExpired()) {
throw new AccountExpiredException(MessageConstant.ACCOUNT_EXPIRED);
} else if (!user.isCredentialsNonExpired()) {
throw new CredentialsExpiredException(MessageConstant.CREDENTIALS_EXPIRED);
}
return user;
}
use of com.besscroft.aurora.mall.common.domain.UserDto in project aurora-mall by besscroft.
the class UserServiceTest method loadUserByUsername.
@Test
void loadUserByUsername() throws Exception {
String username = "admin";
UserDto dto = userService.loadUserByUsername(username);
assertNotNull(dto, "获取当前用户信息失败!");
LOGGER.info("当前用户的信息:{}", objectMapper.writeValueAsString(dto));
}
Aggregations