SEC-449: Rename internal LdapTemplate class to SpringSecurityLdapTemplate to avoid confusion.
This commit is contained in:
parent
f178ca2a39
commit
ff1f1d8ef5
|
@ -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.
|
* @deprecated use spring-ldap ContextExecutor instead.
|
||||||
* @TODO: Delete before 2.0 release
|
* @TODO: Delete before 2.0 release
|
||||||
|
|
|
@ -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.
|
* a set of attributes retrieved from a directory entry.
|
||||||
*
|
*
|
||||||
* @author Luke Taylor
|
* @author Luke Taylor
|
||||||
|
|
|
@ -20,9 +20,10 @@ import org.springframework.dao.DataAccessException;
|
||||||
import javax.naming.NamingException;
|
import javax.naming.NamingException;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Luke Taylor
|
* @author Luke Taylor
|
||||||
* @version $Id$
|
* @deprecated Spring ldap is used instead.
|
||||||
|
* @version $Id$
|
||||||
*/
|
*/
|
||||||
public interface NamingExceptionTranslator {
|
public interface NamingExceptionTranslator {
|
||||||
//~ Methods ========================================================================================================
|
//~ Methods ========================================================================================================
|
||||||
|
|
|
@ -49,7 +49,7 @@ import javax.naming.directory.SearchResult;
|
||||||
* @author Ben Alex
|
* @author Ben Alex
|
||||||
* @author Luke Taylor
|
* @author Luke Taylor
|
||||||
*/
|
*/
|
||||||
public class LdapTemplate extends org.springframework.ldap.LdapTemplate {
|
public class SpringSecurityLdapTemplate extends org.springframework.ldap.LdapTemplate {
|
||||||
//~ Static fields/initializers =====================================================================================
|
//~ Static fields/initializers =====================================================================================
|
||||||
|
|
||||||
public static final String[] NO_ATTRS = new String[0];
|
public static final String[] NO_ATTRS = new String[0];
|
||||||
|
@ -63,7 +63,7 @@ public class LdapTemplate extends org.springframework.ldap.LdapTemplate {
|
||||||
|
|
||||||
//~ Constructors ===================================================================================================
|
//~ Constructors ===================================================================================================
|
||||||
|
|
||||||
public LdapTemplate(ContextSource contextSource) {
|
public SpringSecurityLdapTemplate(ContextSource contextSource) {
|
||||||
Assert.notNull(contextSource, "ContextSource cannot be null");
|
Assert.notNull(contextSource, "ContextSource cannot be null");
|
||||||
setContextSource(contextSource);
|
setContextSource(contextSource);
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
package org.acegisecurity.ldap.search;
|
package org.acegisecurity.ldap.search;
|
||||||
|
|
||||||
import org.acegisecurity.ldap.InitialDirContextFactory;
|
import org.acegisecurity.ldap.InitialDirContextFactory;
|
||||||
import org.acegisecurity.ldap.LdapTemplate;
|
import org.acegisecurity.ldap.SpringSecurityLdapTemplate;
|
||||||
import org.acegisecurity.ldap.LdapUserSearch;
|
import org.acegisecurity.ldap.LdapUserSearch;
|
||||||
|
|
||||||
import org.acegisecurity.userdetails.UsernameNotFoundException;
|
import org.acegisecurity.userdetails.UsernameNotFoundException;
|
||||||
|
@ -32,7 +32,6 @@ import org.springframework.dao.IncorrectResultSizeDataAccessException;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
import org.springframework.ldap.ContextSource;
|
import org.springframework.ldap.ContextSource;
|
||||||
|
|
||||||
import javax.naming.directory.DirContext;
|
|
||||||
import javax.naming.directory.SearchControls;
|
import javax.naming.directory.SearchControls;
|
||||||
|
|
||||||
|
|
||||||
|
@ -111,7 +110,7 @@ public class FilterBasedLdapUserSearch implements LdapUserSearch {
|
||||||
+ this.toString());
|
+ this.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
LdapTemplate template = new LdapTemplate(initialDirContextFactory);
|
SpringSecurityLdapTemplate template = new SpringSecurityLdapTemplate(initialDirContextFactory);
|
||||||
|
|
||||||
template.setSearchControls(searchControls);
|
template.setSearchControls(searchControls);
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ package org.acegisecurity.providers.ldap.authenticator;
|
||||||
import org.acegisecurity.BadCredentialsException;
|
import org.acegisecurity.BadCredentialsException;
|
||||||
|
|
||||||
import org.acegisecurity.ldap.InitialDirContextFactory;
|
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.LdapUserDetails;
|
||||||
import org.acegisecurity.userdetails.ldap.LdapUserDetailsImpl;
|
import org.acegisecurity.userdetails.ldap.LdapUserDetailsImpl;
|
||||||
|
@ -84,7 +84,7 @@ public class BindAuthenticator extends AbstractLdapAuthenticator {
|
||||||
}
|
}
|
||||||
|
|
||||||
private LdapUserDetails bindWithDn(String userDn, String username, String password) {
|
private LdapUserDetails bindWithDn(String userDn, String username, String password) {
|
||||||
LdapTemplate template = new LdapTemplate(
|
SpringSecurityLdapTemplate template = new SpringSecurityLdapTemplate(
|
||||||
new BindWithSpecificDnContextSource(getInitialDirContextFactory(), userDn, password));
|
new BindWithSpecificDnContextSource(getInitialDirContextFactory(), userDn, password));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -18,7 +18,7 @@ package org.acegisecurity.providers.ldap.authenticator;
|
||||||
import org.acegisecurity.BadCredentialsException;
|
import org.acegisecurity.BadCredentialsException;
|
||||||
|
|
||||||
import org.acegisecurity.ldap.InitialDirContextFactory;
|
import org.acegisecurity.ldap.InitialDirContextFactory;
|
||||||
import org.acegisecurity.ldap.LdapTemplate;
|
import org.acegisecurity.ldap.SpringSecurityLdapTemplate;
|
||||||
import org.acegisecurity.ldap.LdapUtils;
|
import org.acegisecurity.ldap.LdapUtils;
|
||||||
|
|
||||||
import org.acegisecurity.providers.encoding.PasswordEncoder;
|
import org.acegisecurity.providers.encoding.PasswordEncoder;
|
||||||
|
@ -76,7 +76,7 @@ public final class PasswordComparisonAuthenticator extends AbstractLdapAuthentic
|
||||||
|
|
||||||
Iterator dns = getUserDns(username).iterator();
|
Iterator dns = getUserDns(username).iterator();
|
||||||
|
|
||||||
LdapTemplate ldapTemplate = new LdapTemplate(getInitialDirContextFactory());
|
SpringSecurityLdapTemplate ldapTemplate = new SpringSecurityLdapTemplate(getInitialDirContextFactory());
|
||||||
|
|
||||||
while (dns.hasNext() && (user == null)) {
|
while (dns.hasNext() && (user == null)) {
|
||||||
final String userDn = (String) dns.next();
|
final String userDn = (String) dns.next();
|
||||||
|
|
|
@ -19,7 +19,7 @@ import org.acegisecurity.GrantedAuthority;
|
||||||
import org.acegisecurity.GrantedAuthorityImpl;
|
import org.acegisecurity.GrantedAuthorityImpl;
|
||||||
|
|
||||||
import org.acegisecurity.ldap.InitialDirContextFactory;
|
import org.acegisecurity.ldap.InitialDirContextFactory;
|
||||||
import org.acegisecurity.ldap.LdapTemplate;
|
import org.acegisecurity.ldap.SpringSecurityLdapTemplate;
|
||||||
|
|
||||||
import org.acegisecurity.providers.ldap.LdapAuthoritiesPopulator;
|
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.
|
* An initial context factory is only required if searching for groups is required.
|
||||||
*/
|
*/
|
||||||
private InitialDirContextFactory initialDirContextFactory = null;
|
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
|
* 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");
|
Assert.notNull(initialDirContextFactory, "InitialDirContextFactory must not be null");
|
||||||
this.initialDirContextFactory = initialDirContextFactory;
|
this.initialDirContextFactory = initialDirContextFactory;
|
||||||
|
|
||||||
ldapTemplate = new LdapTemplate(initialDirContextFactory);
|
ldapTemplate = new SpringSecurityLdapTemplate(initialDirContextFactory);
|
||||||
ldapTemplate.setSearchControls(searchControls);
|
ldapTemplate.setSearchControls(searchControls);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -55,6 +55,7 @@ import java.util.*;
|
||||||
*
|
*
|
||||||
* @author Luke Taylor
|
* @author Luke Taylor
|
||||||
* @since 2.0
|
* @since 2.0
|
||||||
|
* @version $Id$
|
||||||
*/
|
*/
|
||||||
public class LdapUserDetailsManager implements UserDetailsManager {
|
public class LdapUserDetailsManager implements UserDetailsManager {
|
||||||
private final Log logger = LogFactory.getLog(LdapUserDetailsManager.class);
|
private final Log logger = LogFactory.getLog(LdapUserDetailsManager.class);
|
||||||
|
|
|
@ -31,14 +31,14 @@ import javax.naming.directory.DirContext;
|
||||||
public class LdapTemplateTests extends AbstractLdapServerTestCase {
|
public class LdapTemplateTests extends AbstractLdapServerTestCase {
|
||||||
//~ Instance fields ================================================================================================
|
//~ Instance fields ================================================================================================
|
||||||
|
|
||||||
private LdapTemplate template;
|
private SpringSecurityLdapTemplate template;
|
||||||
|
|
||||||
//~ Methods ========================================================================================================
|
//~ Methods ========================================================================================================
|
||||||
|
|
||||||
protected void onSetUp() {
|
protected void onSetUp() {
|
||||||
getInitialCtxFactory().setManagerDn(MANAGER_USER);
|
getInitialCtxFactory().setManagerDn(MANAGER_USER);
|
||||||
getInitialCtxFactory().setManagerPassword(MANAGER_PASSWORD);
|
getInitialCtxFactory().setManagerPassword(MANAGER_PASSWORD);
|
||||||
template = new LdapTemplate(getInitialCtxFactory());
|
template = new SpringSecurityLdapTemplate(getInitialCtxFactory());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCompareOfCorrectByteValueSucceeds() {
|
public void testCompareOfCorrectByteValueSucceeds() {
|
||||||
|
|
|
@ -20,6 +20,8 @@ import org.acegisecurity.userdetails.UserDetails;
|
||||||
import org.acegisecurity.userdetails.UsernameNotFoundException;
|
import org.acegisecurity.userdetails.UsernameNotFoundException;
|
||||||
import org.acegisecurity.GrantedAuthority;
|
import org.acegisecurity.GrantedAuthority;
|
||||||
import org.acegisecurity.GrantedAuthorityImpl;
|
import org.acegisecurity.GrantedAuthorityImpl;
|
||||||
|
import org.acegisecurity.providers.UsernamePasswordAuthenticationToken;
|
||||||
|
import org.acegisecurity.context.SecurityContextHolder;
|
||||||
import org.springframework.ldap.LdapTemplate;
|
import org.springframework.ldap.LdapTemplate;
|
||||||
import org.springframework.ldap.support.DirContextAdapter;
|
import org.springframework.ldap.support.DirContextAdapter;
|
||||||
import org.springframework.ldap.support.DistinguishedName;
|
import org.springframework.ldap.support.DistinguishedName;
|
||||||
|
@ -82,6 +84,7 @@ public class LdapUserDetailsManagerTests extends AbstractLdapServerTestCase {
|
||||||
template.unbind("cn=clowns,ou=testgroups");
|
template.unbind("cn=clowns,ou=testgroups");
|
||||||
template.unbind("ou=testgroups");
|
template.unbind("ou=testgroups");
|
||||||
|
|
||||||
|
SecurityContextHolder.clearContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testLoadUserByUsernameReturnsCorrectData() {
|
public void testLoadUserByUsernameReturnsCorrectData() {
|
||||||
|
@ -149,5 +152,28 @@ public class LdapUserDetailsManagerTests extends AbstractLdapServerTestCase {
|
||||||
|
|
||||||
// Check that no authorities are left
|
// Check that no authorities are left
|
||||||
assertEquals(0, mgr.getUserAuthorities(mgr.buildDn("don"), "don").length);
|
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");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue