);
}
}
uploader.reset();
User adminUser = (User)Component.getInstance("adminUser");
User guestUser = (User)Component.getInstance("guestUser");
if ( !getInstance().getId().equals(adminUser.getId()) &&
!getInstance().getId().equals(guestUser.getId()) &&
roles != null && roles.size() > 0) {
// Roles
getInstance().setRoles(new ArrayList<Role>()); // Clear out the collection
getInstance().getRoles().addAll(roles);
}
// Preferences
if (preferenceEditor != null) {
String editorFailed = preferenceEditor.save();
if (editorFailed != null) return null;
}
boolean loginCredentialsModified = false;
// User wants to change his password
if (getPassword() != null && getPassword().length() != 0) {
if (!passwordAndControlNotNull() ||
!passwordMatchesRegex() ||
!passwordMatchesControl()) {
// Force re-entry
setPassword(null);
setPasswordControl(null);
return null;
} else {
// Set password hash
getInstance().setPasswordHash(hashUtil.hash(getPassword()));
loginCredentialsModified = true;
}
}
// User changed his username
if (!getInstance().getUsername().equals(oldUsername)) {
loginCredentialsModified = true;
// Validate
if (!isUniqueUsername()) return null;
}
if (Identity.instance().hasPermission("User", "isAdmin", Component.getInstance("currentUser"))) {
// Current user is admin and activated an account
if (getInstance().isActivated()) {
getInstance().setActivationCode(null);
}
}
String outcome = super.update();
if (outcome != null) {
org.jboss.seam.core.Events.instance().raiseEvent("User.updated", getInstance());
User currentUser = (User)Component.getInstance("currentUser");
if (getInstance().getId().equals(currentUser.getId())) {
// Updated profile of currently logged-in user
Contexts.getSessionContext().set("currentUser", getInstance());
// TODO: If identity.logout() wouldn't kill my session, I could call it here...
// And I don't have cleartext password in all cases, so I can't relogin the user automatically