mirror of
https://github.com/spring-projects/spring-security.git
synced 2025-06-29 15:22:15 +00:00
SEC-1036: Removed deprecated class and unnecessary mock.
This commit is contained in:
parent
6293541b73
commit
953a4ab9ea
@ -1,39 +0,0 @@
|
|||||||
/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.springframework.security.ldap;
|
|
||||||
|
|
||||||
import org.springframework.dao.DataAccessException;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Used to wrap unexpected NamingExceptions while accessing the LDAP server or for other LDAP-related data problems
|
|
||||||
* such as data we can't handle.
|
|
||||||
*
|
|
||||||
* @deprecated Spring LDAP classes are now used instead.
|
|
||||||
* @author Luke Taylor
|
|
||||||
* @version $Id$
|
|
||||||
*/
|
|
||||||
public class LdapDataAccessException extends DataAccessException {
|
|
||||||
//~ Constructors ===================================================================================================
|
|
||||||
|
|
||||||
public LdapDataAccessException(String msg) {
|
|
||||||
super(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
public LdapDataAccessException(String msg, Throwable ex) {
|
|
||||||
super(msg, ex);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,68 +0,0 @@
|
|||||||
/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.springframework.security.ldap;
|
|
||||||
|
|
||||||
import javax.naming.directory.DirContext;
|
|
||||||
|
|
||||||
import org.springframework.dao.DataAccessException;
|
|
||||||
import org.springframework.ldap.NamingException;
|
|
||||||
import org.springframework.ldap.core.DistinguishedName;
|
|
||||||
import org.springframework.ldap.core.support.BaseLdapPathContextSource;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Luke Taylor
|
|
||||||
* @version $Id$
|
|
||||||
*/
|
|
||||||
public class MockSpringSecurityContextSource implements BaseLdapPathContextSource {
|
|
||||||
//~ Instance fields ================================================================================================
|
|
||||||
|
|
||||||
private DirContext ctx;
|
|
||||||
private String baseDn;
|
|
||||||
|
|
||||||
//~ Constructors ===================================================================================================
|
|
||||||
|
|
||||||
public MockSpringSecurityContextSource() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public MockSpringSecurityContextSource(DirContext ctx, String baseDn) {
|
|
||||||
this.baseDn = baseDn;
|
|
||||||
this.ctx = ctx;
|
|
||||||
}
|
|
||||||
|
|
||||||
//~ Methods ========================================================================================================
|
|
||||||
|
|
||||||
public DirContext getReadOnlyContext() throws DataAccessException {
|
|
||||||
return ctx;
|
|
||||||
}
|
|
||||||
|
|
||||||
public DirContext getReadWriteContext() throws DataAccessException {
|
|
||||||
return ctx;
|
|
||||||
}
|
|
||||||
|
|
||||||
public DirContext getContext(String principal, String credentials) throws NamingException {
|
|
||||||
return ctx;
|
|
||||||
}
|
|
||||||
|
|
||||||
public DistinguishedName getBaseLdapPath() {
|
|
||||||
return new DistinguishedName(baseDn);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getBaseLdapPathAsString() {
|
|
||||||
return getBaseLdapPath().toString();
|
|
||||||
}
|
|
||||||
}
|
|
@ -15,19 +15,19 @@
|
|||||||
|
|
||||||
package org.springframework.security.providers.ldap.authenticator;
|
package org.springframework.security.providers.ldap.authenticator;
|
||||||
|
|
||||||
|
import javax.naming.directory.Attributes;
|
||||||
|
import javax.naming.directory.BasicAttribute;
|
||||||
|
import javax.naming.directory.BasicAttributes;
|
||||||
|
import javax.naming.directory.DirContext;
|
||||||
|
import javax.naming.directory.SearchControls;
|
||||||
|
|
||||||
import org.jmock.Expectations;
|
import org.jmock.Expectations;
|
||||||
import org.jmock.Mockery;
|
import org.jmock.Mockery;
|
||||||
import org.jmock.integration.junit4.JUnit4Mockery;
|
import org.jmock.integration.junit4.JUnit4Mockery;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.security.ldap.MockSpringSecurityContextSource;
|
import org.springframework.ldap.core.support.BaseLdapPathContextSource;
|
||||||
import org.springframework.security.providers.UsernamePasswordAuthenticationToken;
|
import org.springframework.security.providers.UsernamePasswordAuthenticationToken;
|
||||||
|
|
||||||
import javax.naming.directory.Attributes;
|
|
||||||
import javax.naming.directory.BasicAttributes;
|
|
||||||
import javax.naming.directory.DirContext;
|
|
||||||
import javax.naming.directory.BasicAttribute;
|
|
||||||
import javax.naming.directory.SearchControls;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -35,23 +35,24 @@ import javax.naming.directory.SearchControls;
|
|||||||
* @version $Id$
|
* @version $Id$
|
||||||
*/
|
*/
|
||||||
public class PasswordComparisonAuthenticatorMockTests {
|
public class PasswordComparisonAuthenticatorMockTests {
|
||||||
Mockery context = new JUnit4Mockery();
|
Mockery jmock = new JUnit4Mockery();
|
||||||
|
|
||||||
//~ Methods ========================================================================================================
|
//~ Methods ========================================================================================================
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void ldapCompareOperationIsUsedWhenPasswordIsNotRetrieved() throws Exception {
|
public void ldapCompareOperationIsUsedWhenPasswordIsNotRetrieved() throws Exception {
|
||||||
final DirContext dirCtx = context.mock(DirContext.class);
|
final DirContext dirCtx = jmock.mock(DirContext.class);
|
||||||
|
final BaseLdapPathContextSource source = jmock.mock(BaseLdapPathContextSource.class);
|
||||||
final BasicAttributes attrs = new BasicAttributes();
|
final BasicAttributes attrs = new BasicAttributes();
|
||||||
attrs.put(new BasicAttribute("uid", "bob"));
|
attrs.put(new BasicAttribute("uid", "bob"));
|
||||||
|
|
||||||
PasswordComparisonAuthenticator authenticator =
|
PasswordComparisonAuthenticator authenticator = new PasswordComparisonAuthenticator(source);
|
||||||
new PasswordComparisonAuthenticator(new MockSpringSecurityContextSource(dirCtx, ""));
|
|
||||||
|
|
||||||
authenticator.setUserDnPatterns(new String[] {"cn={0},ou=people"});
|
authenticator.setUserDnPatterns(new String[] {"cn={0},ou=people"});
|
||||||
|
|
||||||
// Get the mock to return an empty attribute set
|
// Get the mock to return an empty attribute set
|
||||||
context.checking(new Expectations() {{
|
jmock.checking(new Expectations() {{
|
||||||
|
allowing(source).getReadOnlyContext(); will(returnValue(dirCtx));
|
||||||
oneOf(dirCtx).getAttributes(with(equal("cn=Bob,ou=people")), with(aNull(String[].class))); will(returnValue(attrs));
|
oneOf(dirCtx).getAttributes(with(equal("cn=Bob,ou=people")), with(aNull(String[].class))); will(returnValue(attrs));
|
||||||
oneOf(dirCtx).getNameInNamespace(); will(returnValue("dc=springframework,dc=org"));
|
oneOf(dirCtx).getNameInNamespace(); will(returnValue("dc=springframework,dc=org"));
|
||||||
}});
|
}});
|
||||||
@ -59,7 +60,7 @@ public class PasswordComparisonAuthenticatorMockTests {
|
|||||||
// Setup a single return value (i.e. success)
|
// Setup a single return value (i.e. success)
|
||||||
final Attributes searchResults = new BasicAttributes("", null);
|
final Attributes searchResults = new BasicAttributes("", null);
|
||||||
|
|
||||||
context.checking(new Expectations() {{
|
jmock.checking(new Expectations() {{
|
||||||
oneOf(dirCtx).search(with(equal("cn=Bob,ou=people")),
|
oneOf(dirCtx).search(with(equal("cn=Bob,ou=people")),
|
||||||
with(equal("(userPassword={0})")),
|
with(equal("(userPassword={0})")),
|
||||||
with(aNonNull(Object[].class)),
|
with(aNonNull(Object[].class)),
|
||||||
@ -70,6 +71,6 @@ public class PasswordComparisonAuthenticatorMockTests {
|
|||||||
|
|
||||||
authenticator.authenticate(new UsernamePasswordAuthenticationToken("Bob","bobspassword"));
|
authenticator.authenticate(new UsernamePasswordAuthenticationToken("Bob","bobspassword"));
|
||||||
|
|
||||||
context.assertIsSatisfied();
|
jmock.assertIsSatisfied();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user