Adding flag for authenticator to avoid autowiring exceptions
Adds a isValid() method to the authenticator to avoid exceptions during initialization.
This commit is contained in:
parent
c9ca73b94c
commit
2aa6cdf6c6
|
@ -24,9 +24,15 @@ package org.apache.archiva.redback.authentication;
|
|||
public abstract class AbstractAuthenticator
|
||||
implements Authenticator
|
||||
{
|
||||
protected boolean valid = false;
|
||||
|
||||
public void initialize()
|
||||
throws AuthenticationException
|
||||
{
|
||||
// no op
|
||||
valid = true;
|
||||
}
|
||||
|
||||
public boolean isValid() {
|
||||
return valid;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,4 +38,6 @@ public interface Authenticator
|
|||
throws AccountLockedException, AuthenticationException, MustChangePasswordException;
|
||||
|
||||
void initialize() throws AuthenticationException;
|
||||
|
||||
boolean isValid();
|
||||
}
|
||||
|
|
|
@ -92,7 +92,7 @@ public class DefaultAuthenticationManager
|
|||
List<AuthenticationFailureCause> authnResultErrors = new ArrayList<AuthenticationFailureCause>();
|
||||
for ( Authenticator authenticator : authenticators )
|
||||
{
|
||||
if ( authenticator.supportsDataSource( source ) )
|
||||
if ( authenticator.isValid() && authenticator.supportsDataSource( source ) )
|
||||
{
|
||||
AuthenticationResult authResult = authenticator.authenticate( source );
|
||||
List<AuthenticationFailureCause> authenticationFailureCauses =
|
||||
|
|
|
@ -208,4 +208,9 @@ public class LdapBindAuthenticator
|
|||
log.warn( "skip exception closing naming search result {}", e.getMessage() );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid() {
|
||||
return connectionFactory.isValid();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,6 +21,8 @@ package org.apache.archiva.redback.common.ldap.connection;
|
|||
|
||||
import org.apache.archiva.redback.configuration.UserConfiguration;
|
||||
import org.apache.archiva.redback.configuration.UserConfigurationKeys;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
@ -41,6 +43,8 @@ public class ConfigurableLdapConnectionFactory
|
|||
implements LdapConnectionFactory
|
||||
{
|
||||
|
||||
private final Logger log = LoggerFactory.getLogger(ConfigurableLdapConnectionFactory.class);
|
||||
|
||||
private String hostname;
|
||||
|
||||
private int port;
|
||||
|
@ -61,6 +65,8 @@ public class ConfigurableLdapConnectionFactory
|
|||
|
||||
private LdapConnectionConfiguration ldapConnectionConfiguration;
|
||||
|
||||
private boolean valid = false;
|
||||
|
||||
|
||||
@Inject
|
||||
@Named(value = "userConfiguration#default")
|
||||
|
@ -90,10 +96,11 @@ public class ConfigurableLdapConnectionFactory
|
|||
ldapConnectionConfiguration.setAuthenticationMethod(
|
||||
userConf.getString( UserConfigurationKeys.LDAP_AUTHENTICATION_METHOD, authenticationMethod ) );
|
||||
ldapConnectionConfiguration.setExtraProperties( extraProperties );
|
||||
valid = true;
|
||||
}
|
||||
catch ( InvalidNameException e )
|
||||
{
|
||||
throw new RuntimeException( "Error while initializing connection factory.", e );
|
||||
log.error("Error during initialization of LdapConnectionFactory "+e.getMessage(),e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -266,4 +273,8 @@ public class ConfigurableLdapConnectionFactory
|
|||
{
|
||||
this.userConf = userConf;
|
||||
}
|
||||
|
||||
public boolean isValid() {
|
||||
return valid;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -51,4 +51,6 @@ public interface LdapConnectionFactory
|
|||
|
||||
void initialize();
|
||||
|
||||
public boolean isValid();
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue