use of com.salesmanager.core.model.user.User in project shopizer by shopizer-ecommerce.
the class JWTAdminServicesImpl method loadUserByUsername.
@Override
public UserDetails loadUserByUsername(String userName) throws UsernameNotFoundException {
User user = null;
Collection<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
try {
LOGGER.debug("Loading user by user id: {}", userName);
user = userService.getByUserName(userName);
if (user == null) {
// return null;
throw new UsernameNotFoundException("User " + userName + " not found");
}
// required to login
GrantedAuthority role = new SimpleGrantedAuthority(ROLE_PREFIX + Constants.PERMISSION_AUTHENTICATED);
authorities.add(role);
List<Integer> groupsId = new ArrayList<Integer>();
List<Group> groups = user.getGroups();
for (Group group : groups) {
groupsId.add(group.getId());
}
if (CollectionUtils.isNotEmpty(groupsId)) {
List<Permission> permissions = permissionService.getPermissions(groupsId);
for (Permission permission : permissions) {
GrantedAuthority auth = new SimpleGrantedAuthority(permission.getPermissionName());
authorities.add(auth);
}
}
} catch (ServiceException e) {
LOGGER.error("Exception while querrying customer", e);
throw new SecurityDataAccessException("Cannot authenticate customer", e);
}
return userDetails(userName, user, authorities);
}
Aggregations