From 0b54eece28b0c2b95d2e68f8b30e2b25ca52045b Mon Sep 17 00:00:00 2001 From: Luke Taylor Date: Sat, 13 Oct 2007 21:20:19 +0000 Subject: [PATCH] Added code to set the manager username and password if supplied. --- .../security/config/LdapBeanDefinitionParser.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/org/springframework/security/config/LdapBeanDefinitionParser.java b/core/src/main/java/org/springframework/security/config/LdapBeanDefinitionParser.java index 92161d9b2a..316839b9ca 100644 --- a/core/src/main/java/org/springframework/security/config/LdapBeanDefinitionParser.java +++ b/core/src/main/java/org/springframework/security/config/LdapBeanDefinitionParser.java @@ -6,6 +6,7 @@ import org.springframework.beans.factory.support.AbstractBeanDefinition; import org.springframework.beans.factory.support.RootBeanDefinition; import org.springframework.beans.factory.BeanDefinitionStoreException; import org.springframework.util.StringUtils; +import org.springframework.util.Assert; import org.springframework.security.ldap.DefaultInitialDirContextFactory; import org.springframework.security.providers.ldap.LdapAuthenticationProvider; import org.springframework.security.providers.ldap.populator.DefaultLdapAuthoritiesPopulator; @@ -34,7 +35,6 @@ public class LdapBeanDefinitionParser extends AbstractBeanDefinitionParser { /** Defines the Url of the ldap server to use. If not specified, an embedded apache DS instance will be created */ private static final String URL_ATTRIBUTE = "url"; private static final String AUTH_TYPE_ATTRIBUTE = "auth"; - // TODO: Setting login/passwords for non embedded server. private static final String PRINCIPAL_ATTRIBUTE = "managerDn"; private static final String PASSWORD_ATTRIBUTE = "managerPassword"; @@ -68,6 +68,18 @@ public class LdapBeanDefinitionParser extends AbstractBeanDefinitionParser { initialDirContextFactory.getConstructorArgumentValues().addIndexedArgumentValue(0, url); } + String managerDn = elt.getAttribute(PRINCIPAL_ATTRIBUTE); + String managerPassword = elt.getAttribute(PASSWORD_ATTRIBUTE); + + if (StringUtils.hasText(managerDn)) { + Assert.hasText(managerPassword, "You must specify the " + PASSWORD_ATTRIBUTE + + " if you supply a " + managerDn); + + initialDirContextFactory.getPropertyValues().addPropertyValue("managerDn", managerDn); + initialDirContextFactory.getPropertyValues().addPropertyValue("managerPassword", managerPassword); + } + + // TODO: Make these default values for 2.0 initialDirContextFactory.getPropertyValues().addPropertyValue("useLdapContext", Boolean.TRUE); initialDirContextFactory.getPropertyValues().addPropertyValue("dirObjectFactory", "org.springframework.ldap.core.support.DefaultDirObjectFactory");