use of com.besscroft.aurora.mall.auth.domain.User 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.auth.domain.User in project aurora-mall by besscroft.
the class JwtTokenEnhancer method enhance.
@Override
public OAuth2AccessToken enhance(OAuth2AccessToken oAuth2AccessToken, OAuth2Authentication oAuth2Authentication) {
User user = (User) oAuth2Authentication.getPrincipal();
Map<String, Object> info = new HashMap<>();
// 把用户ID设置到JWT中
info.put("id", user.getId());
info.put("client_id", user.getClientId());
((DefaultOAuth2AccessToken) oAuth2AccessToken).setAdditionalInformation(info);
return oAuth2AccessToken;
}
Aggregations