maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From car...@apache.org
Subject svn commit: r442886 - in /maven/shared/trunk/maven-user/maven-user-acegi/src/main/java/org/apache/maven/user/acegi: AcegiUserManager.java event/authentication/UserEventPublisher.java
Date Wed, 13 Sep 2006 07:54:26 GMT
Author: carlos
Date: Wed Sep 13 00:54:25 2006
New Revision: 442886

URL: http://svn.apache.org/viewvc?view=rev&rev=442886
Log:
Add sucessful and failed login hooks between acegi and UserManager

Modified:
    maven/shared/trunk/maven-user/maven-user-acegi/src/main/java/org/apache/maven/user/acegi/AcegiUserManager.java
    maven/shared/trunk/maven-user/maven-user-acegi/src/main/java/org/apache/maven/user/acegi/event/authentication/UserEventPublisher.java

Modified: maven/shared/trunk/maven-user/maven-user-acegi/src/main/java/org/apache/maven/user/acegi/AcegiUserManager.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-user/maven-user-acegi/src/main/java/org/apache/maven/user/acegi/AcegiUserManager.java?view=diff&rev=442886&r1=442885&r2=442886
==============================================================================
--- maven/shared/trunk/maven-user/maven-user-acegi/src/main/java/org/apache/maven/user/acegi/AcegiUserManager.java
(original)
+++ maven/shared/trunk/maven-user/maven-user-acegi/src/main/java/org/apache/maven/user/acegi/AcegiUserManager.java
Wed Sep 13 00:54:25 2006
@@ -154,6 +154,16 @@
         return getUserManager().login( username, rawpassword );
     }
 
+    public void loginFailed( String username )
+    {
+        getUserManager().loginFailed( username );
+    }
+
+    public void loginSuccessful( String username )
+    {
+        getUserManager().loginSuccessful( username );
+    }
+
     public void removeUser( int accountId )
     {
         getUserManager().removeUser( accountId );

Modified: maven/shared/trunk/maven-user/maven-user-acegi/src/main/java/org/apache/maven/user/acegi/event/authentication/UserEventPublisher.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-user/maven-user-acegi/src/main/java/org/apache/maven/user/acegi/event/authentication/UserEventPublisher.java?view=diff&rev=442886&r1=442885&r2=442886
==============================================================================
--- maven/shared/trunk/maven-user/maven-user-acegi/src/main/java/org/apache/maven/user/acegi/event/authentication/UserEventPublisher.java
(original)
+++ maven/shared/trunk/maven-user/maven-user-acegi/src/main/java/org/apache/maven/user/acegi/event/authentication/UserEventPublisher.java
Wed Sep 13 00:54:25 2006
@@ -17,12 +17,16 @@
  */
 
 import org.acegisecurity.event.authentication.AuthenticationFailureBadCredentialsEvent;
-import org.acegisecurity.event.authentication.AuthenticationFailureCredentialsExpiredEvent;
+import org.acegisecurity.event.authentication.AuthenticationSuccessEvent;
+import org.acegisecurity.userdetails.User;
+import org.apache.maven.user.model.UserManager;
 import org.springframework.context.ApplicationEvent;
 import org.springframework.context.ApplicationEventPublisher;
 
 /**
- * Hook in Acegi event system to check for login failures and password expired.
+ * Hook in Acegi event system to delegate successful and failed login events to {@link UserManager}.
+ * 
+ * @plexus.component role="org.springframework.context.ApplicationEventPublisher"
  * 
  * @author <a href="mailto:carlos@apache.org">Carlos Sanchez</a>
  * @version $Id$
@@ -31,16 +35,42 @@
     implements ApplicationEventPublisher
 {
 
+    /**
+     * @plexus.requirement role-hint="acegi"
+     */
+    private UserManager userManager;
+
+    public void setUserManager( UserManager userManager )
+    {
+        this.userManager = userManager;
+    }
+
+    public UserManager getUserManager()
+    {
+        return userManager;
+    }
+
     public void publishEvent( ApplicationEvent event )
     {
-        if ( event instanceof AuthenticationFailureCredentialsExpiredEvent )
+        if ( event instanceof AuthenticationSuccessEvent )
         {
-            // TODO expired password, force to change it
+            success( (AuthenticationSuccessEvent) event );
         }
         if ( event instanceof AuthenticationFailureBadCredentialsEvent )
         {
-            // TODO bad password, increase count
+            badCredentials( (AuthenticationFailureBadCredentialsEvent) event );
         }
     }
 
+    private void success( AuthenticationSuccessEvent event )
+    {
+        User user = (User) event.getAuthentication().getPrincipal();
+        getUserManager().loginSuccessful( user.getUsername() );
+    }
+
+    private void badCredentials( AuthenticationFailureBadCredentialsEvent event )
+    {
+        User user = (User) event.getAuthentication().getPrincipal();
+        getUserManager().loginFailed( user.getUsername() );
+    }
 }



Mime
View raw message