From e1eb775d4434584a483498fb13dcbdf8ce200670 Mon Sep 17 00:00:00 2001 From: Mathieu Baudier Date: Thu, 24 Mar 2011 01:31:43 +0000 Subject: [PATCH] Fix issue with empty description in OpenLDAP git-svn-id: https://svn.argeo.org/commons/trunk@4358 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- .../ui/admin/wizards/NewUserWizard.java | 20 +++++++++++++++++-- .../ldap/jcr/JcrUserDetailsContextMapper.java | 6 ++++++ 2 files changed, 24 insertions(+), 2 deletions(-) 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 493e1881f..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,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; } } diff --git a/security/runtime/org.argeo.security.ldap/src/main/java/org/argeo/security/ldap/jcr/JcrUserDetailsContextMapper.java b/security/runtime/org.argeo.security.ldap/src/main/java/org/argeo/security/ldap/jcr/JcrUserDetailsContextMapper.java index 3a39e6906..7e2d89e6d 100644 --- a/security/runtime/org.argeo.security.ldap/src/main/java/org/argeo/security/ldap/jcr/JcrUserDetailsContextMapper.java +++ b/security/runtime/org.argeo.security.ldap/src/main/java/org/argeo/security/ldap/jcr/JcrUserDetailsContextMapper.java @@ -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(); -- 2.30.2