*
* @see ch.entwine.weblounge.common.security.DirectoryService#loadUser(java.lang.String,
* ch.entwine.weblounge.common.site.Site)
*/
public User loadUser(String login, Site site) {
JpaAccount jpaAccount = null;
// Load the user account and the user
try {
jpaAccount = persistence.getAccount(site.getIdentifier(), login, true);
} catch (Throwable e) {
logger.error("Error loading user '{}' from the database: {}", login, e.getMessage());
return null;
}
// Is that user known
if (jpaAccount == null) {
logger.debug("User '{}' is not known in site '{}'", login, site.getIdentifier());
return null;
}
// Create the weblounge user
WebloungeUser user = new WebloungeUserImpl(login, site.getIdentifier());
// Standard attributes like first name, name, ...
if (StringUtils.isNotBlank(jpaAccount.getFirstname()))
user.setFirstName(jpaAccount.getFirstname());
if (StringUtils.isNotBlank(jpaAccount.getLastname()))
user.setLastName(jpaAccount.getLastname());
if (StringUtils.isNotBlank(jpaAccount.getEmail()))
user.setEmail(jpaAccount.getEmail());
if (StringUtils.isNotBlank(jpaAccount.getInitials()))
user.setInitials(jpaAccount.getInitials());
// Password
user.addPrivateCredentials(new PasswordImpl(jpaAccount.getPassword(), DigestType.md5));
// Roles
for (JpaRole r : jpaAccount.getRoles()) {
// Make sure weblounge roles get special treatment in order
// to support role inheritance. Other directories will need
// to implement this through a LoginListener implementation
if (Security.SYSTEM_CONTEXT.equals(r.getContext())) {