*/
@Override
public final UserDetails loadUserByUsername(final String username) {
final List<GrantedAuthority> authorities =
new ArrayList<GrantedAuthority>();
UserAccount user = (UserAccount) memcacheService.get(username);
if (user == null) {
final Query query = entityManager.createQuery(
"SELECT u FROM UserAccount u WHERE username = :username");
query.setParameter(USERNAME, username);
try {
user = (UserAccount) query.getSingleResult();
memcacheService.put(username, user,
Expiration.byDeltaSeconds(DEFAULT_EXPIRATION));
} catch (NoResultException e) {
throw new UsernameNotFoundException("Username not found.", e);
}
}
authorities.add(new SimpleGrantedAuthority(user.getRole()));
return new EnhancedUser(user.getUsername(), user.getEmail(),
user.getDisplayName(), user.getPassword(), user.getSalt(),
user.isEnabled(), user.isAccountNonExpired(),
user.isCredentialsNonExpired(), user.isAccountNonLocked(),
authorities);
}