diff --git a/core/src/main/java/org/acegisecurity/ldap/LdapCallback.java b/core/src/main/java/org/acegisecurity/ldap/LdapCallback.java index b10d4f68f9..73821f37e2 100644 --- a/core/src/main/java/org/acegisecurity/ldap/LdapCallback.java +++ b/core/src/main/java/org/acegisecurity/ldap/LdapCallback.java @@ -20,7 +20,7 @@ import javax.naming.directory.DirContext; /** - * Callback object for use with LdapTemplate. + * Callback object for use with SpringSecurityLdapTemplate. * * @deprecated use spring-ldap ContextExecutor instead. * @TODO: Delete before 2.0 release diff --git a/core/src/main/java/org/acegisecurity/ldap/LdapEntryMapper.java b/core/src/main/java/org/acegisecurity/ldap/LdapEntryMapper.java index 7bf26c292d..63213add01 100644 --- a/core/src/main/java/org/acegisecurity/ldap/LdapEntryMapper.java +++ b/core/src/main/java/org/acegisecurity/ldap/LdapEntryMapper.java @@ -20,7 +20,7 @@ import javax.naming.directory.Attributes; /** - * A mapper for use with {@link LdapTemplate}. Creates a customized object from + * A mapper for use with {@link SpringSecurityLdapTemplate}. Creates a customized object from * a set of attributes retrieved from a directory entry. * * @author Luke Taylor diff --git a/core/src/main/java/org/acegisecurity/ldap/NamingExceptionTranslator.java b/core/src/main/java/org/acegisecurity/ldap/NamingExceptionTranslator.java index 3a9dae8b53..ad9d7b8cf5 100644 --- a/core/src/main/java/org/acegisecurity/ldap/NamingExceptionTranslator.java +++ b/core/src/main/java/org/acegisecurity/ldap/NamingExceptionTranslator.java @@ -20,9 +20,10 @@ import org.springframework.dao.DataAccessException; import javax.naming.NamingException; -/** - * @author Luke Taylor - * @version $Id$ +/** + * @author Luke Taylor + * @deprecated Spring ldap is used instead. + * @version $Id$ */ public interface NamingExceptionTranslator { //~ Methods ======================================================================================================== diff --git a/core/src/main/java/org/acegisecurity/ldap/LdapTemplate.java b/core/src/main/java/org/acegisecurity/ldap/SpringSecurityLdapTemplate.java similarity index 98% rename from core/src/main/java/org/acegisecurity/ldap/LdapTemplate.java rename to core/src/main/java/org/acegisecurity/ldap/SpringSecurityLdapTemplate.java index f0ef188029..953b0a6549 100644 --- a/core/src/main/java/org/acegisecurity/ldap/LdapTemplate.java +++ b/core/src/main/java/org/acegisecurity/ldap/SpringSecurityLdapTemplate.java @@ -49,7 +49,7 @@ import javax.naming.directory.SearchResult; * @author Ben Alex * @author Luke Taylor */ -public class LdapTemplate extends org.springframework.ldap.LdapTemplate { +public class SpringSecurityLdapTemplate extends org.springframework.ldap.LdapTemplate { //~ Static fields/initializers ===================================================================================== public static final String[] NO_ATTRS = new String[0]; @@ -63,7 +63,7 @@ public class LdapTemplate extends org.springframework.ldap.LdapTemplate { //~ Constructors =================================================================================================== - public LdapTemplate(ContextSource contextSource) { + public SpringSecurityLdapTemplate(ContextSource contextSource) { Assert.notNull(contextSource, "ContextSource cannot be null"); setContextSource(contextSource); diff --git a/core/src/main/java/org/acegisecurity/ldap/search/FilterBasedLdapUserSearch.java b/core/src/main/java/org/acegisecurity/ldap/search/FilterBasedLdapUserSearch.java index fbd4123613..a41353dee0 100644 --- a/core/src/main/java/org/acegisecurity/ldap/search/FilterBasedLdapUserSearch.java +++ b/core/src/main/java/org/acegisecurity/ldap/search/FilterBasedLdapUserSearch.java @@ -16,7 +16,7 @@ package org.acegisecurity.ldap.search; import org.acegisecurity.ldap.InitialDirContextFactory; -import org.acegisecurity.ldap.LdapTemplate; +import org.acegisecurity.ldap.SpringSecurityLdapTemplate; import org.acegisecurity.ldap.LdapUserSearch; import org.acegisecurity.userdetails.UsernameNotFoundException; @@ -32,7 +32,6 @@ import org.springframework.dao.IncorrectResultSizeDataAccessException; import org.springframework.util.Assert; import org.springframework.ldap.ContextSource; -import javax.naming.directory.DirContext; import javax.naming.directory.SearchControls; @@ -111,7 +110,7 @@ public class FilterBasedLdapUserSearch implements LdapUserSearch { + this.toString()); } - LdapTemplate template = new LdapTemplate(initialDirContextFactory); + SpringSecurityLdapTemplate template = new SpringSecurityLdapTemplate(initialDirContextFactory); template.setSearchControls(searchControls); diff --git a/core/src/main/java/org/acegisecurity/providers/ldap/authenticator/BindAuthenticator.java b/core/src/main/java/org/acegisecurity/providers/ldap/authenticator/BindAuthenticator.java index 28497f2f3d..156bb86db4 100644 --- a/core/src/main/java/org/acegisecurity/providers/ldap/authenticator/BindAuthenticator.java +++ b/core/src/main/java/org/acegisecurity/providers/ldap/authenticator/BindAuthenticator.java @@ -18,7 +18,7 @@ package org.acegisecurity.providers.ldap.authenticator; import org.acegisecurity.BadCredentialsException; import org.acegisecurity.ldap.InitialDirContextFactory; -import org.acegisecurity.ldap.LdapTemplate; +import org.acegisecurity.ldap.SpringSecurityLdapTemplate; import org.acegisecurity.userdetails.ldap.LdapUserDetails; import org.acegisecurity.userdetails.ldap.LdapUserDetailsImpl; @@ -84,7 +84,7 @@ public class BindAuthenticator extends AbstractLdapAuthenticator { } private LdapUserDetails bindWithDn(String userDn, String username, String password) { - LdapTemplate template = new LdapTemplate( + SpringSecurityLdapTemplate template = new SpringSecurityLdapTemplate( new BindWithSpecificDnContextSource(getInitialDirContextFactory(), userDn, password)); try { diff --git a/core/src/main/java/org/acegisecurity/providers/ldap/authenticator/PasswordComparisonAuthenticator.java b/core/src/main/java/org/acegisecurity/providers/ldap/authenticator/PasswordComparisonAuthenticator.java index 64985af557..77218e4521 100644 --- a/core/src/main/java/org/acegisecurity/providers/ldap/authenticator/PasswordComparisonAuthenticator.java +++ b/core/src/main/java/org/acegisecurity/providers/ldap/authenticator/PasswordComparisonAuthenticator.java @@ -18,7 +18,7 @@ package org.acegisecurity.providers.ldap.authenticator; import org.acegisecurity.BadCredentialsException; import org.acegisecurity.ldap.InitialDirContextFactory; -import org.acegisecurity.ldap.LdapTemplate; +import org.acegisecurity.ldap.SpringSecurityLdapTemplate; import org.acegisecurity.ldap.LdapUtils; import org.acegisecurity.providers.encoding.PasswordEncoder; @@ -76,7 +76,7 @@ public final class PasswordComparisonAuthenticator extends AbstractLdapAuthentic Iterator dns = getUserDns(username).iterator(); - LdapTemplate ldapTemplate = new LdapTemplate(getInitialDirContextFactory()); + SpringSecurityLdapTemplate ldapTemplate = new SpringSecurityLdapTemplate(getInitialDirContextFactory()); while (dns.hasNext() && (user == null)) { final String userDn = (String) dns.next(); diff --git a/core/src/main/java/org/acegisecurity/providers/ldap/populator/DefaultLdapAuthoritiesPopulator.java b/core/src/main/java/org/acegisecurity/providers/ldap/populator/DefaultLdapAuthoritiesPopulator.java index c434564126..5cc97d2ed7 100644 --- a/core/src/main/java/org/acegisecurity/providers/ldap/populator/DefaultLdapAuthoritiesPopulator.java +++ b/core/src/main/java/org/acegisecurity/providers/ldap/populator/DefaultLdapAuthoritiesPopulator.java @@ -19,7 +19,7 @@ import org.acegisecurity.GrantedAuthority; import org.acegisecurity.GrantedAuthorityImpl; import org.acegisecurity.ldap.InitialDirContextFactory; -import org.acegisecurity.ldap.LdapTemplate; +import org.acegisecurity.ldap.SpringSecurityLdapTemplate; import org.acegisecurity.providers.ldap.LdapAuthoritiesPopulator; @@ -103,7 +103,7 @@ public class DefaultLdapAuthoritiesPopulator implements LdapAuthoritiesPopulator * An initial context factory is only required if searching for groups is required. */ private InitialDirContextFactory initialDirContextFactory = null; - private LdapTemplate ldapTemplate; + private SpringSecurityLdapTemplate ldapTemplate; /** * Controls used to determine whether group searches should be performed over the full sub-tree from the @@ -273,7 +273,7 @@ public class DefaultLdapAuthoritiesPopulator implements LdapAuthoritiesPopulator Assert.notNull(initialDirContextFactory, "InitialDirContextFactory must not be null"); this.initialDirContextFactory = initialDirContextFactory; - ldapTemplate = new LdapTemplate(initialDirContextFactory); + ldapTemplate = new SpringSecurityLdapTemplate(initialDirContextFactory); ldapTemplate.setSearchControls(searchControls); } diff --git a/core/src/main/java/org/acegisecurity/userdetails/ldap/LdapUserDetailsManager.java b/core/src/main/java/org/acegisecurity/userdetails/ldap/LdapUserDetailsManager.java index 9d4216a7a8..f1389eddf9 100644 --- a/core/src/main/java/org/acegisecurity/userdetails/ldap/LdapUserDetailsManager.java +++ b/core/src/main/java/org/acegisecurity/userdetails/ldap/LdapUserDetailsManager.java @@ -55,6 +55,7 @@ import java.util.*; * * @author Luke Taylor * @since 2.0 + * @version $Id$ */ public class LdapUserDetailsManager implements UserDetailsManager { private final Log logger = LogFactory.getLog(LdapUserDetailsManager.class); diff --git a/core/src/test/java/org/acegisecurity/ldap/LdapTemplateTests.java b/core/src/test/java/org/acegisecurity/ldap/LdapTemplateTests.java index ec43a74b52..84fa4ffb20 100644 --- a/core/src/test/java/org/acegisecurity/ldap/LdapTemplateTests.java +++ b/core/src/test/java/org/acegisecurity/ldap/LdapTemplateTests.java @@ -31,14 +31,14 @@ import javax.naming.directory.DirContext; public class LdapTemplateTests extends AbstractLdapServerTestCase { //~ Instance fields ================================================================================================ - private LdapTemplate template; + private SpringSecurityLdapTemplate template; //~ Methods ======================================================================================================== protected void onSetUp() { getInitialCtxFactory().setManagerDn(MANAGER_USER); getInitialCtxFactory().setManagerPassword(MANAGER_PASSWORD); - template = new LdapTemplate(getInitialCtxFactory()); + template = new SpringSecurityLdapTemplate(getInitialCtxFactory()); } public void testCompareOfCorrectByteValueSucceeds() { diff --git a/core/src/test/java/org/acegisecurity/userdetails/ldap/LdapUserDetailsManagerTests.java b/core/src/test/java/org/acegisecurity/userdetails/ldap/LdapUserDetailsManagerTests.java index f9ef9a5123..be30783e27 100644 --- a/core/src/test/java/org/acegisecurity/userdetails/ldap/LdapUserDetailsManagerTests.java +++ b/core/src/test/java/org/acegisecurity/userdetails/ldap/LdapUserDetailsManagerTests.java @@ -20,6 +20,8 @@ import org.acegisecurity.userdetails.UserDetails; import org.acegisecurity.userdetails.UsernameNotFoundException; import org.acegisecurity.GrantedAuthority; import org.acegisecurity.GrantedAuthorityImpl; +import org.acegisecurity.providers.UsernamePasswordAuthenticationToken; +import org.acegisecurity.context.SecurityContextHolder; import org.springframework.ldap.LdapTemplate; import org.springframework.ldap.support.DirContextAdapter; import org.springframework.ldap.support.DistinguishedName; @@ -82,6 +84,7 @@ public class LdapUserDetailsManagerTests extends AbstractLdapServerTestCase { template.unbind("cn=clowns,ou=testgroups"); template.unbind("ou=testgroups"); + SecurityContextHolder.clearContext(); } public void testLoadUserByUsernameReturnsCorrectData() { @@ -149,5 +152,28 @@ public class LdapUserDetailsManagerTests extends AbstractLdapServerTestCase { // Check that no authorities are left assertEquals(0, mgr.getUserAuthorities(mgr.buildDn("don"), "don").length); + } + + public void testPasswordChangeSucceeds() { + InetOrgPerson.Essence p = new InetOrgPerson.Essence(); + p.setCn(new String[] {"John Yossarian"}); + p.setSn("Yossarian"); + p.setUid("john"); + p.setPassword("yossarianspassword"); + p.setAuthorities(TEST_AUTHORITIES); + + mgr.createUser(p.createUserDetails()); + + SecurityContextHolder.getContext().setAuthentication( + new UsernamePasswordAuthenticationToken("john", "yossarianspassword", TEST_AUTHORITIES)); + + mgr.changePassword("yossarianspassword", "yossariansnewpassword"); + + + + + + + } }