From 953a4ab9eaa38e64a768df8ff2c54e9451e3e4be Mon Sep 17 00:00:00 2001 From: Luke Taylor Date: Fri, 5 Dec 2008 22:30:26 +0000 Subject: [PATCH] SEC-1036: Removed deprecated class and unnecessary mock. --- .../ldap/LdapDataAccessException.java | 39 ----------- .../ldap/MockSpringSecurityContextSource.java | 68 ------------------- ...swordComparisonAuthenticatorMockTests.java | 29 ++++---- 3 files changed, 15 insertions(+), 121 deletions(-) delete mode 100644 core/src/main/java/org/springframework/security/ldap/LdapDataAccessException.java delete mode 100644 core/src/test/java/org/springframework/security/ldap/MockSpringSecurityContextSource.java diff --git a/core/src/main/java/org/springframework/security/ldap/LdapDataAccessException.java b/core/src/main/java/org/springframework/security/ldap/LdapDataAccessException.java deleted file mode 100644 index a5e1983a33..0000000000 --- a/core/src/main/java/org/springframework/security/ldap/LdapDataAccessException.java +++ /dev/null @@ -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); - } -} diff --git a/core/src/test/java/org/springframework/security/ldap/MockSpringSecurityContextSource.java b/core/src/test/java/org/springframework/security/ldap/MockSpringSecurityContextSource.java deleted file mode 100644 index ad34b3dd6a..0000000000 --- a/core/src/test/java/org/springframework/security/ldap/MockSpringSecurityContextSource.java +++ /dev/null @@ -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(); - } -} diff --git a/core/src/test/java/org/springframework/security/providers/ldap/authenticator/PasswordComparisonAuthenticatorMockTests.java b/core/src/test/java/org/springframework/security/providers/ldap/authenticator/PasswordComparisonAuthenticatorMockTests.java index f7beeee001..50734cd9d8 100644 --- a/core/src/test/java/org/springframework/security/providers/ldap/authenticator/PasswordComparisonAuthenticatorMockTests.java +++ b/core/src/test/java/org/springframework/security/providers/ldap/authenticator/PasswordComparisonAuthenticatorMockTests.java @@ -15,19 +15,19 @@ 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.Mockery; import org.jmock.integration.junit4.JUnit4Mockery; import org.junit.Test; -import org.springframework.security.ldap.MockSpringSecurityContextSource; +import org.springframework.ldap.core.support.BaseLdapPathContextSource; 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$ */ public class PasswordComparisonAuthenticatorMockTests { - Mockery context = new JUnit4Mockery(); + Mockery jmock = new JUnit4Mockery(); //~ Methods ======================================================================================================== @Test 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(); attrs.put(new BasicAttribute("uid", "bob")); - PasswordComparisonAuthenticator authenticator = - new PasswordComparisonAuthenticator(new MockSpringSecurityContextSource(dirCtx, "")); + PasswordComparisonAuthenticator authenticator = new PasswordComparisonAuthenticator(source); authenticator.setUserDnPatterns(new String[] {"cn={0},ou=people"}); // 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).getNameInNamespace(); will(returnValue("dc=springframework,dc=org")); }}); @@ -59,7 +60,7 @@ public class PasswordComparisonAuthenticatorMockTests { // Setup a single return value (i.e. success) final Attributes searchResults = new BasicAttributes("", null); - context.checking(new Expectations() {{ + jmock.checking(new Expectations() {{ oneOf(dirCtx).search(with(equal("cn=Bob,ou=people")), with(equal("(userPassword={0})")), with(aNonNull(Object[].class)), @@ -70,6 +71,6 @@ public class PasswordComparisonAuthenticatorMockTests { authenticator.authenticate(new UsernamePasswordAuthenticationToken("Bob","bobspassword")); - context.assertIsSatisfied(); + jmock.assertIsSatisfied(); } }