Collecting callback now top-level (LDAP-192).
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -87,10 +87,10 @@
|
||||
<programlisting>boolean authenticated = ldapTemplate.authenticate("", "(uid=john.doe)", "secret");</programlisting>
|
||||
</example></para>
|
||||
|
||||
<important>
|
||||
<tip>
|
||||
<para>Don't write your own custom authenticate methods. Use the ones
|
||||
provided in Spring LDAP 1.3.x.</para>
|
||||
</important>
|
||||
</tip>
|
||||
</sect1>
|
||||
|
||||
<sect1>
|
||||
@@ -212,7 +212,7 @@ ldapTemplate.authenticate("", "(uid=john.doe)", "secret", contextCallback));</pr
|
||||
<title>Convenience implementation of
|
||||
<literal>AuthenticationErrorCallback</literal>.</title>
|
||||
|
||||
<programlisting>public static final class CollectingErrorCallback implements AuthenticationErrorCallback {
|
||||
<programlisting>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));</pr
|
||||
<title>Authenticating a user and retrieving the authentication
|
||||
exception.</title>
|
||||
|
||||
<programlisting>import org.springframework.ldap.core.LdapTemplate.CollectingErrorCallback;
|
||||
<programlisting>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
|
||||
}</programlisting>
|
||||
</example></para>
|
||||
|
||||
<important>
|
||||
<para>Don't write your own custom authenticate methods that operate on
|
||||
the authenticated context. Use the ones provided in Spring LDAP
|
||||
1.3.1.</para>
|
||||
</important>
|
||||
</sect1>
|
||||
|
||||
<sect1>
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user