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

This commit is contained in:
Luke Taylor 2007-09-07 20:49:38 +00:00
parent f178ca2a39
commit ff1f1d8ef5
11 changed files with 46 additions and 19 deletions

View File

@ -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

View File

@ -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

View File

@ -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 ========================================================================================================

View File

@ -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);

View File

@ -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);

View File

@ -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 {

View File

@ -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();

View File

@ -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);
}

View File

@ -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);

View File

@ -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() {

View File

@ -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");
}
}