private Collection<? extends GrantedAuthority> getAuthorities(User user) { List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>(user.getRoles().size()); for (Role role : user.getRoles()) { authorities.add(new SimpleGrantedAuthority(role.getRoleName())); } return authorities; }
/** This Method is used by container based authentication (web client) */ @Override public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { if ((username == null) || username.equals("")) { throw new AuthenticationCredentialsNotFoundException("No username provided in auth request"); } try { User user = userRepo.findByUsername(username); if (user == null) { throw new UsernameNotFoundException("No user with name " + username + " found"); } return new MultiTenantUserDetails( user.getUsername(), user.getPassword(), getAuthorities(user), user.getTenant().getTenantId()); } catch (NoResultException e) { throw new UsernameNotFoundException("No user with name " + username + " found"); } }