Skip to content
Permalink
Browse files
Adding flag for authenticator to avoid autowiring exceptions
Adds a isValid() method to the authenticator to avoid exceptions during
initialization.
  • Loading branch information
effrafax committed Oct 16, 2016
1 parent c9ca73b commit 2aa6cdf6c6c89684a04f2f357dabad65c2fb9627
Showing 6 changed files with 29 additions and 3 deletions.
@@ -24,9 +24,15 @@
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 @@ AuthenticationResult authenticate( AuthenticationDataSource source )
throws AccountLockedException, AuthenticationException, MustChangePasswordException;

void initialize() throws AuthenticationException;

boolean isValid();
}
@@ -92,7 +92,7 @@ public AuthenticationResult authenticate( AuthenticationDataSource source )
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 @@ private void closeNamingEnumeration( NamingEnumeration<SearchResult> results )
log.warn( "skip exception closing naming search result {}", e.getMessage() );
}
}

@Override
public boolean isValid() {
return connectionFactory.isValid();
}
}
@@ -21,6 +21,8 @@

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 @@
implements LdapConnectionFactory
{

private final Logger log = LoggerFactory.getLogger(ConfigurableLdapConnectionFactory.class);

private String hostname;

private int port;
@@ -61,6 +65,8 @@

private LdapConnectionConfiguration ldapConnectionConfiguration;

private boolean valid = false;


@Inject
@Named(value = "userConfiguration#default")
@@ -90,10 +96,11 @@ public void initialize()
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 void setUserConf( UserConfiguration userConf )
{
this.userConf = userConf;
}

public boolean isValid() {
return valid;
}
}
@@ -51,4 +51,6 @@ LdapName getBaseDnLdapName()

void initialize();

public boolean isValid();

}

0 comments on commit 2aa6cdf

Please sign in to comment.