@Override
@Transactional
public User create(Account account, String emailAddress, String password) throws ValidationException,
EntityExistsException {
final User user = entityAssembler.assembleEntity(User.class, new EntityCache(account));
String encPassword = null;
try {
encPassword = encodePassword(password, emailAddress);
}
catch(final IllegalArgumentException iae) {
throw new ValidationException("Invalid password");
}
user.setEmailAddress(emailAddress);
user.setPassword(encPassword);
// set default expiry date to 1 day from now
final Calendar clndr = Calendar.getInstance();
clndr.add(Calendar.DAY_OF_MONTH, 1);
final Date expires = clndr.getTime();
user.setExpires(expires);
// set the user as un-locked by default
user.setLocked(false);
// set the role as user by default
Authority userAuth =
dao.load(new NameKey<Authority>(Authority.class, AuthorityRoles.ROLE_USER.toString(),
Authority.FIELDNAME_AUTHORITY));
user.addAuthority(userAuth);
persist(user);
return user;
}