Fix issue with empty description in OpenLDAP
authorMathieu Baudier <mbaudier@argeo.org>
Thu, 24 Mar 2011 01:31:43 +0000 (01:31 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Thu, 24 Mar 2011 01:31:43 +0000 (01:31 +0000)
git-svn-id: https://svn.argeo.org/commons/trunk@4358 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

security/plugins/org.argeo.security.ui.admin/src/main/java/org/argeo/security/ui/admin/wizards/NewUserWizard.java
security/runtime/org.argeo.security.ldap/src/main/java/org/argeo/security/ldap/jcr/JcrUserDetailsContextMapper.java

index 493e1881f526a325efd9a8d88c8dbfa6d264a402..b99570c200dae79345d0b4fbdb7468c86ebc3a3f 100644 (file)
@@ -1,8 +1,11 @@
 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;
@@ -13,6 +16,8 @@ import org.springframework.security.GrantedAuthority;
 
 /** 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 UserAdminService userAdminService;
@@ -36,8 +41,8 @@ public class NewUserWizard extends Wizard {
                if (!canFinish())
                        return false;
 
+               String username = mainUserInfo.getUsername();
                try {
-                       String username = mainUserInfo.getUsername();
                        session.save();
                        Node userHome = JcrUtils.createUserHome(session, homeBasePath,
                                        username);
@@ -52,7 +57,18 @@ public class NewUserWizard extends Wizard {
                        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;
                }
        }
index 3a39e690627712d3379d90b1c65638e05c2ec6e8..7e2d89e6d62805adaf15f424cf8fecedc099fbd6 100644 (file)
@@ -208,6 +208,12 @@ public class JcrUserDetailsContextMapper implements UserDetailsContextMapper,
                                                        .equals("")))
                                userProfile.setProperty(jcrProperty, "empty");
 
+                       if (ldapAttribute.equals("description")) {
+                               String value = userProfile.getProperty(jcrProperty).getString();
+                               if(value.trim().equals(""))
+                                       return;
+                       }
+
                        if (!userProfile.hasProperty(jcrProperty))
                                return;
                        String value = userProfile.getProperty(jcrProperty).getString();