From ab62786774b0f6752ddaa92148dc5a8e27dcac81 Mon Sep 17 00:00:00 2001 From: Mattias Hellborg Arthursson Date: Fri, 30 Aug 2013 15:44:29 +0200 Subject: [PATCH] LDAP-258: Deprecated core-tiger module. --- .../AbstractParameterizedContextMapper.java | 4 +- ...textMapperCallbackHandlerWithControls.java | 9 +- .../simple/ParameterizedContextMapper.java | 5 +- ...arameterizedContextMapperWithControls.java | 6 +- .../core/simple/SimpleLdapOperations.java | 1 + .../ldap/core/simple/SimpleLdapTemplate.java | 12 +-- .../ldap/core/simple/package.html | 3 +- ...textMapperCallbackHandlerWithControls.java | 71 ++++++++++++++ .../support/ContextMapperWithControls.java | 37 +++++++ ...MapperCallbackHandlerWithControlsTest.java | 98 +++++++++++++++++++ src/docbkx/simple.xml | 15 +-- 11 files changed, 237 insertions(+), 24 deletions(-) create mode 100644 core/src/main/java/org/springframework/ldap/core/support/ContextMapperCallbackHandlerWithControls.java create mode 100644 core/src/main/java/org/springframework/ldap/core/support/ContextMapperWithControls.java create mode 100644 core/src/test/java/org/springframework/ldap/core/support/ContextMapperCallbackHandlerWithControlsTest.java diff --git a/core-tiger/src/main/java/org/springframework/ldap/core/simple/AbstractParameterizedContextMapper.java b/core-tiger/src/main/java/org/springframework/ldap/core/simple/AbstractParameterizedContextMapper.java index 8ad603f6..2d2502ad 100644 --- a/core-tiger/src/main/java/org/springframework/ldap/core/simple/AbstractParameterizedContextMapper.java +++ b/core-tiger/src/main/java/org/springframework/ldap/core/simple/AbstractParameterizedContextMapper.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2010 the original author or authors. + * Copyright 2005-2013 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,7 +26,7 @@ import org.springframework.ldap.core.DirContextOperations; * ClassCastException. * * @author Mattias Hellborg Arthursson - * + * @deprecated Core classes are parameterized as of 2.0. */ public abstract class AbstractParameterizedContextMapper implements ParameterizedContextMapper { diff --git a/core-tiger/src/main/java/org/springframework/ldap/core/simple/ContextMapperCallbackHandlerWithControls.java b/core-tiger/src/main/java/org/springframework/ldap/core/simple/ContextMapperCallbackHandlerWithControls.java index 183866b2..cd8c9e39 100644 --- a/core-tiger/src/main/java/org/springframework/ldap/core/simple/ContextMapperCallbackHandlerWithControls.java +++ b/core-tiger/src/main/java/org/springframework/ldap/core/simple/ContextMapperCallbackHandlerWithControls.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2010 the original author or authors. + * Copyright 2005-2013 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,13 +15,13 @@ */ package org.springframework.ldap.core.simple; +import org.springframework.ldap.core.ContextMapperCallbackHandler; +import org.springframework.ldap.core.ObjectRetrievalException; + import javax.naming.Binding; import javax.naming.NameClassPair; import javax.naming.ldap.HasControls; -import org.springframework.ldap.core.ContextMapperCallbackHandler; -import org.springframework.ldap.core.ObjectRetrievalException; - /** * Currently only per request controls can be inspected via the post process * method on a context processor. If a request control gives a different value @@ -34,6 +34,7 @@ import org.springframework.ldap.core.ObjectRetrievalException; * * @author Tim Terry * @author Ulrik Sandberg + * @deprecated use {@link org.springframework.ldap.core.support.ContextMapperCallbackHandlerWithControls} instead. */ public class ContextMapperCallbackHandlerWithControls extends ContextMapperCallbackHandler { diff --git a/core-tiger/src/main/java/org/springframework/ldap/core/simple/ParameterizedContextMapper.java b/core-tiger/src/main/java/org/springframework/ldap/core/simple/ParameterizedContextMapper.java index e9cc332d..d8ca6491 100644 --- a/core-tiger/src/main/java/org/springframework/ldap/core/simple/ParameterizedContextMapper.java +++ b/core-tiger/src/main/java/org/springframework/ldap/core/simple/ParameterizedContextMapper.java @@ -15,17 +15,18 @@ */ package org.springframework.ldap.core.simple; +import org.springframework.ldap.core.ContextMapper; + import javax.naming.Binding; import javax.naming.directory.SearchResult; -import org.springframework.ldap.core.ContextMapper; - /** * Extension of the {@link ContextMapper} interface. Uses Java 5 covariant * return types to override the return type of the * {@link #mapFromContext(Object)} method to be the type parameter T. * * @param + * @deprecated Core classes are parameterized as of 2.0. */ public interface ParameterizedContextMapper extends ContextMapper { diff --git a/core-tiger/src/main/java/org/springframework/ldap/core/simple/ParameterizedContextMapperWithControls.java b/core-tiger/src/main/java/org/springframework/ldap/core/simple/ParameterizedContextMapperWithControls.java index 3fa941ec..2b5eedc6 100644 --- a/core-tiger/src/main/java/org/springframework/ldap/core/simple/ParameterizedContextMapperWithControls.java +++ b/core-tiger/src/main/java/org/springframework/ldap/core/simple/ParameterizedContextMapperWithControls.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2010 the original author or authors. + * Copyright 2005-2013 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,8 +26,8 @@ import javax.naming.ldap.HasControls; * * @author Tim Terry * @author Ulrik Sandberg - * @param return type of the - * {@link #mapFromContextWithControls(Object, HasControls)} method + * @param return type of the {@link #mapFromContextWithControls(Object, HasControls)} method. + * @deprecated use {@link org.springframework.ldap.core.support.ContextMapperWithControls} instead. */ public interface ParameterizedContextMapperWithControls extends ParameterizedContextMapper { diff --git a/core-tiger/src/main/java/org/springframework/ldap/core/simple/SimpleLdapOperations.java b/core-tiger/src/main/java/org/springframework/ldap/core/simple/SimpleLdapOperations.java index 8cb66780..f85223fe 100644 --- a/core-tiger/src/main/java/org/springframework/ldap/core/simple/SimpleLdapOperations.java +++ b/core-tiger/src/main/java/org/springframework/ldap/core/simple/SimpleLdapOperations.java @@ -32,6 +32,7 @@ import java.util.List; * common LDAP operations. * * @author Mattias Hellborg Arthursson + * @deprecated Core classes are parameterized as of 2.0. */ public interface SimpleLdapOperations { diff --git a/core-tiger/src/main/java/org/springframework/ldap/core/simple/SimpleLdapTemplate.java b/core-tiger/src/main/java/org/springframework/ldap/core/simple/SimpleLdapTemplate.java index 74d389ed..bf19e22c 100644 --- a/core-tiger/src/main/java/org/springframework/ldap/core/simple/SimpleLdapTemplate.java +++ b/core-tiger/src/main/java/org/springframework/ldap/core/simple/SimpleLdapTemplate.java @@ -15,18 +15,17 @@ */ package org.springframework.ldap.core.simple; -import java.util.List; - -import javax.naming.Name; -import javax.naming.directory.Attributes; -import javax.naming.directory.SearchControls; - import org.springframework.ldap.core.ContextSource; import org.springframework.ldap.core.DirContextOperations; import org.springframework.ldap.core.DirContextProcessor; import org.springframework.ldap.core.LdapOperations; import org.springframework.ldap.core.LdapTemplate; +import javax.naming.Name; +import javax.naming.directory.Attributes; +import javax.naming.directory.SearchControls; +import java.util.List; + /** * Java-5-based convenience wrapper for the classic LdapTemplate, adding some * convenient shortcuts and taking advantage of Java 5 Generics. @@ -35,6 +34,7 @@ import org.springframework.ldap.core.LdapTemplate; * commonly used template methods. * * @author Mattias Hellborg Arthursson + * @deprecated Core classes are parameterized as of 2.0. */ public class SimpleLdapTemplate implements SimpleLdapOperations { diff --git a/core-tiger/src/main/java/org/springframework/ldap/core/simple/package.html b/core-tiger/src/main/java/org/springframework/ldap/core/simple/package.html index 56f3b7ec..b6d396c6 100644 --- a/core-tiger/src/main/java/org/springframework/ldap/core/simple/package.html +++ b/core-tiger/src/main/java/org/springframework/ldap/core/simple/package.html @@ -1,7 +1,8 @@ -Simplification layer over LdapTemplate for Java 5 and above. +Simplification layer over LdapTemplate for Java 5 and above. As of Spring LDAP 2.0 all interfaces and classes +in this package are deprecated. diff --git a/core/src/main/java/org/springframework/ldap/core/support/ContextMapperCallbackHandlerWithControls.java b/core/src/main/java/org/springframework/ldap/core/support/ContextMapperCallbackHandlerWithControls.java new file mode 100644 index 00000000..3e68ea97 --- /dev/null +++ b/core/src/main/java/org/springframework/ldap/core/support/ContextMapperCallbackHandlerWithControls.java @@ -0,0 +1,71 @@ +/* + * Copyright 2005-2013 the original author or authors. + * + * 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.ldap.core.support; + +import org.springframework.ldap.core.ContextMapperCallbackHandler; +import org.springframework.ldap.core.ObjectRetrievalException; + +import javax.naming.Binding; +import javax.naming.NameClassPair; +import javax.naming.NamingException; +import javax.naming.ldap.HasControls; + +/** + * Currently only per request controls can be inspected via the post process + * method on a context processor. If a request control gives a different value + * for each search result, then this cannot be inspected using the existing + * support classes. An example control that requires this feature would be + * 1.3.6.1.4.1.42.2.27.9.5.8 Account usability control, that can be used with + * for example the Sun ONE or the OpenDS directory servers. + * + * The extended callback handler can pass hasControls to mapper. + * + * @author Tim Terry + * @author Ulrik Sandberg + */ +public class ContextMapperCallbackHandlerWithControls extends ContextMapperCallbackHandler { + + private ContextMapperWithControls mapper = null; + + public ContextMapperCallbackHandlerWithControls(final ContextMapperWithControls mapper) { + super(mapper); + this.mapper = mapper; + } + + /* + * @see org.springframework.ldap.core.ContextMapperCallbackHandler# + * getObjectFromNameClassPair(javax.naming.NameClassPair) + */ + public T getObjectFromNameClassPair(final NameClassPair nameClassPair) throws NamingException{ + if (!(nameClassPair instanceof Binding)) { + throw new IllegalArgumentException("Parameter must be an instance of Binding"); + } + + Binding binding = (Binding) nameClassPair; + Object object = binding.getObject(); + if (object == null) { + throw new ObjectRetrievalException("Binding did not contain any object."); + } + T result; + if (nameClassPair instanceof HasControls) { + result = mapper.mapFromContextWithControls(object, (HasControls) nameClassPair); + } + else { + result = mapper.mapFromContext(object); + } + return result; + } +} diff --git a/core/src/main/java/org/springframework/ldap/core/support/ContextMapperWithControls.java b/core/src/main/java/org/springframework/ldap/core/support/ContextMapperWithControls.java new file mode 100644 index 00000000..a0d6662a --- /dev/null +++ b/core/src/main/java/org/springframework/ldap/core/support/ContextMapperWithControls.java @@ -0,0 +1,37 @@ +/* + * Copyright 2005-2013 the original author or authors. + * + * 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.ldap.core.support; + +import org.springframework.ldap.core.ContextMapper; + +import javax.naming.NamingException; +import javax.naming.ldap.HasControls; + +/** + * Extension of the {@link org.springframework.ldap.core.ContextMapper} interface that allows + * controls to be passed to the mapper implementation. Uses Java 5 covariant + * return types to override the return type of the + * {@link #mapFromContextWithControls(Object, javax.naming.ldap.HasControls)} method to be the + * type parameter T. + * + * @author Tim Terry + * @author Ulrik Sandberg + * @param return type of the + * {@link #mapFromContextWithControls(Object, javax.naming.ldap.HasControls)} method + */ +public interface ContextMapperWithControls extends ContextMapper { + T mapFromContextWithControls(final Object ctx, final HasControls hasControls) throws NamingException; +} diff --git a/core/src/test/java/org/springframework/ldap/core/support/ContextMapperCallbackHandlerWithControlsTest.java b/core/src/test/java/org/springframework/ldap/core/support/ContextMapperCallbackHandlerWithControlsTest.java new file mode 100644 index 00000000..4a1596ca --- /dev/null +++ b/core/src/test/java/org/springframework/ldap/core/support/ContextMapperCallbackHandlerWithControlsTest.java @@ -0,0 +1,98 @@ +/* + * Copyright 2005-2013 the original author or authors. + * + * 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.ldap.core.support; + +import org.junit.Before; +import org.junit.Test; +import org.springframework.ldap.core.ObjectRetrievalException; + +import javax.naming.Binding; +import javax.naming.NamingException; +import javax.naming.ldap.Control; +import javax.naming.ldap.HasControls; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +/** + * @Ulrik Sandberg + * @author Mattias Hellborg Arthursson + */ +public class ContextMapperCallbackHandlerWithControlsTest { + private ContextMapperWithControls mapperMock; + + private ContextMapperCallbackHandlerWithControls tested; + + private static class MyBindingThatHasControls extends Binding implements HasControls { + private static final long serialVersionUID = 1L; + + public MyBindingThatHasControls(String name, Object obj) { + super(name, obj); + } + + public Control[] getControls() throws NamingException { + return null; + } + } + + @SuppressWarnings("unchecked") + @Before + public void setUp() throws Exception { + mapperMock = mock(ContextMapperWithControls.class); + tested = new ContextMapperCallbackHandlerWithControls(mapperMock); + } + + @Test(expected = IllegalArgumentException.class) + public void testConstructorWithEmptyArgument() { + new ContextMapperCallbackHandlerWithControls(null); + } + + @Test + public void testGetObjectFromNameClassPair() throws NamingException { + Object expectedObject = "object"; + Object expectedResult = "result"; + Binding expectedBinding = new Binding("some name", expectedObject); + + when(mapperMock.mapFromContext(expectedObject)).thenReturn(expectedResult); + + Object actualResult = tested.getObjectFromNameClassPair(expectedBinding); + + assertEquals(expectedResult, actualResult); + } + + @Test + public void testGetObjectFromNameClassPairImplementingHasControls() throws NamingException { + Object expectedObject = "object"; + Object expectedResult = "result"; + MyBindingThatHasControls expectedBinding = new MyBindingThatHasControls("some name", expectedObject); + + when(mapperMock.mapFromContextWithControls(expectedObject, expectedBinding)).thenReturn(expectedResult); + + Object actualResult = tested.getObjectFromNameClassPair(expectedBinding); + + assertEquals(expectedResult, actualResult); + } + + @Test(expected = ObjectRetrievalException.class) + public void testGetObjectFromNameClassPairObjectRetrievalException() throws NamingException { + Binding expectedBinding = new Binding("some name", null); + + tested.getObjectFromNameClassPair(expectedBinding); + } + +} diff --git a/src/docbkx/simple.xml b/src/docbkx/simple.xml index 967cbe71..788e2bd1 100644 --- a/src/docbkx/simple.xml +++ b/src/docbkx/simple.xml @@ -1,11 +1,14 @@ - + Java 5 Support - - - SimpleLdapTemplate - + + + SimpleLdapTemplate + + As of Spring LDAP 2.0 the core API has full Java 5 support, and SimpleLdapTemplate + and associated classes are all deprecated. + As of version 1.3 Spring LDAP includes the spring-ldap-core-tiger.jar distributable, which adds a thin layer of Java 5 functionality on top of Spring LDAP. @@ -32,4 +35,4 @@ - +