if (account.getEditing()) {
user = udb.getAccount(account.getUsername());
try {
udb.updateAccount(user, account.getEmail(), account.getFullname(), roles);
CoreEvent coreEvent = new CoreEvent(this, CoreEventConstants.USER_EDITED, user, info)
.addAttribute(CoreAttributeConstants.EVENT_ATTR_PRINCIPAL_ID, user.getPrincipalName())
.addAttribute(CoreAttributeConstants.EVENT_ATTR_FULL_NAME, user.getFullname())
.addAttribute(CoreAttributeConstants.EVENT_ATTR_ACCOUNT_EMAIL, user.getEmail());
if(roles.length != 0) {
for(int i = 0; i < roles.length; i++ ) {
coreEvent.addAttribute(CoreAttributeConstants.EVENT_ATTR_GROUP + Integer.toString(i+1), roles[i].getPrincipalName());
}
}
CoreServlet.getServlet().fireCoreEvent(coreEvent);
} catch (GroupsRequiredForUserException e) {
saveError(request, "createAccount.error.groupsRequired");
return mapping.findForward("display");
} catch (UserDatabaseException e) {
if(UserDatabaseException.INTERNAL_ERROR == e.getCode()) {
handleException(CoreEventConstants.USER_CREATED, account, info, roles, e);
throw e;
} else {
saveError(request, e.getBundleActionMessage());
return mapping.findForward("display");
}
} catch (Exception e) {
handleException(CoreEventConstants.USER_EDITED, account, info, roles, e);
throw e;
}
} else {
try {
user = udb.createAccount(account.getUsername(), String.valueOf((int) (Math.random() * 100000)),
// Set a random password
account.getEmail(), account.getFullname(), roles);
CoreEvent coreEvent = new CoreEvent(this, CoreEventConstants.USER_CREATED, null, info, CoreEvent.STATE_SUCCESSFUL)
.addAttribute(CoreAttributeConstants.EVENT_ATTR_PRINCIPAL_ID, account.getUsername())
.addAttribute(CoreAttributeConstants.EVENT_ATTR_FULL_NAME, account.getFullname())
.addAttribute(CoreAttributeConstants.EVENT_ATTR_ACCOUNT_EMAIL, account.getEmail());
if(roles.length != 0) {
for(int i = 0; i < roles.length; i++ ) {
coreEvent.addAttribute(CoreAttributeConstants.EVENT_ATTR_GROUP + Integer.toString(i+1), roles[i].getPrincipalName());
}
}
CoreServlet.getServlet().fireCoreEvent(coreEvent);
} catch (GroupsRequiredForUserException e) {
saveError(request, "createAccount.error.groupsRequired");