From 4b6308a3f0af63318ac9a28ddc0cc82c84f72b4c Mon Sep 17 00:00:00 2001 From: Ulrik Sandberg Date: Sun, 7 Jan 2007 17:18:37 +0000 Subject: [PATCH] LDAP-18: Deprecated the userName property in AbstractContextSource and changed it to the more correct userDn. --- spring-ldap/changelog.txt | 3 ++ .../docs/reference/src/configuration.xml | 8 ++--- spring-ldap/docs/reference/src/overview.xml | 2 +- .../java/conf/ldap-openldap.properties | 2 +- .../conf/ldapTemplateTestContext-openldap.xml | 2 +- .../src/itest/java/conf/apacheDsContext.xml | 2 +- .../src/itest/java/conf/ldap.properties | 2 +- .../conf/ldapContextSourceTestContext.xml | 2 +- .../conf/ldapTemplateAcegiTestContext.xml | 2 +- .../ldapTemplateNoBaseSuffixTestContext.xml | 2 +- .../java/conf/ldapTemplateTestContext.xml | 2 +- .../ldap/core/AuthenticationSource.java | 4 +-- .../ldap/support/AbstractContextSource.java | 29 +++++++++++++------ .../ldap/support/LdapContextSourceTest.java | 6 ++-- 14 files changed, 41 insertions(+), 27 deletions(-) diff --git a/spring-ldap/changelog.txt b/spring-ldap/changelog.txt index 46467fd8..4a7f0a6b 100644 --- a/spring-ldap/changelog.txt +++ b/spring-ldap/changelog.txt @@ -14,6 +14,9 @@ Changes in version 1.2 (xx.yy.2007) ------------------------------------------- * Moved the core classes into the package ldap.core. +* Deprecated the userName property in AbstractContextSource and changed + it to the more correct userDn. + * Upgraded ApacheDS to 1.0.0. Changes in version 1.1.2 (1.12.2006) diff --git a/spring-ldap/docs/reference/src/configuration.xml b/spring-ldap/docs/reference/src/configuration.xml index 09f1a45b..3e769463 100644 --- a/spring-ldap/docs/reference/src/configuration.xml +++ b/spring-ldap/docs/reference/src/configuration.xml @@ -26,12 +26,12 @@ Authenticated contexts are created for both read-only and read-write operations by default. You specify - userName and password of the LDAP + userDn and password of the LDAP user to be used for authentication on the ContextSource. - The userName needs to be the full + The userDn needs to be the full Distinguished Name (DN) of the user. @@ -53,7 +53,7 @@ executing LDAP operations for that user. The default behaviour can be modified by supplying a custom AuthenticationSource implementation to the ContextSource on startup, - instead of explicitly specifying the userName and + instead of explicitly specifying the userDn and password. The AuthenticationSource will be queried by the ContextSource for principal and credentials each @@ -84,7 +84,7 @@ - We don't specify any userName or + We don't specify any userDn or password to our ContextSource when using an AuthenticationSource - these properties are needed only when the default behaviour is diff --git a/spring-ldap/docs/reference/src/overview.xml b/spring-ldap/docs/reference/src/overview.xml index 40d2ab5f..4d3c5640 100644 --- a/spring-ldap/docs/reference/src/overview.xml +++ b/spring-ldap/docs/reference/src/overview.xml @@ -184,7 +184,7 @@ public class PersonDaoImpl implements PersonDao { <bean id="contextSource" class="org.springframework.ldap.support.LdapContextSource"> <property name="url" value="ldap://localhost:389" /> <property name="base" value="dc=example,dc=com" /> - <property name="userName" value="cn=Manager" /> + <property name="userDn" value="cn=Manager" /> <property name="password" value="secret" /> </bean> diff --git a/spring-ldap/src/itest-openldap/java/conf/ldap-openldap.properties b/spring-ldap/src/itest-openldap/java/conf/ldap-openldap.properties index 57aa1478..427661f7 100644 --- a/spring-ldap/src/itest-openldap/java/conf/ldap-openldap.properties +++ b/spring-ldap/src/itest-openldap/java/conf/ldap-openldap.properties @@ -1,4 +1,4 @@ urls=ldap://127.0.0.1 -userName=cn=manager,dc=jayway,dc=se +userDn=cn=manager,dc=jayway,dc=se password=secret base=dc=jayway,dc=se diff --git a/spring-ldap/src/itest-openldap/java/conf/ldapTemplateTestContext-openldap.xml b/spring-ldap/src/itest-openldap/java/conf/ldapTemplateTestContext-openldap.xml index 5ebf2354..e6b739a5 100644 --- a/spring-ldap/src/itest-openldap/java/conf/ldapTemplateTestContext-openldap.xml +++ b/spring-ldap/src/itest-openldap/java/conf/ldapTemplateTestContext-openldap.xml @@ -11,7 +11,7 @@ - + diff --git a/spring-ldap/src/itest/java/conf/apacheDsContext.xml b/spring-ldap/src/itest/java/conf/apacheDsContext.xml index 1396161e..52694704 100644 --- a/spring-ldap/src/itest/java/conf/apacheDsContext.xml +++ b/spring-ldap/src/itest/java/conf/apacheDsContext.xml @@ -17,7 +17,7 @@ simple - ${userName} + ${userDn} ${password} diff --git a/spring-ldap/src/itest/java/conf/ldap.properties b/spring-ldap/src/itest/java/conf/ldap.properties index c176bae6..8843f1f1 100644 --- a/spring-ldap/src/itest/java/conf/ldap.properties +++ b/spring-ldap/src/itest/java/conf/ldap.properties @@ -1,4 +1,4 @@ urls=ldap://127.0.0.1:3900 -userName=uid=admin,ou=system +userDn=uid=admin,ou=system password=secret base=dc=jayway,dc=se diff --git a/spring-ldap/src/itest/java/conf/ldapContextSourceTestContext.xml b/spring-ldap/src/itest/java/conf/ldapContextSourceTestContext.xml index 7c102139..563c1c85 100644 --- a/spring-ldap/src/itest/java/conf/ldapContextSourceTestContext.xml +++ b/spring-ldap/src/itest/java/conf/ldapContextSourceTestContext.xml @@ -6,7 +6,7 @@ http://www.springframework.org/schema/beans/spring-beans-2.0.xsd"> - + diff --git a/spring-ldap/src/itest/java/conf/ldapTemplateAcegiTestContext.xml b/spring-ldap/src/itest/java/conf/ldapTemplateAcegiTestContext.xml index f3668551..0d49b793 100644 --- a/spring-ldap/src/itest/java/conf/ldapTemplateAcegiTestContext.xml +++ b/spring-ldap/src/itest/java/conf/ldapTemplateAcegiTestContext.xml @@ -30,7 +30,7 @@ - + diff --git a/spring-ldap/src/itest/java/conf/ldapTemplateNoBaseSuffixTestContext.xml b/spring-ldap/src/itest/java/conf/ldapTemplateNoBaseSuffixTestContext.xml index 1558be7b..50ba6af0 100644 --- a/spring-ldap/src/itest/java/conf/ldapTemplateNoBaseSuffixTestContext.xml +++ b/spring-ldap/src/itest/java/conf/ldapTemplateNoBaseSuffixTestContext.xml @@ -12,7 +12,7 @@ - + diff --git a/spring-ldap/src/itest/java/conf/ldapTemplateTestContext.xml b/spring-ldap/src/itest/java/conf/ldapTemplateTestContext.xml index 6f8fe0b5..b6c80c68 100644 --- a/spring-ldap/src/itest/java/conf/ldapTemplateTestContext.xml +++ b/spring-ldap/src/itest/java/conf/ldapTemplateTestContext.xml @@ -12,7 +12,7 @@ - + diff --git a/spring-ldap/src/main/java/org/springframework/ldap/core/AuthenticationSource.java b/spring-ldap/src/main/java/org/springframework/ldap/core/AuthenticationSource.java index fc04f7ce..ef4a3bcc 100644 --- a/spring-ldap/src/main/java/org/springframework/ldap/core/AuthenticationSource.java +++ b/spring-ldap/src/main/java/org/springframework/ldap/core/AuthenticationSource.java @@ -27,14 +27,14 @@ public interface AuthenticationSource { /** * Get the principal to use when creating an authenticated context. * - * @return the principal (userName). + * @return the principal (userDn). */ public String getPrincipal(); /** * Get the credentials to use when creating an authenticated context. * - * @return the credentials (userName). + * @return the credentials (password). */ public String getCredentials(); } diff --git a/spring-ldap/src/main/java/org/springframework/ldap/support/AbstractContextSource.java b/spring-ldap/src/main/java/org/springframework/ldap/support/AbstractContextSource.java index 53097af3..996a7188 100644 --- a/spring-ldap/src/main/java/org/springframework/ldap/support/AbstractContextSource.java +++ b/spring-ldap/src/main/java/org/springframework/ldap/support/AbstractContextSource.java @@ -45,7 +45,7 @@ import org.springframework.ldap.core.ContextSource; *

* If an AuthenticationSource is set, this will be used for getting user name * and password for each new connection, otherwise a default one will be created - * using the specified userName and password. + * using the specified userDn and password. *

* Note: When using implementations of this class outside of a Spring * Context it is necessary to call {@link #afterPropertiesSet()} when all @@ -73,7 +73,7 @@ public abstract class AbstractContextSource implements ContextSource, private DistinguishedName base; - protected String userName = ""; + protected String userDn = ""; protected String password = ""; @@ -123,7 +123,7 @@ public abstract class AbstractContextSource implements ContextSource, env .put(Context.SECURITY_PRINCIPAL, authenticationSource .getPrincipal()); - log.debug("Principal: '" + userName + "'"); + log.debug("Principal: '" + userDn + "'"); env.put(Context.SECURITY_CREDENTIALS, authenticationSource .getCredentials()); } @@ -250,9 +250,9 @@ public abstract class AbstractContextSource implements ContextSource, if (authenticationSource == null) { log.debug("AuthenticationSource not set - " + "using default implementation"); - if (StringUtils.isBlank(userName)) { + if (StringUtils.isBlank(userDn)) { log - .warn("Property 'userName' not set - " + .warn("Property 'userDn' not set - " + "anonymous context will be used for read-write operations"); } else if (StringUtils.isBlank(password)) { log.warn("Property 'password' not set - " @@ -304,13 +304,24 @@ public abstract class AbstractContextSource implements ContextSource, } /** - * Set the user name (principal) to use for getting authenticated contexts. + * Set the user distinguished name (principal) to use for getting authenticated contexts. + * + * @param userDn + * the user distinguished name. + */ + public void setUserDn(String userDn) { + this.userDn = userDn; + } + + /** + * Set the user distinguished name (principal) to use for getting authenticated contexts. * * @param userName - * the user name. + * the user distinguished name. + * @deprecated Use {@link #setUserDn(String)} instead. */ public void setUserName(String userName) { - this.userName = userName; + setUserDn(userName); } /** @@ -444,7 +455,7 @@ public abstract class AbstractContextSource implements ContextSource, class SimpleAuthenticationSource implements AuthenticationSource { public String getPrincipal() { - return userName; + return userDn; } public String getCredentials() { diff --git a/spring-ldap/src/test/java/org/springframework/ldap/support/LdapContextSourceTest.java b/spring-ldap/src/test/java/org/springframework/ldap/support/LdapContextSourceTest.java index 3f621613..d00424f6 100644 --- a/spring-ldap/src/test/java/org/springframework/ldap/support/LdapContextSourceTest.java +++ b/spring-ldap/src/test/java/org/springframework/ldap/support/LdapContextSourceTest.java @@ -76,7 +76,7 @@ public class LdapContextSourceTest extends TestCase { tested.setBase("dc=example,dc=se"); tested.setUrl("ldap://ldap.example.com:389"); tested.setPooled(true); - tested.setUserName("cn=Some User"); + tested.setUserDn("cn=Some User"); tested.setPassword("secret"); tested.afterPropertiesSet(); Hashtable env = tested.getAnonymousEnv(); @@ -103,7 +103,7 @@ public class LdapContextSourceTest extends TestCase { tested.setBase("dc=example,dc=se"); tested.setUrl("ldap://ldap.example.com:389"); tested.setPooled(true); - tested.setUserName("cn=Some User"); + tested.setUserDn("cn=Some User"); tested.setPassword("secret"); tested.afterPropertiesSet(); @@ -158,7 +158,7 @@ public class LdapContextSourceTest extends TestCase { tested.setBase("dc=example,dc=se"); tested.setUrl("ldap://ldap.example.com:389"); tested.setPooled(true); - tested.setUserName("cn=Some User"); + tested.setUserDn("cn=Some User"); tested.setPassword("secret"); tested.setCacheEnvironmentProperties(false); tested.afterPropertiesSet();