Author: olamy
Date: Sat Feb 23 18:36:40 2013
New Revision: 1449386
URL: http://svn.apache.org/r1449386
Log:
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
Modified:
archiva/redback/redback-core/trunk/redback-authentication/redback-authentication-api/pom.xml
archiva/redback/redback-core/trunk/redback-authentication/redback-authentication-api/src/main/java/org/apache/archiva/redback/authentication/AuthenticationFailureCause.java
archiva/redback/redback-core/trunk/redback-authentication/redback-authentication-api/src/main/java/org/apache/archiva/redback/authentication/AuthenticationResult.java
archiva/redback/redback-core/trunk/redback-authentication/redback-authentication-api/src/main/java/org/apache/archiva/redback/authentication/DefaultAuthenticationManager.java
archiva/redback/redback-core/trunk/redback-system/src/test/resources/spring-context.xml
Modified:
archiva/redback/redback-core/trunk/redback-authentication/redback-authentication-api/pom.xml
URL:
http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-authentication/redback-authentication-api/pom.xml?rev=1449386&r1=1449385&r2=1449386&view=diff
==============================================================================
---
archiva/redback/redback-core/trunk/redback-authentication/redback-authentication-api/pom.xml
(original)
+++
archiva/redback/redback-core/trunk/redback-authentication/redback-authentication-api/pom.xml
Sat Feb 23 18:36:40 2013
@@ -65,7 +65,8 @@
org.apache.archiva.redback.policy;version=${project.version},
org.apache.archiva.redback.users;version=${project.version},
org.apache.commons.lang;version="[2.6,3)",
- org.springframework*;version="[3,4)"
+ org.springframework*;version="[3,4)",
+ org.slf4j;resolution:=optional
</Import-Package>
</instructions>
</configuration>
Modified:
archiva/redback/redback-core/trunk/redback-authentication/redback-authentication-api/src/main/java/org/apache/archiva/redback/authentication/AuthenticationFailureCause.java
URL:
http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-authentication/redback-authentication-api/src/main/java/org/apache/archiva/redback/authentication/AuthenticationFailureCause.java?rev=1449386&r1=1449385&r2=1449386&view=diff
==============================================================================
---
archiva/redback/redback-core/trunk/redback-authentication/redback-authentication-api/src/main/java/org/apache/archiva/redback/authentication/AuthenticationFailureCause.java
(original)
+++
archiva/redback/redback-core/trunk/redback-authentication/redback-authentication-api/src/main/java/org/apache/archiva/redback/authentication/AuthenticationFailureCause.java
Sat Feb 23 18:36:40 2013
@@ -18,6 +18,8 @@ package org.apache.archiva.redback.authe
* under the License.
*/
+import org.apache.archiva.redback.users.User;
+
import java.io.Serializable;
/**
@@ -33,6 +35,8 @@ public class AuthenticationFailureCause
private String message;
+ private User user;
+
public AuthenticationFailureCause( int cause, String message )
{
this.cause = cause;
@@ -59,6 +63,22 @@ public class AuthenticationFailureCause
this.message = message;
}
+ public User getUser()
+ {
+ return user;
+ }
+
+ public AuthenticationFailureCause user ( User user)
+ {
+ this.user = user;
+ return this;
+ }
+
+ public void setUser( User user )
+ {
+ this.user = user;
+ }
+
@Override
public String toString()
{
Modified:
archiva/redback/redback-core/trunk/redback-authentication/redback-authentication-api/src/main/java/org/apache/archiva/redback/authentication/AuthenticationResult.java
URL:
http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-authentication/redback-authentication-api/src/main/java/org/apache/archiva/redback/authentication/AuthenticationResult.java?rev=1449386&r1=1449385&r2=1449386&view=diff
==============================================================================
---
archiva/redback/redback-core/trunk/redback-authentication/redback-authentication-api/src/main/java/org/apache/archiva/redback/authentication/AuthenticationResult.java
(original)
+++
archiva/redback/redback-core/trunk/redback-authentication/redback-authentication-api/src/main/java/org/apache/archiva/redback/authentication/AuthenticationResult.java
Sat Feb 23 18:36:40 2013
@@ -22,6 +22,7 @@ package org.apache.archiva.redback.authe
import org.apache.archiva.redback.users.User;
import java.io.Serializable;
+import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -93,6 +94,10 @@ public class AuthenticationResult
public List<AuthenticationFailureCause> getAuthenticationFailureCauses()
{
+ if ( authenticationFailureCauses == null )
+ {
+ this.authenticationFailureCauses = new
ArrayList<AuthenticationFailureCause>();
+ }
return authenticationFailureCauses;
}
Modified:
archiva/redback/redback-core/trunk/redback-authentication/redback-authentication-api/src/main/java/org/apache/archiva/redback/authentication/DefaultAuthenticationManager.java
URL:
http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-authentication/redback-authentication-api/src/main/java/org/apache/archiva/redback/authentication/DefaultAuthenticationManager.java?rev=1449386&r1=1449385&r2=1449386&view=diff
==============================================================================
---
archiva/redback/redback-core/trunk/redback-authentication/redback-authentication-api/src/main/java/org/apache/archiva/redback/authentication/DefaultAuthenticationManager.java
(original)
+++
archiva/redback/redback-core/trunk/redback-authentication/redback-authentication-api/src/main/java/org/apache/archiva/redback/authentication/DefaultAuthenticationManager.java
Sat Feb 23 18:36:40 2013
@@ -21,11 +21,17 @@ package org.apache.archiva.redback.authe
import org.apache.archiva.redback.policy.AccountLockedException;
import org.apache.archiva.redback.policy.MustChangePasswordException;
+import org.apache.archiva.redback.users.User;
+import org.apache.archiva.redback.users.UserManager;
+import org.apache.archiva.redback.users.UserManagerException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
+import javax.inject.Named;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -47,12 +53,18 @@ public class DefaultAuthenticationManage
implements AuthenticationManager
{
+ private Logger log = LoggerFactory.getLogger( getClass() );
+
private List<Authenticator> authenticators;
@Inject
private ApplicationContext applicationContext;
- @SuppressWarnings("unchecked")
+ @Inject
+ @Named( value = "userManager#configurable" )
+ private UserManager userManager;
+
+ @SuppressWarnings( "unchecked" )
@PostConstruct
public void initialize()
{
@@ -88,6 +100,37 @@ public class DefaultAuthenticationManage
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;
}
Modified:
archiva/redback/redback-core/trunk/redback-system/src/test/resources/spring-context.xml
URL:
http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-system/src/test/resources/spring-context.xml?rev=1449386&r1=1449385&r2=1449386&view=diff
==============================================================================
---
archiva/redback/redback-core/trunk/redback-system/src/test/resources/spring-context.xml
(original)
+++
archiva/redback/redback-core/trunk/redback-system/src/test/resources/spring-context.xml
Sat Feb 23 18:36:40 2013
@@ -45,4 +45,6 @@
<alias name="commons-configuration" alias="test-conf"/>
+ <bean name="userManager#configurable"
class="org.apache.archiva.redback.system.MockUserManager"/>
+
</beans>
\ No newline at end of file