public void addUser(String username, String password) throws AccountCreationException {
final EntityImpl entity;
try {
entity = EntityImpl.parse(username);
} catch (EntityFormatException e) {
throw new AccountCreationException("username is expected to be in proper entity format, not " + username, e); // wrap as unchecked
}
// if already existent, don't create, throw error
try {
if (jcrStorage.getEntityNode(entity, CREDENTIALS_NAMESPACE, false) != null) {
throw new AccountCreationException("account already exists: " + entity.getFullQualifiedName());
}
} catch (JcrStorageException e) {
throw new AccountCreationException("account exists check failed for " + entity.getFullQualifiedName(), e);
}
// now, finally, create
try {
final Node credentialsNode = jcrStorage.getEntityNode(entity, CREDENTIALS_NAMESPACE, true);
credentialsNode.setProperty("password", password);
credentialsNode.save();
logger.info("JCR node created: " + credentialsNode);
} catch (Exception e) {
// TODO remove account?
throw new AccountCreationException("failed to create the account set credentials", e);
}
}