From 1d47163f9dab80e3c868d3d19d7a07ff84ef0d97 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Tue, 4 Dec 2012 15:07:13 +0000 Subject: take of having all authenticator exceptions returned git-svn-id: https://svn.apache.org/repos/asf/archiva/redback/redback-core/trunk@1416980 13f79535-47bb-0310-9956-ffa450edef68 --- .../authentication/AuthenticationConstants.java | 5 +++++ .../authentication/AuthenticationResult.java | 1 + .../DefaultAuthenticationManager.java | 26 +++++++++++++++------- .../authentication/ldap/LdapBindAuthenticator.java | 3 +++ 4 files changed, 27 insertions(+), 8 deletions(-) (limited to 'redback-authentication') diff --git a/redback-authentication/redback-authentication-api/src/main/java/org/apache/archiva/redback/authentication/AuthenticationConstants.java b/redback-authentication/redback-authentication-api/src/main/java/org/apache/archiva/redback/authentication/AuthenticationConstants.java index 35c9bfd7e..88e4d2b61 100644 --- a/redback-authentication/redback-authentication-api/src/main/java/org/apache/archiva/redback/authentication/AuthenticationConstants.java +++ b/redback-authentication/redback-authentication-api/src/main/java/org/apache/archiva/redback/authentication/AuthenticationConstants.java @@ -29,4 +29,9 @@ public class AuthenticationConstants // for User Manager Authenticator public static final String AUTHN_NO_SUCH_USER = "1"; + /** + * @since 2.1 + */ + public static final String AUTHN_RUNTIME_EXCEPTION = "2"; + } diff --git a/redback-authentication/redback-authentication-api/src/main/java/org/apache/archiva/redback/authentication/AuthenticationResult.java b/redback-authentication/redback-authentication-api/src/main/java/org/apache/archiva/redback/authentication/AuthenticationResult.java index 90a4cf07e..2608959a4 100644 --- a/redback-authentication/redback-authentication-api/src/main/java/org/apache/archiva/redback/authentication/AuthenticationResult.java +++ b/redback-authentication/redback-authentication-api/src/main/java/org/apache/archiva/redback/authentication/AuthenticationResult.java @@ -22,6 +22,7 @@ package org.apache.archiva.redback.authentication; import org.apache.archiva.redback.users.User; import java.io.Serializable; +import java.util.HashMap; import java.util.Map; /** diff --git a/redback-authentication/redback-authentication-api/src/main/java/org/apache/archiva/redback/authentication/DefaultAuthenticationManager.java b/redback-authentication/redback-authentication-api/src/main/java/org/apache/archiva/redback/authentication/DefaultAuthenticationManager.java index b05539b0f..85c6d5958 100644 --- a/redback-authentication/redback-authentication-api/src/main/java/org/apache/archiva/redback/authentication/DefaultAuthenticationManager.java +++ b/redback-authentication/redback-authentication-api/src/main/java/org/apache/archiva/redback/authentication/DefaultAuthenticationManager.java @@ -46,21 +46,21 @@ import java.util.Map; public class DefaultAuthenticationManager implements AuthenticationManager { - + private List authenticators; @Inject private ApplicationContext applicationContext; - + @SuppressWarnings("unchecked") @PostConstruct public void initialize() { - this.authenticators = new ArrayList - ( applicationContext.getBeansOfType( Authenticator.class ).values() ); + this.authenticators = + new ArrayList( applicationContext.getBeansOfType( Authenticator.class ).values() ); } - - + + public String getId() { return "Default Authentication Manager - " + this.getClass().getName() + " : managed authenticators - " + @@ -77,13 +77,13 @@ public class DefaultAuthenticationManager } // put AuthenticationResult exceptions in a map - Map authnResultExceptionsMap = new HashMap(); + Map authnResultExceptionsMap = new HashMap(); for ( Authenticator authenticator : authenticators ) { if ( authenticator.supportsDataSource( source ) ) { AuthenticationResult authResult = authenticator.authenticate( source ); - Map exceptionsMap = authResult.getExceptionsMap(); + Map exceptionsMap = authResult.getExceptionsMap(); if ( authResult.isAuthenticated() ) { @@ -94,6 +94,16 @@ public class DefaultAuthenticationManager { authnResultExceptionsMap.putAll( exceptionsMap ); } + else + { + if ( authResult.getException() != null ) + { + authnResultExceptionsMap.put( AuthenticationConstants.AUTHN_RUNTIME_EXCEPTION, + authResult.getException().getMessage() ); + } + } + + } } diff --git a/redback-authentication/redback-authentication-providers/redback-authentication-ldap/src/main/java/org/apache/archiva/redback/authentication/ldap/LdapBindAuthenticator.java b/redback-authentication/redback-authentication-providers/redback-authentication-ldap/src/main/java/org/apache/archiva/redback/authentication/ldap/LdapBindAuthenticator.java index 56b86b13f..3269c1a77 100644 --- a/redback-authentication/redback-authentication-providers/redback-authentication-ldap/src/main/java/org/apache/archiva/redback/authentication/ldap/LdapBindAuthenticator.java +++ b/redback-authentication/redback-authentication-providers/redback-authentication-ldap/src/main/java/org/apache/archiva/redback/authentication/ldap/LdapBindAuthenticator.java @@ -19,6 +19,7 @@ package org.apache.archiva.redback.authentication.ldap; * under the License. */ +import org.apache.archiva.redback.authentication.AuthenticationConstants; import org.apache.archiva.redback.common.ldap.UserMapper; import org.apache.archiva.redback.common.ldap.connection.LdapConnectionFactory; import org.apache.archiva.redback.configuration.UserConfiguration; @@ -42,6 +43,8 @@ import javax.naming.NamingException; import javax.naming.directory.DirContext; import javax.naming.directory.SearchControls; import javax.naming.directory.SearchResult; +import java.util.HashMap; +import java.util.Map; /** * LdapBindAuthenticator: -- cgit v1.2.3