Procházet zdrojové kódy

SEC-449: Rename internal LdapTemplate class to SpringSecurityLdapTemplate to avoid confusion.

Luke Taylor před 18 roky
rodič
revize
ff1f1d8ef5

+ 1 - 1
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

+ 1 - 1
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

+ 4 - 3
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 ========================================================================================================

+ 2 - 2
core/src/main/java/org/acegisecurity/ldap/LdapTemplate.java → 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);
 

+ 2 - 3
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);
 

+ 2 - 2
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 {

+ 2 - 2
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();

+ 3 - 3
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);
     }
 

+ 1 - 0
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);

+ 2 - 2
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() {

+ 26 - 0
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");
+
+        
+
+
+
+
+
     }
 }