diff --git a/core/src/main/java/org/springframework/ldap/core/LdapTemplate.java b/core/src/main/java/org/springframework/ldap/core/LdapTemplate.java
index 0d824e5e..586ff145 100644
--- a/core/src/main/java/org/springframework/ldap/core/LdapTemplate.java
+++ b/core/src/main/java/org/springframework/ldap/core/LdapTemplate.java
@@ -1549,17 +1549,4 @@ public class LdapTemplate implements LdapOperations, InitializingBean {
// Do nothing
}
}
-
- public static final class CollectingErrorCallback implements
- AuthenticationErrorCallback {
- private Exception error;
-
- public void execute(Exception e) {
- this.error = e;
- }
-
- public Exception getError() {
- return error;
- }
- }
}
diff --git a/core/src/main/java/org/springframework/ldap/core/support/CollectingAuthenticationErrorCallback.java b/core/src/main/java/org/springframework/ldap/core/support/CollectingAuthenticationErrorCallback.java
new file mode 100644
index 00000000..7db04894
--- /dev/null
+++ b/core/src/main/java/org/springframework/ldap/core/support/CollectingAuthenticationErrorCallback.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2005-2008 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.AuthenticationErrorCallback;
+
+/**
+ * Convenience implementation of AuthenticationErrorCallback that stores the
+ * given exception and provides a method for retrieving it. The caller of the
+ * authenticate method can provide an instance of this class as an error
+ * callback. If the authentication fails, the caller can ask the callback
+ * instance for the actual authentication exception.
+ *
+ * @author Ulrik Sandberg
+ * @since 1.3.1
+ */
+public final class CollectingAuthenticationErrorCallback implements AuthenticationErrorCallback {
+ private Exception error;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.springframework.ldap.core.AuthenticationErrorCallback#execute(java
+ * .lang.Exception)
+ */
+ public void execute(Exception e) {
+ this.error = e;
+ }
+
+ /**
+ * @return the collected exception
+ */
+ public Exception getError() {
+ return error;
+ }
+}
\ No newline at end of file
diff --git a/src/docbkx/user-authentication.xml b/src/docbkx/user-authentication.xml
index f29d7dac..c8ad5759 100644
--- a/src/docbkx/user-authentication.xml
+++ b/src/docbkx/user-authentication.xml
@@ -87,10 +87,10 @@
boolean authenticated = ldapTemplate.authenticate("", "(uid=john.doe)", "secret");
-
+
Don't write your own custom authenticate methods. Use the ones
provided in Spring LDAP 1.3.x.
-
+
@@ -212,7 +212,7 @@ ldapTemplate.authenticate("", "(uid=john.doe)", "secret", contextCallback));Convenience implementation of
AuthenticationErrorCallback.
- public static final class CollectingErrorCallback implements AuthenticationErrorCallback {
+ public final class CollectingAuthenticationErrorCallback implements AuthenticationErrorCallback {
private Exception error;
public void execute(Exception e) {
@@ -230,21 +230,15 @@ ldapTemplate.authenticate("", "(uid=john.doe)", "secret", contextCallback));Authenticating a user and retrieving the authentication
exception.
- import org.springframework.ldap.core.LdapTemplate.CollectingErrorCallback;
+ import org.springframework.ldap.core.support.CollectingAuthenticationErrorCallback;
...
-CollectingErrorCallback errorCallback = new CollectingErrorCallback();
+CollectingAuthenticationErrorCallback errorCallback = new CollectingAuthenticationErrorCallback();
boolean result = tested.authenticate("", filter.toString(), "invalidpassword", errorCallback);
if (!result) {
Exception error = errorCallback.getError();
// error is likely of type org.springframework.ldap.AuthenticationException
}
-
-
- Don't write your own custom authenticate methods that operate on
- the authenticated context. Use the ones provided in Spring LDAP
- 1.3.1.
-
diff --git a/test/integration-tests/src/test/java/org/springframework/ldap/LdapTemplateAuthenticationITest.java b/test/integration-tests/src/test/java/org/springframework/ldap/LdapTemplateAuthenticationITest.java
index d98c38f7..d190e74e 100644
--- a/test/integration-tests/src/test/java/org/springframework/ldap/LdapTemplateAuthenticationITest.java
+++ b/test/integration-tests/src/test/java/org/springframework/ldap/LdapTemplateAuthenticationITest.java
@@ -30,7 +30,7 @@ import org.springframework.ldap.core.AuthenticatedLdapEntryContextCallback;
import org.springframework.ldap.core.DirContextAdapter;
import org.springframework.ldap.core.LdapEntryIdentification;
import org.springframework.ldap.core.LdapTemplate;
-import org.springframework.ldap.core.LdapTemplate.CollectingErrorCallback;
+import org.springframework.ldap.core.support.CollectingAuthenticationErrorCallback;
import org.springframework.ldap.filter.AndFilter;
import org.springframework.ldap.filter.EqualsFilter;
import org.springframework.ldap.filter.WhitespaceWildcardsFilter;
@@ -84,7 +84,7 @@ public class LdapTemplateAuthenticationITest extends AbstractLdapTemplateIntegra
public void testAuthenticateWithInvalidPasswordAndCollectedException() {
AndFilter filter = new AndFilter();
filter.and(new EqualsFilter("objectclass", "person")).and(new EqualsFilter("uid", "some.person3"));
- final CollectingErrorCallback errorCallback = new CollectingErrorCallback();
+ final CollectingAuthenticationErrorCallback errorCallback = new CollectingAuthenticationErrorCallback();
assertFalse(tested.authenticate("", filter.toString(), "invalidpassword", errorCallback));
final Exception error = errorCallback.getError();
assertNotNull("collected error should not be null", error);