You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@archiva.apache.org by ma...@apache.org on 2016/10/16 15:48:42 UTC
[1/2] archiva-redback-core git commit: Fixing validation error in
unit tests
Repository: archiva-redback-core
Updated Branches:
refs/heads/master c9ca73b94 -> 78d822d14
Fixing validation error in unit tests
Project: http://git-wip-us.apache.org/repos/asf/archiva-redback-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/archiva-redback-core/commit/78d822d1
Tree: http://git-wip-us.apache.org/repos/asf/archiva-redback-core/tree/78d822d1
Diff: http://git-wip-us.apache.org/repos/asf/archiva-redback-core/diff/78d822d1
Branch: refs/heads/master
Commit: 78d822d145a6bfd6450e4f837a79e363c9d83bd0
Parents: 2aa6cdf
Author: Martin Stockhammer <ma...@apache.org>
Authored: Sun Oct 16 16:49:38 2016 +0200
Committer: Martin Stockhammer <ma...@apache.org>
Committed: Sun Oct 16 17:18:42 2016 +0200
----------------------------------------------------------------------
.../DefaultAuthenticationManager.java | 138 ++++++++-----------
.../users/UserManagerAuthenticator.java | 6 +
.../keystore/KeyStoreAuthenticator.java | 6 +
3 files changed, 72 insertions(+), 78 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/archiva-redback-core/blob/78d822d1/redback-authentication/redback-authentication-api/src/main/java/org/apache/archiva/redback/authentication/DefaultAuthenticationManager.java
----------------------------------------------------------------------
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 bda3276..1bc4770 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
@@ -41,7 +41,7 @@ import java.util.Map;
/**
* DefaultAuthenticationManager: the goal of the authentication manager is to act as a conduit for
* authentication requests into different authentication schemes
- *
+ * <p>
* For example, the default implementation can be configured with any number of authenticators and will
* sequentially try them for an authenticated result. This allows you to have the standard user/pass
* auth procedure followed by authentication based on a known key for 'remember me' type functionality.
@@ -50,10 +50,9 @@ import java.util.Map;
*/
@Service("authenticationManager")
public class DefaultAuthenticationManager
- implements AuthenticationManager
-{
+ implements AuthenticationManager {
- private Logger log = LoggerFactory.getLogger( getClass() );
+ private Logger log = LoggerFactory.getLogger(getClass());
private List<Authenticator> authenticators;
@@ -61,113 +60,96 @@ public class DefaultAuthenticationManager
private ApplicationContext applicationContext;
@Inject
- @Named( value = "userManager#default" )
+ @Named(value = "userManager#default")
private UserManager userManager;
- @SuppressWarnings( "unchecked" )
+ @SuppressWarnings("unchecked")
@PostConstruct
- public void initialize()
- {
+ public void initialize() {
this.authenticators =
- new ArrayList<Authenticator>( applicationContext.getBeansOfType( Authenticator.class ).values() );
+ new ArrayList<Authenticator>(applicationContext.getBeansOfType(Authenticator.class).values());
}
- public String getId()
- {
+ public String getId() {
return "Default Authentication Manager - " + this.getClass().getName() + " : managed authenticators - " +
- knownAuthenticators();
+ knownAuthenticators();
}
- public AuthenticationResult authenticate( AuthenticationDataSource source )
- throws AccountLockedException, AuthenticationException, MustChangePasswordException
- {
- if ( authenticators == null || authenticators.size() == 0 )
- {
- return ( new AuthenticationResult( false, null, new AuthenticationException(
- "no valid authenticators, can't authenticate" ) ) );
+ public AuthenticationResult authenticate(AuthenticationDataSource source)
+ throws AccountLockedException, AuthenticationException, MustChangePasswordException {
+ if (authenticators == null || authenticators.size() == 0) {
+ return (new AuthenticationResult(false, null, new AuthenticationException(
+ "no valid authenticators, can't authenticate")));
}
// put AuthenticationResult exceptions in a map
List<AuthenticationFailureCause> authnResultErrors = new ArrayList<AuthenticationFailureCause>();
- for ( Authenticator authenticator : authenticators )
- {
- if ( authenticator.isValid() && authenticator.supportsDataSource( source ) )
- {
- AuthenticationResult authResult = authenticator.authenticate( source );
- List<AuthenticationFailureCause> authenticationFailureCauses =
- authResult.getAuthenticationFailureCauses();
-
- if ( authResult.isAuthenticated() )
- {
- //olamy: as we can chain various user managers with Archiva
- // user manager authenticator can lock accounts in the following case :
- // 2 user managers: ldap and jdo.
- // ldap correctly find the user but cannot compare hashed password
- // jdo reject password so increase loginAttemptCount
- // now ldap bind authenticator work but loginAttemptCount has been increased.
- // so we restore here loginAttemptCount to 0 if in authenticationFailureCauses
-
- for ( AuthenticationFailureCause authenticationFailureCause : authenticationFailureCauses )
- {
- User user = authenticationFailureCause.getUser();
- if ( user != null )
- {
- if ( user.getCountFailedLoginAttempts() > 0 )
- {
- user.setCountFailedLoginAttempts( 0 );
- if ( !userManager.isReadOnly() )
- {
- try
- {
- userManager.updateUser( user );
- }
- catch ( UserManagerException e )
- {
- log.debug( e.getMessage(), e );
- log.warn( "skip error updating user: {}", e.getMessage() );
+ for (Authenticator authenticator : authenticators) {
+ if (authenticator.isValid()) {
+ if (authenticator.supportsDataSource(source)) {
+ AuthenticationResult authResult = authenticator.authenticate(source);
+ List<AuthenticationFailureCause> authenticationFailureCauses =
+ authResult.getAuthenticationFailureCauses();
+
+ if (authResult.isAuthenticated()) {
+ //olamy: as we can chain various user managers with Archiva
+ // user manager authenticator can lock accounts in the following case :
+ // 2 user managers: ldap and jdo.
+ // ldap correctly find the user but cannot compare hashed password
+ // jdo reject password so increase loginAttemptCount
+ // now ldap bind authenticator work but loginAttemptCount has been increased.
+ // so we restore here loginAttemptCount to 0 if in authenticationFailureCauses
+
+ for (AuthenticationFailureCause authenticationFailureCause : authenticationFailureCauses) {
+ User user = authenticationFailureCause.getUser();
+ if (user != null) {
+ if (user.getCountFailedLoginAttempts() > 0) {
+ user.setCountFailedLoginAttempts(0);
+ if (!userManager.isReadOnly()) {
+ try {
+ userManager.updateUser(user);
+ } catch (UserManagerException e) {
+ log.debug(e.getMessage(), e);
+ log.warn("skip error updating user: {}", e.getMessage());
+ }
}
}
}
}
+ return authResult;
}
- return authResult;
- }
- if ( authenticationFailureCauses != null )
- {
- authnResultErrors.addAll( authenticationFailureCauses );
- }
- else
- {
- if ( authResult.getException() != null )
- {
- authnResultErrors.add(
- new AuthenticationFailureCause( AuthenticationConstants.AUTHN_RUNTIME_EXCEPTION,
- authResult.getException().getMessage() ) );
+ if (authenticationFailureCauses != null) {
+ authnResultErrors.addAll(authenticationFailureCauses);
+ } else {
+ if (authResult.getException() != null) {
+ authnResultErrors.add(
+ new AuthenticationFailureCause(AuthenticationConstants.AUTHN_RUNTIME_EXCEPTION,
+ authResult.getException().getMessage()));
+ }
}
- }
+ }
+ } else {
+ log.warn("Invalid authenticator found: " + authenticator.getId());
}
}
- return ( new AuthenticationResult( false, null, new AuthenticationException(
- "authentication failed on authenticators: " + knownAuthenticators() ), authnResultErrors ) );
+ return (new AuthenticationResult(false, null, new AuthenticationException(
+ "authentication failed on authenticators: " + knownAuthenticators()), authnResultErrors));
}
- public List<Authenticator> getAuthenticators()
- {
+ public List<Authenticator> getAuthenticators() {
return authenticators;
}
- private String knownAuthenticators()
- {
+ private String knownAuthenticators() {
StringBuilder strbuf = new StringBuilder();
- for ( Authenticator authenticator : authenticators )
- {
- strbuf.append( '(' ).append( authenticator.getId() ).append( ") " );
+ for (Authenticator authenticator : authenticators) {
+ strbuf.append('(').append(authenticator.getId()).append(") ");
}
return strbuf.toString();
http://git-wip-us.apache.org/repos/asf/archiva-redback-core/blob/78d822d1/redback-authentication/redback-authentication-providers/redback-authentication-users/src/main/java/org/apache/archiva/redback/authentication/users/UserManagerAuthenticator.java
----------------------------------------------------------------------
diff --git a/redback-authentication/redback-authentication-providers/redback-authentication-users/src/main/java/org/apache/archiva/redback/authentication/users/UserManagerAuthenticator.java b/redback-authentication/redback-authentication-providers/redback-authentication-users/src/main/java/org/apache/archiva/redback/authentication/users/UserManagerAuthenticator.java
index 567b7b3..ed9e33a 100644
--- a/redback-authentication/redback-authentication-providers/redback-authentication-users/src/main/java/org/apache/archiva/redback/authentication/users/UserManagerAuthenticator.java
+++ b/redback-authentication/redback-authentication-providers/redback-authentication-users/src/main/java/org/apache/archiva/redback/authentication/users/UserManagerAuthenticator.java
@@ -40,6 +40,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
+import javax.annotation.PostConstruct;
import javax.inject.Inject;
import javax.inject.Named;
import java.util.ArrayList;
@@ -69,6 +70,11 @@ public class UserManagerAuthenticator
return "UserManagerAuthenticator";
}
+ @PostConstruct
+ private void init() {
+ super.valid = true;
+ }
+
/**
* @throws org.apache.archiva.redback.policy.AccountLockedException
http://git-wip-us.apache.org/repos/asf/archiva-redback-core/blob/78d822d1/redback-keys/redback-authentication-keys/src/main/java/org/apache/archiva/redback/authentication/keystore/KeyStoreAuthenticator.java
----------------------------------------------------------------------
diff --git a/redback-keys/redback-authentication-keys/src/main/java/org/apache/archiva/redback/authentication/keystore/KeyStoreAuthenticator.java b/redback-keys/redback-authentication-keys/src/main/java/org/apache/archiva/redback/authentication/keystore/KeyStoreAuthenticator.java
index 51a9d31..931c610 100644
--- a/redback-keys/redback-authentication-keys/src/main/java/org/apache/archiva/redback/authentication/keystore/KeyStoreAuthenticator.java
+++ b/redback-keys/redback-authentication-keys/src/main/java/org/apache/archiva/redback/authentication/keystore/KeyStoreAuthenticator.java
@@ -39,6 +39,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
+import javax.annotation.PostConstruct;
import javax.annotation.Resource;
/**
@@ -59,6 +60,11 @@ public class KeyStoreAuthenticator
@Resource(name = "userManager#default")
private UserManager userManager;
+ @PostConstruct
+ private void init() {
+ super.valid=true;
+ }
+
public String getId()
{
return getClass().getName();
[2/2] archiva-redback-core git commit: Adding flag for authenticator
to avoid autowiring exceptions
Posted by ma...@apache.org.
Adding flag for authenticator to avoid autowiring exceptions
Adds a isValid() method to the authenticator to avoid exceptions during
initialization.
Project: http://git-wip-us.apache.org/repos/asf/archiva-redback-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/archiva-redback-core/commit/2aa6cdf6
Tree: http://git-wip-us.apache.org/repos/asf/archiva-redback-core/tree/2aa6cdf6
Diff: http://git-wip-us.apache.org/repos/asf/archiva-redback-core/diff/2aa6cdf6
Branch: refs/heads/master
Commit: 2aa6cdf6c6c89684a04f2f357dabad65c2fb9627
Parents: c9ca73b
Author: Martin Stockhammer <ma...@apache.org>
Authored: Mon Oct 3 19:36:13 2016 +0200
Committer: Martin Stockhammer <ma...@apache.org>
Committed: Sun Oct 16 17:18:42 2016 +0200
----------------------------------------------------------------------
.../redback/authentication/AbstractAuthenticator.java | 8 +++++++-
.../archiva/redback/authentication/Authenticator.java | 2 ++
.../authentication/DefaultAuthenticationManager.java | 2 +-
.../authentication/ldap/LdapBindAuthenticator.java | 5 +++++
.../connection/ConfigurableLdapConnectionFactory.java | 13 ++++++++++++-
.../common/ldap/connection/LdapConnectionFactory.java | 2 ++
6 files changed, 29 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/archiva-redback-core/blob/2aa6cdf6/redback-authentication/redback-authentication-api/src/main/java/org/apache/archiva/redback/authentication/AbstractAuthenticator.java
----------------------------------------------------------------------
diff --git a/redback-authentication/redback-authentication-api/src/main/java/org/apache/archiva/redback/authentication/AbstractAuthenticator.java b/redback-authentication/redback-authentication-api/src/main/java/org/apache/archiva/redback/authentication/AbstractAuthenticator.java
index 1c80bc3..80d1918 100644
--- a/redback-authentication/redback-authentication-api/src/main/java/org/apache/archiva/redback/authentication/AbstractAuthenticator.java
+++ b/redback-authentication/redback-authentication-api/src/main/java/org/apache/archiva/redback/authentication/AbstractAuthenticator.java
@@ -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;
}
}
http://git-wip-us.apache.org/repos/asf/archiva-redback-core/blob/2aa6cdf6/redback-authentication/redback-authentication-api/src/main/java/org/apache/archiva/redback/authentication/Authenticator.java
----------------------------------------------------------------------
diff --git a/redback-authentication/redback-authentication-api/src/main/java/org/apache/archiva/redback/authentication/Authenticator.java b/redback-authentication/redback-authentication-api/src/main/java/org/apache/archiva/redback/authentication/Authenticator.java
index 6efe11c..ce99757 100644
--- a/redback-authentication/redback-authentication-api/src/main/java/org/apache/archiva/redback/authentication/Authenticator.java
+++ b/redback-authentication/redback-authentication-api/src/main/java/org/apache/archiva/redback/authentication/Authenticator.java
@@ -38,4 +38,6 @@ public interface Authenticator
throws AccountLockedException, AuthenticationException, MustChangePasswordException;
void initialize() throws AuthenticationException;
+
+ boolean isValid();
}
http://git-wip-us.apache.org/repos/asf/archiva-redback-core/blob/2aa6cdf6/redback-authentication/redback-authentication-api/src/main/java/org/apache/archiva/redback/authentication/DefaultAuthenticationManager.java
----------------------------------------------------------------------
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 d5342bf..bda3276 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
@@ -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 =
http://git-wip-us.apache.org/repos/asf/archiva-redback-core/blob/2aa6cdf6/redback-authentication/redback-authentication-providers/redback-authentication-ldap/src/main/java/org/apache/archiva/redback/authentication/ldap/LdapBindAuthenticator.java
----------------------------------------------------------------------
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 648b2f9..fedae34 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
@@ -208,4 +208,9 @@ public class LdapBindAuthenticator
log.warn( "skip exception closing naming search result {}", e.getMessage() );
}
}
+
+ @Override
+ public boolean isValid() {
+ return connectionFactory.isValid();
+ }
}
http://git-wip-us.apache.org/repos/asf/archiva-redback-core/blob/2aa6cdf6/redback-common/redback-common-ldap/src/main/java/org/apache/archiva/redback/common/ldap/connection/ConfigurableLdapConnectionFactory.java
----------------------------------------------------------------------
diff --git a/redback-common/redback-common-ldap/src/main/java/org/apache/archiva/redback/common/ldap/connection/ConfigurableLdapConnectionFactory.java b/redback-common/redback-common-ldap/src/main/java/org/apache/archiva/redback/common/ldap/connection/ConfigurableLdapConnectionFactory.java
index 4aab487..2340cc5 100644
--- a/redback-common/redback-common-ldap/src/main/java/org/apache/archiva/redback/common/ldap/connection/ConfigurableLdapConnectionFactory.java
+++ b/redback-common/redback-common-ldap/src/main/java/org/apache/archiva/redback/common/ldap/connection/ConfigurableLdapConnectionFactory.java
@@ -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;
+ }
}
http://git-wip-us.apache.org/repos/asf/archiva-redback-core/blob/2aa6cdf6/redback-common/redback-common-ldap/src/main/java/org/apache/archiva/redback/common/ldap/connection/LdapConnectionFactory.java
----------------------------------------------------------------------
diff --git a/redback-common/redback-common-ldap/src/main/java/org/apache/archiva/redback/common/ldap/connection/LdapConnectionFactory.java b/redback-common/redback-common-ldap/src/main/java/org/apache/archiva/redback/common/ldap/connection/LdapConnectionFactory.java
index d81b3e2..4d6ec03 100644
--- a/redback-common/redback-common-ldap/src/main/java/org/apache/archiva/redback/common/ldap/connection/LdapConnectionFactory.java
+++ b/redback-common/redback-common-ldap/src/main/java/org/apache/archiva/redback/common/ldap/connection/LdapConnectionFactory.java
@@ -51,4 +51,6 @@ public interface LdapConnectionFactory
void initialize();
+ public boolean isValid();
+
}