*/
@Override
public final UserDetails loadUserByUsername(final String username) {
Preconditions.checkNotNull(username);
final Principal principal = principalService.findByName(username);
if (principal == null) {
throw new UsernameNotFoundException("Username was not found: " + username);
}
final Set<Role> rolesOfUser = principal.getRoles();
final Set<Privilege> privileges = Sets.newHashSet();
for (final Role roleOfUser : rolesOfUser) {
privileges.addAll(roleOfUser.getPrivileges());
}
final Function<Object, String> toStringFunction = Functions.toStringFunction();
final Collection<String> rolesToString = Collections2.transform(privileges, toStringFunction);
final String[] roleStringsAsArray = rolesToString.toArray(new String[rolesToString.size()]);
final List<GrantedAuthority> auths = AuthorityUtils.createAuthorityList(roleStringsAsArray);
return new User(principal.getName(), principal.getPassword(), auths);
}