X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;ds=sidebyside;f=security%2Fplugins%2Forg.argeo.security.ui.admin%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fsecurity%2Fui%2Fadmin%2Fwizards%2FNewUserWizard.java;h=b99570c200dae79345d0b4fbdb7468c86ebc3a3f;hb=e1eb775d4434584a483498fb13dcbdf8ce200670;hp=6c894d62a57bedf3315a6c44754e00c9342abbfc;hpb=5266ec50ddbf3247a5033d98a1dbceec6673a5b8;p=lgpl%2Fargeo-commons.git diff --git a/security/plugins/org.argeo.security.ui.admin/src/main/java/org/argeo/security/ui/admin/wizards/NewUserWizard.java b/security/plugins/org.argeo.security.ui.admin/src/main/java/org/argeo/security/ui/admin/wizards/NewUserWizard.java index 6c894d62a..b99570c20 100644 --- a/security/plugins/org.argeo.security.ui.admin/src/main/java/org/argeo/security/ui/admin/wizards/NewUserWizard.java +++ b/security/plugins/org.argeo.security.ui.admin/src/main/java/org/argeo/security/ui/admin/wizards/NewUserWizard.java @@ -1,40 +1,49 @@ package org.argeo.security.ui.admin.wizards; import javax.jcr.Node; +import javax.jcr.RepositoryException; import javax.jcr.Session; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.argeo.eclipse.ui.dialogs.Error; import org.argeo.jcr.ArgeoNames; import org.argeo.jcr.JcrUtils; +import org.argeo.security.UserAdminService; import org.argeo.security.jcr.JcrUserDetails; import org.eclipse.jface.wizard.Wizard; import org.springframework.security.GrantedAuthority; -import org.springframework.security.userdetails.UserDetailsManager; /** Wizard to create a new user */ public class NewUserWizard extends Wizard { + private final static Log log = LogFactory.getLog(NewUserWizard.class); + private String homeBasePath = "/home"; private Session session; - private UserDetailsManager userDetailsManager; + private UserAdminService userAdminService; // pages private MainUserInfoWizardPage mainUserInfo; - public NewUserWizard(Session session, UserDetailsManager userDetailsManager) { + public NewUserWizard(Session session, UserAdminService userAdminService) { this.session = session; - this.userDetailsManager = userDetailsManager; + this.userAdminService = userAdminService; } @Override public void addPages() { - mainUserInfo = new MainUserInfoWizardPage(); + mainUserInfo = new MainUserInfoWizardPage(userAdminService); addPage(mainUserInfo); } @Override public boolean performFinish() { + if (!canFinish()) + return false; + + String username = mainUserInfo.getUsername(); try { - String username = mainUserInfo.getUsername(); + session.save(); Node userHome = JcrUtils.createUserHome(session, homeBasePath, username); Node userProfile = userHome.getNode(ArgeoNames.ARGEO_PROFILE); @@ -44,11 +53,22 @@ public class NewUserWizard extends Wizard { userHome.getPath(), username, password, true, true, true, true, new GrantedAuthority[0]); session.save(); - userDetailsManager.createUser(jcrUserDetails); + userAdminService.createUser(jcrUserDetails); return true; } catch (Exception e) { JcrUtils.discardQuietly(session); - Error.show("Cannot create new user", e); + Node userHome = JcrUtils.getUserHome(session, username); + if (userHome != null) { + try { + userHome.remove(); + session.save(); + } catch (RepositoryException e1) { + JcrUtils.discardQuietly(session); + log.warn("Error when trying to clean up failed new user " + + username, e1); + } + } + Error.show("Cannot create new user " + username, e); return false; } }