You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@archiva.apache.org by ol...@apache.org on 2012/04/06 11:59:32 UTC

svn commit: r1310268 [20/42] - in /archiva/redback/redback-core/trunk: ./ redback-authentication/ redback-authentication/redback-authentication-api/ redback-authentication/redback-authentication-api/src/ redback-authentication/redback-authentication-ap...

Added: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/AccountAction.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/AccountAction.java?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/AccountAction.java (added)
+++ archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/AccountAction.java Fri Apr  6 09:58:14 2012
@@ -0,0 +1,255 @@
+package org.codehaus.plexus.redback.struts2.action;
+
+/*
+ * Copyright 2005-2006 The Codehaus.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.codehaus.plexus.redback.policy.PasswordEncoder;
+import org.codehaus.plexus.redback.policy.PasswordRuleViolationException;
+import org.codehaus.plexus.redback.system.DefaultSecuritySession;
+import org.codehaus.plexus.redback.system.SecuritySession;
+import org.codehaus.plexus.redback.system.SecuritySystemConstants;
+import org.codehaus.plexus.redback.users.User;
+import org.codehaus.plexus.redback.users.UserManager;
+import org.codehaus.plexus.redback.users.UserNotFoundException;
+import org.codehaus.plexus.util.StringUtils;
+import org.codehaus.redback.integration.interceptor.SecureActionBundle;
+import org.codehaus.redback.integration.interceptor.SecureActionException;
+import org.codehaus.redback.integration.model.EditUserCredentials;
+import org.springframework.context.annotation.Scope;
+import org.springframework.stereotype.Controller;
+
+import java.util.Arrays;
+
+/**
+ * AccountAction
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+@Controller( "redback-account" )
+@Scope( "prototype" )
+public class AccountAction
+    extends AbstractUserCredentialsAction
+    implements CancellableAction
+{
+    private static final String ACCOUNT_SUCCESS = "security-account-success";
+
+    // ------------------------------------------------------------------
+    // Action Parameters
+    // ------------------------------------------------------------------
+
+    private EditUserCredentials user;
+
+    private String oldPassword;
+
+    // ------------------------------------------------------------------
+    // Action Entry Points - (aka Names)
+    // ------------------------------------------------------------------
+
+    public String show()
+    {
+        SecuritySession session = getSecuritySession();
+
+        if ( !session.isAuthenticated() )
+        {
+            addActionError( getText( "cannot.show.account.login.required" ) );
+            return REQUIRES_AUTHENTICATION;
+        }
+
+        String username = session.getUser().getUsername();
+
+        if ( username == null )
+        {
+            addActionError( getText( "cannot.edit.user.null.username" ) );
+            return ERROR;
+        }
+
+        if ( StringUtils.isEmpty( username ) )
+        {
+            addActionError( getText( "cannot.edit.user.empty.username" ) );
+            return ERROR;
+        }
+
+        UserManager manager = super.securitySystem.getUserManager();
+
+        if ( !manager.userExists( username ) )
+        {
+            // Means that the role name doesn't exist.
+            // We need to fail fast and return to the previous page.
+            addActionError( getText( "user.does.not.exist", Arrays.asList( (Object) username ) ) );
+            return ERROR;
+        }
+
+        internalUser = user;
+
+        try
+        {
+            User u = manager.findUser( username );
+            if ( u == null )
+            {
+                addActionError( getText( "cannot.operate.on.null.user" ) );
+                return ERROR;
+            }
+
+            user = new EditUserCredentials( u );
+        }
+        catch ( UserNotFoundException e )
+        {
+            addActionError( getText( "cannot.get.user", Arrays.asList( (Object) username, e.getMessage() ) ) );
+            return ERROR;
+        }
+
+        return INPUT;
+    }
+
+    public String submit()
+    {
+        SecuritySession session = getSecuritySession();
+
+        if ( !session.isAuthenticated() )
+        {
+            addActionError( getText( "cannot.show.account.login.required" ) );
+            return REQUIRES_AUTHENTICATION;
+        }
+
+        String username = session.getUser().getUsername();
+
+        if ( username == null )
+        {
+            addActionError( getText( "cannot.edit.user.null.username" ) );
+            return ERROR;
+        }
+
+        if ( StringUtils.isEmpty( username ) )
+        {
+            addActionError( getText( "cannot.edit.user.empty.username" ) );
+            return ERROR;
+        }
+
+        if ( user == null )
+        {
+            addActionError( getText( "cannot.edit.user.null.credentials" ) );
+            return ERROR;
+        }
+
+        if ( !user.getPassword().equals( user.getConfirmPassword() ) )
+        {
+            addFieldError( "user.confirmPassword", getText( "password.confimation.failed" ) );
+            return ERROR;
+        }
+
+        UserManager manager = super.securitySystem.getUserManager();
+
+        if ( !manager.userExists( username ) )
+        {
+            // Means that the role name doesn't exist.
+            // We need to fail fast and return to the previous page.
+            addActionError( getText( "user.does.not.exist", Arrays.asList( (Object) username ) ) );
+            return ERROR;
+        }
+
+        internalUser = user;
+
+        try
+        {
+            User u = manager.findUser( username );
+            if ( u == null )
+            {
+                addActionError( getText( "cannot.operate.on.null.user" ) );
+                return ERROR;
+            }
+
+            if ( StringUtils.isNotEmpty( user.getPassword() ) )
+            {
+                PasswordEncoder encoder = securitySystem.getPolicy().getPasswordEncoder();
+
+                if ( !encoder.isPasswordValid( u.getEncodedPassword(), oldPassword ) )
+                {
+                    addFieldError( "oldPassword", getText( "password.provided.does.not.match.existing" ) );
+                    return ERROR;
+                }
+
+                u.setPassword( user.getPassword() );
+            }
+
+            u.setFullName( user.getFullName() );
+            u.setEmail( user.getEmail() );
+            u.setPassword( user.getPassword() );
+
+            manager.updateUser( u );
+
+            //check if current user then update the session
+            if ( getSecuritySession().getUser().getUsername().equals( u.getUsername() ) )
+            {
+                SecuritySession securitySession =
+                    new DefaultSecuritySession( getSecuritySession().getAuthenticationResult(), u );
+
+                this.session.put( SecuritySystemConstants.SECURITY_SESSION_KEY, securitySession );
+
+                setSession( this.session );
+            }
+        }
+        catch ( UserNotFoundException e )
+        {
+            addActionError( getText( "cannot.get.user", Arrays.asList( (Object) username, e.getMessage() ) ) );
+            return ERROR;
+        }
+        catch ( PasswordRuleViolationException e )
+        {
+            processPasswordRuleViolations( e );
+            return ERROR;
+        }
+
+        return ACCOUNT_SUCCESS;
+    }
+
+    public String cancel()
+    {
+        return CANCEL;
+    }
+
+    // ------------------------------------------------------------------
+    // Parameter Accessor Methods
+    // ------------------------------------------------------------------
+
+    public EditUserCredentials getUser()
+    {
+        return user;
+    }
+
+    public void setUser( EditUserCredentials user )
+    {
+        this.user = user;
+    }
+
+    public SecureActionBundle initSecureActionBundle()
+        throws SecureActionException
+    {
+        SecureActionBundle bundle = new SecureActionBundle();
+        bundle.setRequiresAuthentication( true );
+        return bundle;
+    }
+
+    public void setOldPassword( String oldPassword )
+    {
+        this.oldPassword = oldPassword;
+    }
+
+    public boolean isSelf()
+    {
+        return true;
+    }
+}

Propchange: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/AccountAction.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/AccountAction.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/AuditEvent.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/AuditEvent.java?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/AuditEvent.java (added)
+++ archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/AuditEvent.java Fri Apr  6 09:58:14 2012
@@ -0,0 +1,92 @@
+package org.codehaus.plexus.redback.struts2.action;
+
+/*
+ * Copyright 2009 The Codehaus.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.slf4j.MDC;
+
+public class AuditEvent
+{
+    private Logger logger = LoggerFactory.getLogger( AuditEvent.class.getName() );
+
+    private final String action;
+
+    private String affectedUser;
+
+    private String role;
+
+    private String currentUser;
+
+    public AuditEvent( String action )
+    {
+        this.action = action;
+    }
+
+    public void setRole( String role )
+    {
+        this.role = role;
+    }
+
+    public String getRole()
+    {
+        return role;
+    }
+
+    public void setAffectedUser( String affectedUser )
+    {
+        this.affectedUser = affectedUser;
+    }
+
+    public String getAffectedUser()
+    {
+        return affectedUser;
+    }
+
+    public void setCurrentUser( String currentUser )
+    {
+        this.currentUser = currentUser;
+    }
+
+    public String getCurrentUser()
+    {
+        return currentUser;
+    }
+
+    public void log()
+    {
+        // TODO: it would be better to push this into the login interceptor so it is always set consistently 
+        //   (same for IP address)
+        if ( currentUser != null )
+        {
+            MDC.put( "redback.currentUser", currentUser );
+        }
+
+        if ( affectedUser != null )
+        {
+            if ( role != null )
+            {
+                logger.info( action, affectedUser, role );
+            }
+            else
+            {
+                logger.info( action, affectedUser );
+
+            }
+        }
+    }
+}

Propchange: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/AuditEvent.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/AuditEvent.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/CancellableAction.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/CancellableAction.java?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/CancellableAction.java (added)
+++ archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/CancellableAction.java Fri Apr  6 09:58:14 2012
@@ -0,0 +1,30 @@
+package org.codehaus.plexus.redback.struts2.action;
+
+/*
+ * Copyright 2005-2006 The Codehaus.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+public interface CancellableAction 
+{
+	public static final String CANCEL = "cancel";
+	
+	/**
+	 * Returns the cancel result.
+	 * 
+	 * A basic implementation would simply be to return CANCEL.
+	 * @return
+	 */
+	String cancel();
+}

Propchange: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/CancellableAction.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/CancellableAction.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/LoginAction.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/LoginAction.java?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/LoginAction.java (added)
+++ archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/LoginAction.java Fri Apr  6 09:58:14 2012
@@ -0,0 +1,461 @@
+package org.codehaus.plexus.redback.struts2.action;
+
+/*
+ * Copyright 2005-2006 The Codehaus.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.struts2.ServletActionContext;
+import org.codehaus.plexus.redback.authentication.AuthenticationConstants;
+import org.codehaus.plexus.redback.authentication.AuthenticationDataSource;
+import org.codehaus.plexus.redback.authentication.AuthenticationException;
+import org.codehaus.plexus.redback.authentication.AuthenticationResult;
+import org.codehaus.plexus.redback.authentication.PasswordBasedAuthenticationDataSource;
+import org.codehaus.plexus.redback.authentication.TokenBasedAuthenticationDataSource;
+import org.codehaus.plexus.redback.configuration.UserConfiguration;
+import org.codehaus.plexus.redback.keys.AuthenticationKey;
+import org.codehaus.plexus.redback.keys.KeyManagerException;
+import org.codehaus.plexus.redback.keys.KeyNotFoundException;
+import org.codehaus.plexus.redback.policy.AccountLockedException;
+import org.codehaus.plexus.redback.policy.MustChangePasswordException;
+import org.codehaus.plexus.redback.system.SecuritySession;
+import org.codehaus.plexus.redback.system.SecuritySystem;
+import org.codehaus.plexus.redback.users.User;
+import org.codehaus.plexus.redback.users.UserNotFoundException;
+import org.codehaus.plexus.util.StringUtils;
+import org.codehaus.redback.integration.interceptor.SecureActionBundle;
+import org.codehaus.redback.integration.interceptor.SecureActionException;
+import org.codehaus.redback.integration.util.AutoLoginCookies;
+import org.springframework.context.annotation.Scope;
+import org.springframework.stereotype.Controller;
+
+import javax.inject.Inject;
+import java.util.Arrays;
+import java.util.Date;
+
+/**
+ * LoginAction
+ *
+ * @author Jesse McConnell <jm...@apache.org>
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+@Controller( "redback-login" )
+@Scope( "prototype" )
+public class LoginAction
+    extends AbstractSecurityAction
+    implements CancellableAction
+{
+    private static final String LOGIN_SUCCESS = "security-login-success";
+
+    private static final String PASSWORD_CHANGE = "security-must-change-password";
+
+    private static final String ACCOUNT_LOCKED = "security-login-locked";
+
+    // ------------------------------------------------------------------
+    //  Component Requirements
+    // ------------------------------------------------------------------
+
+    /**
+     *
+     */
+    @Inject
+    protected SecuritySystem securitySystem;
+
+    private String username;
+
+    private String password;
+
+    private String validateMe;
+
+    private String resetPassword;
+
+    private boolean rememberMe;
+
+    /**
+     *
+     */
+    @Inject
+    private AutoLoginCookies autologinCookies;
+
+    /**
+     *
+     */
+    @Inject
+    private UserConfiguration config;
+
+    // ------------------------------------------------------------------
+    // Action Entry Points - (aka Names)
+    // ------------------------------------------------------------------
+
+    public String show()
+    {
+        return INPUT;
+    }
+
+    /**
+     * 1) check if this is a validation authentication action
+     * 2) check if this is a reset password authentication action
+     * 3) sets up a password based authentication and passes on to webLogin()
+     *
+     * @return
+     */
+    public String login()
+    {
+        if ( StringUtils.isNotEmpty( validateMe ) )
+        {
+            // Process a login / validate request.
+            return validated();
+        }
+
+        if ( StringUtils.isNotEmpty( resetPassword ) )
+        {
+            // Process a login / reset password request.
+            return resetPassword();
+        }
+
+        if ( StringUtils.isEmpty( username ) )
+        {
+            addFieldError( "username", getText( "username.required" ) );
+            return ERROR;
+        }
+
+        PasswordBasedAuthenticationDataSource authdatasource = new PasswordBasedAuthenticationDataSource();
+        authdatasource.setPrincipal( username );
+        authdatasource.setPassword( password );
+
+        return webLogin( authdatasource, rememberMe );
+    }
+
+    /**
+     * 1) sets up a token based authentication
+     * 2) forces a password change requirement to the user
+     * 3) passes on to webLogin()
+     *
+     * @return
+     */
+    public String resetPassword()
+    {
+        if ( StringUtils.isEmpty( resetPassword ) )
+        {
+            addActionError( getText( "reset.password.missing" ) );
+            return ERROR;
+        }
+
+        try
+        {
+            AuthenticationKey authkey = securitySystem.getKeyManager().findKey( resetPassword );
+
+            User user = securitySystem.getUserManager().findUser( authkey.getForPrincipal() );
+
+            user.setPasswordChangeRequired( true );
+            user.setEncodedPassword( "" );
+
+            TokenBasedAuthenticationDataSource authsource = new TokenBasedAuthenticationDataSource();
+            authsource.setPrincipal( user.getPrincipal().toString() );
+            authsource.setToken( authkey.getKey() );
+            authsource.setEnforcePasswordChange( false );
+
+            securitySystem.getUserManager().updateUser( user );
+
+            AuditEvent event = new AuditEvent( getText( "log.password.change" ) );
+            event.setAffectedUser( username );
+            event.log();
+
+            return webLogin( authsource, false );
+        }
+        catch ( KeyNotFoundException e )
+        {
+            log.info( "Invalid key requested: {}", resetPassword );
+            addActionError( getText( "cannot.find.key" ) );
+            return ERROR;
+        }
+        catch ( KeyManagerException e )
+        {
+            addActionError( getText( "cannot.find.key.at.the.moment" ) );
+            log.warn( "Key Manager error: ", e );
+            return ERROR;
+        }
+        catch ( UserNotFoundException e )
+        {
+            addActionError( getText( "cannot.find.user" ) );
+            return ERROR;
+        }
+    }
+
+    /**
+     * 1) sets up a token based authentication
+     * 2) forces a password change requirement to the user
+     * 3) passes on to webLogin()
+     *
+     * @return
+     */
+    public String validated()
+    {
+        if ( StringUtils.isEmpty( validateMe ) )
+        {
+            addActionError( getText( "validation.failure.key.missing" ) );
+            return ERROR;
+        }
+
+        try
+        {
+            AuthenticationKey authkey = securitySystem.getKeyManager().findKey( validateMe );
+
+            User user = securitySystem.getUserManager().findUser( authkey.getForPrincipal() );
+
+            user.setValidated( true );
+            user.setLocked( false );
+            user.setPasswordChangeRequired( true );
+            user.setEncodedPassword( "" );
+
+            TokenBasedAuthenticationDataSource authsource = new TokenBasedAuthenticationDataSource();
+            authsource.setPrincipal( user.getPrincipal().toString() );
+            authsource.setToken( authkey.getKey() );
+            authsource.setEnforcePasswordChange( false );
+
+            securitySystem.getUserManager().updateUser( user );
+            String currentUser = getCurrentUser();
+
+            AuditEvent event = new AuditEvent( getText( "log.account.validation" ) );
+            event.setAffectedUser( username );
+            event.setCurrentUser( currentUser );
+            event.log();
+
+            return webLogin( authsource, false );
+        }
+        catch ( KeyNotFoundException e )
+        {
+            log.info( "Invalid key requested: {}", validateMe );
+            addActionError( getText( "cannot.find.key" ) );
+            return ERROR;
+        }
+        catch ( KeyManagerException e )
+        {
+            addActionError( getText( "cannot.find.key.at.the.momment" ) );
+            return ERROR;
+        }
+        catch ( UserNotFoundException e )
+        {
+            addActionError( getText( "cannot.find.user" ) );
+            return ERROR;
+        }
+    }
+
+    public String cancel()
+    {
+        return CANCEL;
+    }
+
+    public String getUsername()
+    {
+        return username;
+    }
+
+    public void setUsername( String username )
+    {
+        this.username = username;
+    }
+
+    public String getPassword()
+    {
+        return password;
+    }
+
+    public void setPassword( String password )
+    {
+        this.password = password;
+    }
+
+    public String getValidateMe()
+    {
+        return validateMe;
+    }
+
+    public void setValidateMe( String validateMe )
+    {
+        this.validateMe = validateMe;
+    }
+
+    public SecureActionBundle initSecureActionBundle()
+        throws SecureActionException
+    {
+        return SecureActionBundle.OPEN;
+    }
+
+    public String getResetPassword()
+    {
+        return resetPassword;
+    }
+
+    public void setResetPassword( String resetPassword )
+    {
+        this.resetPassword = resetPassword;
+    }
+
+    public boolean isRememberMe()
+    {
+        return rememberMe;
+    }
+
+    public void setRememberMe( boolean rememberMe )
+    {
+        this.rememberMe = rememberMe;
+    }
+
+
+    /**
+     * 1) attempts to authentication based on the passed in data source
+     * 2) if successful sets cookies and returns LOGIN_SUCCESS
+     * 3) if failure then check what kinda failure and return error
+     *
+     * @param authdatasource
+     * @param rememberMe
+     * @return
+     */
+    private String webLogin( AuthenticationDataSource authdatasource, boolean rememberMe )
+    {
+        // An attempt should log out your authentication tokens first!
+        setAuthTokens( null );
+
+        clearErrorsAndMessages();
+
+        // TODO: share this section with AutoLoginInterceptor
+        try
+        {
+            SecuritySession securitySession = securitySystem.authenticate( authdatasource );
+
+            if ( securitySession.isAuthenticated() )
+            {
+                // Success!  Create tokens.
+                setAuthTokens( securitySession );
+
+                if ( securitySystem.getPolicy().getUserValidationSettings().isEmailValidationRequired() )
+                {
+                    if ( !securitySession.getUser().getUsername().equals(
+                        config.getString( "redback.default.admin" ) ) )
+                    {
+                        if ( !securitySession.getUser().isValidated() )
+                        {
+                            setAuthTokens( null );
+                            // NOTE: this text is the same as incorrect.username.password to avoid exposing actual account existence
+                            addActionError( getText( "account.validation.required" ) );
+                            return ERROR;
+                        }
+                    }
+                }
+
+                setCookies( authdatasource, rememberMe );
+
+                AuditEvent event = new AuditEvent( getText( "log.login.success" ) );
+                event.setAffectedUser( username );
+                event.log();
+
+                User user = securitySession.getUser();
+                user.setLastLoginDate( new Date() );
+                securitySystem.getUserManager().updateUser( user );
+
+                if ( StringUtils.isNotEmpty( validateMe ) )
+                {
+                    try
+                    {
+                        //REDBACK-146: delete key after validating so user won't be able to use it the second time around
+                        securitySystem.getKeyManager().deleteKey( validateMe );
+                    }
+                    catch ( KeyManagerException e )
+                    {
+                        addActionError( getText( "cannot.find.key.at.the.momment" ) );
+                        return ERROR;
+                    }
+                }
+
+                return LOGIN_SUCCESS;
+            }
+            else
+            {
+                log.debug( "Login Action failed against principal : {}",
+                           securitySession.getAuthenticationResult().getPrincipal(),
+                           securitySession.getAuthenticationResult().getException() );
+
+                AuthenticationResult result = securitySession.getAuthenticationResult();
+                if ( result.getExceptionsMap() != null && !result.getExceptionsMap().isEmpty() )
+                {
+                    if ( result.getExceptionsMap().get( AuthenticationConstants.AUTHN_NO_SUCH_USER ) != null )
+                    {
+                        addActionError( getText( "incorrect.username.password" ) );
+                    }
+                    else
+                    {
+                        addActionError( getText( "authentication.failed" ) );
+                    }
+                }
+                else
+                {
+                    addActionError( getText( "authentication.failed" ) );
+                }
+
+                AuditEvent event = new AuditEvent( getText( "log.login.fail" ) );
+                event.setAffectedUser( username );
+                event.log();
+
+                return ERROR;
+            }
+        }
+        catch ( AuthenticationException ae )
+        {
+            addActionError( getText( "authentication.exception", Arrays.asList( (Object) ae.getMessage() ) ) );
+            return ERROR;
+        }
+        catch ( UserNotFoundException ue )
+        {
+            addActionError(
+                getText( "user.not.found.exception", Arrays.asList( (Object) username, ue.getMessage() ) ) );
+
+            AuditEvent event = new AuditEvent( getText( "log.login.fail" ) );
+            event.setAffectedUser( username );
+            event.log();
+            return ERROR;
+        }
+        catch ( AccountLockedException e )
+        {
+            addActionError( getText( "account.locked" ) );
+
+            AuditEvent event = new AuditEvent( getText( "log.login.fail.locked" ) );
+            event.setAffectedUser( username );
+            event.log();
+            return ACCOUNT_LOCKED;
+        }
+        catch ( MustChangePasswordException e )
+        {
+            // TODO: preferably we would not set the cookies for this "partial" login state
+            setCookies( authdatasource, rememberMe );
+
+            AuditEvent event = new AuditEvent( getText( "log.login.fail.locked" ) );
+            event.setAffectedUser( username );
+            event.log();
+            return PASSWORD_CHANGE;
+        }
+    }
+
+    private void setCookies( AuthenticationDataSource authdatasource, boolean rememberMe )
+    {
+        if ( rememberMe )
+        {
+            autologinCookies.setRememberMeCookie( authdatasource.getPrincipal(), ServletActionContext.getResponse(),
+                                                  ServletActionContext.getRequest() );
+        }
+        autologinCookies.setSignonCookie( authdatasource.getPrincipal(), ServletActionContext.getResponse(),
+                                          ServletActionContext.getRequest() );
+    }
+}

Propchange: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/LoginAction.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/LoginAction.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/LogoutAction.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/LogoutAction.java?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/LogoutAction.java (added)
+++ archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/LogoutAction.java Fri Apr  6 09:58:14 2012
@@ -0,0 +1,131 @@
+package org.codehaus.plexus.redback.struts2.action;
+
+/*
+ * Copyright 2005-2006 The Codehaus.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.struts2.ServletActionContext;
+import org.apache.struts2.dispatcher.SessionMap;
+import org.codehaus.plexus.cache.Cache;
+import org.codehaus.redback.integration.interceptor.SecureActionBundle;
+import org.codehaus.redback.integration.interceptor.SecureActionException;
+import org.codehaus.redback.integration.util.AutoLoginCookies;
+import org.springframework.context.annotation.Scope;
+import org.springframework.stereotype.Controller;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+
+/**
+ * LogoutAction
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+@Controller( "redback-logout" )
+@Scope( "prototype" )
+public class LogoutAction
+    extends AbstractSecurityAction
+{
+    // Result Names.
+    private static final String LOGOUT = "security-logout";
+
+    /**
+     * cache used for user assignments
+     *
+     *  role-hint="userAssignments"
+     */
+    @Inject
+    @Named( value = "cache#userAssignments" )
+    private Cache userAssignmentsCache;
+
+    /**
+     * cache used for user permissions
+     *
+     *  role-hint="userPermissions"
+     */
+    @Inject
+    @Named( value = "cache#userPermissions" )
+    private Cache userPermissionsCache;
+
+    /**
+     * Cache used for users
+     *
+     *  role-hint="users"
+     */
+    @Inject
+    @Named( value = "cache#users" )
+    private Cache usersCache;
+
+    /**
+     *
+     */
+    @Inject
+    private AutoLoginCookies autologinCookies;
+
+    public String logout()
+    {
+        if ( getSecuritySession().getUser() == null )
+        {
+            return LOGOUT;
+        }
+
+        String currentUser = (String) getSecuritySession().getUser().getPrincipal();
+
+        if ( getSecuritySession() != null )
+        {
+            // [PLXREDBACK-65] this is a bit of a hack around the cached managers since they don't have the ability to 
+            // purge their caches through the API.  Instead try and bring them in here and invalidate 
+            // the keys directly.  This will not be required once we move to a different model for pre-calculated
+            // permission sets since that will not have the overhead that required these caches in the first place.
+            Object principal = (String) getSecuritySession().getUser().getPrincipal();
+            if ( userAssignmentsCache != null )
+            {
+                userAssignmentsCache.remove( principal );
+            }
+            if ( userPermissionsCache != null )
+            {
+                userPermissionsCache.remove( principal );
+            }
+            if ( usersCache != null )
+            {
+                usersCache.remove( principal );
+            }
+        }
+
+        autologinCookies.removeRememberMeCookie( ServletActionContext.getResponse(),
+                                                 ServletActionContext.getRequest() );
+        autologinCookies.removeSignonCookie( ServletActionContext.getResponse(), ServletActionContext.getRequest() );
+
+        setAuthTokens( null );
+
+        if ( session != null )
+        {
+            ( (SessionMap) session ).invalidate();
+        }
+
+        AuditEvent event = new AuditEvent( getText( "log.logout.success" ) );
+        event.setAffectedUser( currentUser );
+        event.log();
+
+        return LOGOUT;
+    }
+
+    public SecureActionBundle initSecureActionBundle()
+        throws SecureActionException
+    {
+        return SecureActionBundle.OPEN;
+    }
+}

Propchange: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/LogoutAction.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/LogoutAction.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/PasswordAction.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/PasswordAction.java?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/PasswordAction.java (added)
+++ archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/PasswordAction.java Fri Apr  6 09:58:14 2012
@@ -0,0 +1,291 @@
+package org.codehaus.plexus.redback.struts2.action;
+
+/*
+ * Copyright 2005-2006 The Codehaus.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.codehaus.plexus.redback.policy.PasswordEncoder;
+import org.codehaus.plexus.redback.policy.PasswordRuleViolationException;
+import org.codehaus.plexus.redback.policy.PasswordRuleViolations;
+import org.codehaus.plexus.redback.system.SecuritySession;
+import org.codehaus.plexus.redback.system.SecuritySystem;
+import org.codehaus.plexus.redback.users.User;
+import org.codehaus.plexus.redback.users.UserNotFoundException;
+import org.codehaus.plexus.util.StringUtils;
+import org.codehaus.redback.integration.interceptor.SecureActionBundle;
+import org.codehaus.redback.integration.interceptor.SecureActionException;
+import org.springframework.context.annotation.Scope;
+import org.springframework.stereotype.Controller;
+
+import javax.inject.Inject;
+import java.util.Arrays;
+import java.util.Map;
+
+/**
+ * PasswordAction
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+@Controller( "redback-password" )
+@Scope( "prototype" )
+public class PasswordAction
+    extends AbstractSecurityAction
+    implements CancellableAction
+{
+    // ------------------------------------------------------------------
+    // Plexus Component Requirements
+    // ------------------------------------------------------------------
+
+    protected static final String CHANGE_PASSWORD_SUCCESS = "security-change-password-success";
+
+    /**
+     *
+     */
+    @Inject
+    protected SecuritySystem securitySystem;
+
+    // ------------------------------------------------------------------
+    // Action Parameters
+    // ------------------------------------------------------------------
+
+    private String existingPassword;
+
+    private String newPassword;
+
+    private String newPasswordConfirm;
+
+    private String targetUrl;
+
+    private boolean provideExisting;
+
+    public String show()
+    {
+        provideExisting = StringUtils.isNotEmpty( getSecuritySession().getUser().getEncodedPassword() );
+        return INPUT;
+    }
+
+    public String submit()
+    {
+        final SecuritySession securitySession = getSecuritySession();
+
+        provideExisting = StringUtils.isNotEmpty( securitySession.getUser().getEncodedPassword() );
+
+        if ( StringUtils.isEmpty( newPassword ) )
+        {
+            addFieldError( "newPassword", getText( "newPassword.cannot.be.empty" ) );
+        }
+
+        if ( !StringUtils.equals( newPassword, newPasswordConfirm ) )
+        {
+            addFieldError( "newPassword", getText( "password.confimation.failed" ) );
+        }
+
+        User user = securitySession.getUser();
+
+        // Test existing Password.
+        PasswordEncoder encoder = securitySystem.getPolicy().getPasswordEncoder();
+
+        if ( provideExisting )
+        {
+            if ( !encoder.isPasswordValid( user.getEncodedPassword(), existingPassword ) )
+            {
+                addFieldError( "existingPassword", getText( "password.provided.does.not.match.existing" ) );
+            }
+        }
+
+        // Validate the Password.
+        try
+        {
+            User tempUser = securitySystem.getUserManager().createUser( "temp", "temp", "temp" );
+            tempUser.setPassword( newPassword );
+            securitySystem.getPolicy().validatePassword( tempUser );
+        }
+        catch ( PasswordRuleViolationException e )
+        {
+            PasswordRuleViolations violations = e.getViolations();
+
+            if ( violations != null )
+            {
+                for ( String violation : violations.getLocalizedViolations() )
+                {
+                    addFieldError( "newPassword", violation );
+                }
+            }
+        }
+
+        // Toss error (if any exists)
+        if ( hasActionErrors() || hasFieldErrors() || hasActionMessages() )
+        {
+            newPassword = "";
+            newPasswordConfirm = "";
+            existingPassword = "";
+            return ERROR;
+        }
+
+        // We can save the new password.
+        try
+        {
+            String encodedPassword = encoder.encodePassword( newPassword );
+            user.setEncodedPassword( encodedPassword );
+            user.setPassword( newPassword );
+            // TODO: (address this) check once more for password policy, some policies may require additional information
+            // only available in the actual user object, perhaps the thing to do is add a deep cloning mechanism
+            // to user so we can validate this with a test user.  Its ok to just set and test it here before 
+            // setting the updateUser, but logically its better to maintain a clear separation here
+            securitySystem.getPolicy().validatePassword( user );
+            securitySystem.getUserManager().updateUser( user );
+        }
+        catch ( UserNotFoundException e )
+        {
+            addActionError( getText( "cannot.update.user.not.found", Arrays.asList( (Object) user.getUsername() ) ) );
+            addActionError( getText( "admin.deleted.account" ) );
+
+            return ERROR;
+        }
+        catch ( PasswordRuleViolationException e )
+        {
+            PasswordRuleViolations violations = e.getViolations();
+
+            if ( violations != null )
+            {
+                for ( String violation : violations.getLocalizedViolations() )
+                {
+                    addFieldError( "newPassword", violation );
+                }
+            }
+            // [REDBACK-30] when the password is one of the previous 6, it throws exception here, but since the user
+            // object is in the session we need to clear out the encodedPassword otherwise the flow will change and think
+            // it needs to have existingPassword which isn't set on some reset password checks
+            if ( !provideExisting )
+            {
+                user.setEncodedPassword( "" );
+                user.setPassword( "" );
+            }
+
+            return ERROR;
+        }
+
+        log.info( "Password Change Request Success." );
+        String currentUser = getCurrentUser();
+        AuditEvent event = new AuditEvent( getText( "log.password.change" ) );
+        event.setAffectedUser( user.getUsername() );
+        event.setCurrentUser( currentUser );
+        event.log();
+
+        if ( !securitySession.isAuthenticated() )
+        {
+            log.debug( "User is not authenticated." );
+            return REQUIRES_AUTHENTICATION;
+        }
+
+        /*
+        *  If provide existing is true, then this was a normal password change flow, if it is
+        * false then it is changing the password from the registration flow in which case direct to
+         * external link
+         */
+        if ( !provideExisting )
+        {
+            return CHANGE_PASSWORD_SUCCESS;
+        }
+        else
+        {
+
+            if ( super.session != null )
+            {
+
+                Map<String, Object> map = (Map<String, Object>) super.session;
+                String url = "";
+                if ( map.containsKey( "targetUrl" ) )
+                {
+                    url = map.remove( "targetUrl" ).toString();
+                    log.info( "targetUrl is retrieved and removed from the session: {}", url );
+                }
+                else
+                {
+                    log.info( "targetUrl is empty, redirect to change password success page" );
+                    return CHANGE_PASSWORD_SUCCESS;
+                }
+                setTargetUrl( url );
+            }
+            return SUCCESS;
+        }
+    }
+
+    public String cancel()
+    {
+        return CANCEL;
+    }
+
+    // ------------------------------------------------------------------
+    // Parameter Accessor Methods
+    // ------------------------------------------------------------------
+
+    public String getExistingPassword()
+    {
+        return existingPassword;
+    }
+
+    public void setExistingPassword( String existingPassword )
+    {
+        this.existingPassword = existingPassword;
+    }
+
+    public String getNewPassword()
+    {
+        return newPassword;
+    }
+
+    public void setNewPassword( String newPassword )
+    {
+        this.newPassword = newPassword;
+    }
+
+    public String getNewPasswordConfirm()
+    {
+        return newPasswordConfirm;
+    }
+
+    public void setNewPasswordConfirm( String newPasswordConfirm )
+    {
+        this.newPasswordConfirm = newPasswordConfirm;
+    }
+
+    public boolean isProvideExisting()
+    {
+        return provideExisting;
+    }
+
+    public void setProvideExisting( boolean provideExisting )
+    {
+        // Do nothing.
+    }
+
+    public SecureActionBundle initSecureActionBundle()
+        throws SecureActionException
+    {
+        return SecureActionBundle.AUTHONLY;
+    }
+
+    public String getTargetUrl()
+    {
+        return targetUrl;
+    }
+
+    public void setTargetUrl( String targetUrl )
+    {
+        this.targetUrl = targetUrl;
+    }
+}

Propchange: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/PasswordAction.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/PasswordAction.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/PasswordResetAction.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/PasswordResetAction.java?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/PasswordResetAction.java (added)
+++ archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/PasswordResetAction.java Fri Apr  6 09:58:14 2012
@@ -0,0 +1,150 @@
+package org.codehaus.plexus.redback.struts2.action;
+
+/*
+ * Copyright 2005-2006 The Codehaus.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.codehaus.plexus.redback.keys.AuthenticationKey;
+import org.codehaus.plexus.redback.keys.KeyManager;
+import org.codehaus.plexus.redback.keys.KeyManagerException;
+import org.codehaus.plexus.redback.policy.UserSecurityPolicy;
+import org.codehaus.plexus.redback.system.SecuritySystem;
+import org.codehaus.plexus.redback.users.User;
+import org.codehaus.plexus.redback.users.UserManager;
+import org.codehaus.plexus.redback.users.UserNotFoundException;
+import org.codehaus.plexus.util.StringUtils;
+import org.codehaus.redback.integration.interceptor.SecureActionBundle;
+import org.codehaus.redback.integration.interceptor.SecureActionException;
+import org.codehaus.redback.integration.mail.Mailer;
+import org.springframework.context.annotation.Scope;
+import org.springframework.stereotype.Controller;
+
+import javax.inject.Inject;
+import java.util.Arrays;
+
+/**
+ * PasswordResetAction
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+@Controller( "redback-password-reset" )
+@Scope( "prototype" )
+public class PasswordResetAction
+    extends AbstractSecurityAction
+    implements CancellableAction
+{
+    // ------------------------------------------------------------------
+    //  Component Requirements
+    // ------------------------------------------------------------------
+
+    /**
+     *
+     */
+    @Inject
+    private Mailer mailer;
+
+    /**
+     *
+     */
+    @Inject
+    private SecuritySystem securitySystem;
+
+    private String username;
+
+    // ------------------------------------------------------------------
+    // Action Entry Points - (aka Names)
+    // ------------------------------------------------------------------
+
+    public String show()
+    {
+        return INPUT;
+    }
+
+    public String reset()
+    {
+        if ( StringUtils.isEmpty( username ) )
+        {
+            addFieldError( "username", getText( "username.cannot.be.empty" ) );
+            return INPUT;
+        }
+
+        UserManager userManager = securitySystem.getUserManager();
+        KeyManager keyManager = securitySystem.getKeyManager();
+        UserSecurityPolicy policy = securitySystem.getPolicy();
+
+        try
+        {
+            User user = userManager.findUser( username );
+
+            AuthenticationKey authkey = keyManager.createKey( username, "Password Reset Request",
+                                                              policy.getUserValidationSettings().getEmailValidationTimeout() );
+
+            mailer.sendPasswordResetEmail( Arrays.asList( user.getEmail() ), authkey, getBaseUrl() );
+
+            AuditEvent event = new AuditEvent( getText( "log.password.reset.request" ) );
+            event.setAffectedUser( username );
+            event.log();
+
+            addActionMessage( getText( "password.reset.success" ) );
+        }
+        catch ( UserNotFoundException e )
+        {
+            // By default, the success and failure messages are the same.
+            // This is done to prevent a malicious user from attempting to ascertain the
+            // validity of usernames.
+            addActionMessage( getText( "password.reset.failure" ) );
+
+            log.info( "Password Reset on non-existant user [{}].", username );
+        }
+        catch ( KeyManagerException e )
+        {
+            addActionError( getText( "password.reset.email.generation.failure" ) );
+            log.info( "Unable to issue password reset.", e );
+        }
+
+        return INPUT;
+    }
+
+    // ------------------------------------------------------------------
+    // Security Specification
+    // ------------------------------------------------------------------
+
+    public SecureActionBundle initSecureActionBundle()
+        throws SecureActionException
+    {
+        return SecureActionBundle.OPEN;
+    }
+
+    public String cancel()
+    {
+        return NONE;
+    }
+
+    // ------------------------------------------------------------------
+    // Parameter Accessor Methods
+    // ------------------------------------------------------------------
+
+    public String getUsername()
+    {
+        return username;
+    }
+
+    public void setUsername( String username )
+    {
+        this.username = username;
+    }
+
+}

Propchange: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/PasswordResetAction.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/PasswordResetAction.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/RedbackActionSupport.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/RedbackActionSupport.java?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/RedbackActionSupport.java (added)
+++ archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/RedbackActionSupport.java Fri Apr  6 09:58:14 2012
@@ -0,0 +1,28 @@
+package org.codehaus.plexus.redback.struts2.action;
+
+import java.util.Map;
+
+import org.apache.struts2.interceptor.SessionAware;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.opensymphony.xwork2.ActionSupport;
+
+/**
+ *
+ * @author <a href="mailto:james@atlassian.com">James William Dumay</a>
+ */
+public abstract class RedbackActionSupport
+    extends ActionSupport
+    implements SessionAware
+{
+    protected Logger log = LoggerFactory.getLogger( this.getClass() );
+    
+    protected Map<String,Object> session;
+
+    public void setSession( Map<String, Object > map )
+    {
+        //noinspection AssignmentToCollectionOrArrayFieldFromParameter
+        this.session = map;
+    }
+}

Propchange: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/RedbackActionSupport.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/RedbackActionSupport.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/RegisterAction.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/RegisterAction.java?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/RegisterAction.java (added)
+++ archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/RegisterAction.java Fri Apr  6 09:58:14 2012
@@ -0,0 +1,263 @@
+package org.codehaus.plexus.redback.struts2.action;
+
+/*
+ * Copyright 2005-2006 The Codehaus.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.codehaus.plexus.redback.keys.AuthenticationKey;
+import org.codehaus.plexus.redback.keys.KeyManagerException;
+import org.codehaus.plexus.redback.policy.UserSecurityPolicy;
+import org.codehaus.plexus.redback.role.RoleManager;
+import org.codehaus.plexus.redback.role.RoleManagerException;
+import org.codehaus.plexus.redback.users.User;
+import org.codehaus.plexus.redback.users.UserManager;
+import org.codehaus.plexus.redback.users.UserNotFoundException;
+import org.codehaus.redback.integration.interceptor.SecureActionBundle;
+import org.codehaus.redback.integration.interceptor.SecureActionException;
+import org.codehaus.redback.integration.mail.Mailer;
+import org.codehaus.redback.integration.model.CreateUserCredentials;
+import org.codehaus.redback.integration.security.role.RedbackRoleConstants;
+import org.springframework.context.annotation.Scope;
+import org.springframework.stereotype.Controller;
+
+import javax.inject.Inject;
+import java.util.Arrays;
+
+/**
+ * RegisterAction
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+@Controller( "redback-register" )
+@Scope( "prototype" )
+public class RegisterAction
+    extends AbstractUserCredentialsAction
+    implements CancellableAction
+{
+    protected static final String REGISTER_SUCCESS = "security-register-success";
+
+    private static final String VALIDATION_NOTE = "validation-note";
+
+    private static final String RESEND_VALIDATION_EMAIL = "security-resend-validation-email";
+
+    // ------------------------------------------------------------------
+    //  Component Requirements
+    // ------------------------------------------------------------------
+
+    /**
+     *
+     */
+    @Inject
+    private Mailer mailer;
+
+    /**
+     *
+     */
+    @Inject
+    private RoleManager roleManager;
+
+    private CreateUserCredentials user;
+
+    private boolean emailValidationRequired;
+
+    private String username;
+
+    // ------------------------------------------------------------------
+    // Action Entry Points - (aka Names)
+    // ------------------------------------------------------------------
+
+    public String show()
+    {
+        if ( user == null )
+        {
+            user = new CreateUserCredentials();
+        }
+
+        emailValidationRequired = securitySystem.getPolicy().getUserValidationSettings().isEmailValidationRequired();
+
+        return INPUT;
+    }
+
+    public String register()
+    {
+        if ( user == null )
+        {
+            user = new CreateUserCredentials();
+            addActionError( getText( "invalid.user.credentials" ) );
+            return ERROR;
+        }
+
+        UserSecurityPolicy securityPolicy = securitySystem.getPolicy();
+
+        emailValidationRequired = securityPolicy.getUserValidationSettings().isEmailValidationRequired();
+
+        internalUser = user;
+
+        if ( securityPolicy.getUserValidationSettings().isEmailValidationRequired() )
+        {
+            validateCredentialsLoose();
+        }
+        else
+        {
+            validateCredentialsStrict();
+        }
+
+        // NOTE: Do not perform Password Rules Validation Here.
+        UserManager manager = super.securitySystem.getUserManager();
+
+        if ( manager.userExists( user.getUsername() ) )
+        {
+            // Means that the role name doesn't exist.
+            // We need to fail fast and return to the previous page.
+            addActionError( getText( "user.already.exists", Arrays.asList( (Object) user.getUsername() ) ) );
+        }
+
+        if ( hasActionErrors() || hasFieldErrors() )
+        {
+            return ERROR;
+        }
+
+        User u = manager.createUser( user.getUsername(), user.getFullName(), user.getEmail() );
+        u.setPassword( user.getPassword() );
+        u.setValidated( false );
+        u.setLocked( false );
+
+        try
+        {
+            roleManager.assignRole( RedbackRoleConstants.REGISTERED_USER_ROLE_ID, u.getPrincipal().toString() );
+        }
+        catch ( RoleManagerException rpe )
+        {
+            addActionError( getText( "assign.role.failure" ) );
+            log.error( "RoleProfile Error: " + rpe.getMessage(), rpe );
+            return ERROR;
+        }
+
+        if ( securityPolicy.getUserValidationSettings().isEmailValidationRequired() )
+        {
+            u.setLocked( true );
+
+            try
+            {
+                AuthenticationKey authkey =
+                    securitySystem.getKeyManager().createKey( u.getPrincipal().toString(), "New User Email Validation",
+                                                              securityPolicy.getUserValidationSettings().getEmailValidationTimeout() );
+
+                mailer.sendAccountValidationEmail( Arrays.asList( u.getEmail() ), authkey, getBaseUrl() );
+
+                securityPolicy.setEnabled( false );
+                manager.addUser( u );
+
+                return VALIDATION_NOTE;
+            }
+            catch ( KeyManagerException e )
+            {
+                addActionError( getText( "cannot.register.user" ) );
+                log.error( "Unable to register a new user.", e );
+                return ERROR;
+            }
+            finally
+            {
+                securityPolicy.setEnabled( true );
+            }
+        }
+        else
+        {
+            manager.addUser( u );
+        }
+
+        AuditEvent event = new AuditEvent( getText( "log.account.create" ) );
+        event.setAffectedUser( username );
+        event.log();
+
+        return REGISTER_SUCCESS;
+    }
+
+    public String resendRegistrationEmail()
+    {
+        UserSecurityPolicy securityPolicy = securitySystem.getPolicy();
+
+        try
+        {
+            User user = super.securitySystem.getUserManager().findUser( username );
+
+            AuthenticationKey authkey =
+                securitySystem.getKeyManager().createKey( user.getPrincipal().toString(), "New User Email Validation",
+                                                          securityPolicy.getUserValidationSettings().getEmailValidationTimeout() );
+
+            mailer.sendAccountValidationEmail( Arrays.asList( user.getEmail() ), authkey, getBaseUrl() );
+
+            return RESEND_VALIDATION_EMAIL;
+        }
+        catch ( KeyManagerException e )
+        {
+            addActionError( getText( "cannot.register.user" ) );
+            log.error( "Unable to register a new user.", e );
+            return ERROR;
+        }
+        catch ( UserNotFoundException e )
+        {
+            addActionError( getText( "cannot.find.user" ) );
+            log.error( "Unable to find user.", e );
+            return ERROR;
+        }
+    }
+
+    public String cancel()
+    {
+        return CANCEL;
+    }
+
+    // ------------------------------------------------------------------
+    // Parameter Accessor Methods
+    // ------------------------------------------------------------------
+
+    public CreateUserCredentials getUser()
+    {
+        return user;
+    }
+
+    public void setUser( CreateUserCredentials user )
+    {
+        this.user = user;
+    }
+
+    public boolean isEmailValidationRequired()
+    {
+        return emailValidationRequired;
+    }
+
+    public void setEmailValidationRequired( boolean emailValidationRequired )
+    {
+        this.emailValidationRequired = emailValidationRequired;
+    }
+
+    public String getUsername()
+    {
+        return username;
+    }
+
+    public void setUsername( String username )
+    {
+        this.username = username;
+    }
+
+    public SecureActionBundle initSecureActionBundle()
+        throws SecureActionException
+    {
+        return SecureActionBundle.OPEN;
+    }
+}

Propchange: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/RegisterAction.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/RegisterAction.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/SecurityRedirectAction.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/SecurityRedirectAction.java?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/SecurityRedirectAction.java (added)
+++ archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/SecurityRedirectAction.java Fri Apr  6 09:58:14 2012
@@ -0,0 +1,55 @@
+package org.codehaus.plexus.redback.struts2.action;
+
+/*
+ * Copyright 2005-2006 The Codehaus.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.codehaus.plexus.util.StringUtils;
+import org.springframework.context.annotation.Scope;
+import org.springframework.stereotype.Controller;
+
+/**
+ * SecurityRedirectAction
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+@Controller( "redback-redirect" )
+@Scope( "prototype" )
+public class SecurityRedirectAction
+    extends RedbackActionSupport
+{
+    private String externalResult;
+
+    public String redirect()
+    {
+        if ( StringUtils.isNotEmpty( externalResult ) )
+        {
+            return externalResult;
+        }
+
+        return SUCCESS;
+    }
+
+    public String getExternalResult()
+    {
+        return externalResult;
+    }
+
+    public void setExternalResult( String name )
+    {
+        this.externalResult = name;
+    }
+}

Propchange: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/SecurityRedirectAction.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/SecurityRedirectAction.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/admin/AbstractAdminUserCredentialsAction.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/admin/AbstractAdminUserCredentialsAction.java?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/admin/AbstractAdminUserCredentialsAction.java (added)
+++ archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/admin/AbstractAdminUserCredentialsAction.java Fri Apr  6 09:58:14 2012
@@ -0,0 +1,41 @@
+package org.codehaus.plexus.redback.struts2.action.admin;
+
+/*
+ * Copyright 2005-2006 The Codehaus.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.codehaus.plexus.redback.struts2.action.AbstractUserCredentialsAction;
+
+/**
+ * AbstractAdminUserCredentialsAction
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public abstract class AbstractAdminUserCredentialsAction
+    extends AbstractUserCredentialsAction
+{
+    private String username;
+
+    public String getUsername()
+    {
+        return username;
+    }
+
+    public void setUsername( String username )
+    {
+        this.username = username;
+    }
+}

Propchange: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/admin/AbstractAdminUserCredentialsAction.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/admin/AbstractAdminUserCredentialsAction.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/admin/AddAdminUserAction.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/admin/AddAdminUserAction.java?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/admin/AddAdminUserAction.java (added)
+++ archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/admin/AddAdminUserAction.java Fri Apr  6 09:58:14 2012
@@ -0,0 +1,286 @@
+package org.codehaus.plexus.redback.struts2.action.admin;
+
+/*
+ * Copyright 2005-2006 The Codehaus.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.struts2.ServletActionContext;
+import org.codehaus.plexus.redback.authentication.AuthenticationConstants;
+import org.codehaus.plexus.redback.authentication.AuthenticationDataSource;
+import org.codehaus.plexus.redback.authentication.AuthenticationException;
+import org.codehaus.plexus.redback.authentication.AuthenticationResult;
+import org.codehaus.plexus.redback.authentication.PasswordBasedAuthenticationDataSource;
+import org.codehaus.plexus.redback.configuration.UserConfiguration;
+import org.codehaus.plexus.redback.policy.AccountLockedException;
+import org.codehaus.plexus.redback.policy.MustChangePasswordException;
+import org.codehaus.plexus.redback.role.RoleManager;
+import org.codehaus.plexus.redback.role.RoleManagerException;
+import org.codehaus.plexus.redback.struts2.action.AuditEvent;
+import org.codehaus.plexus.redback.system.SecuritySession;
+import org.codehaus.plexus.redback.users.User;
+import org.codehaus.plexus.redback.users.UserManager;
+import org.codehaus.plexus.redback.users.UserNotFoundException;
+import org.codehaus.redback.integration.interceptor.SecureActionBundle;
+import org.codehaus.redback.integration.interceptor.SecureActionException;
+import org.codehaus.redback.integration.model.EditUserCredentials;
+import org.codehaus.redback.integration.util.AutoLoginCookies;
+import org.springframework.context.annotation.Scope;
+import org.springframework.stereotype.Controller;
+
+import javax.inject.Inject;
+import java.util.Arrays;
+import java.util.Date;
+
+/**
+ * AddAdminUserAction
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+@Controller( "redback-admin-account" )
+@Scope( "prototype" )
+public class AddAdminUserAction
+    extends AbstractAdminUserCredentialsAction
+{
+    private static final String LOGIN_ERROR = "login-error";
+
+    private static final String LOGIN_SUCCESS = "security-login-success";
+
+    private static final String PASSWORD_CHANGE = "security-must-change-password";
+
+    private static final String ACCOUNT_LOCKED = "security-login-locked";
+
+    @Inject
+    private RoleManager roleManager;
+
+
+    @Inject
+    private UserConfiguration config;
+
+    private EditUserCredentials user;
+
+    @Inject
+    private AutoLoginCookies autologinCookies;
+
+    public String show()
+    {
+        if ( user == null )
+        {
+            user = new EditUserCredentials( config.getString( "redback.default.admin" ) );
+        }
+
+        return INPUT;
+    }
+
+    /**
+     * TODO this must done in a service !!
+     * @return
+     */
+    public String submit()
+    {
+        if ( user == null )
+        {
+            user = new EditUserCredentials( config.getString( "redback.default.admin" ) );
+            addActionError( getText( "invalid.admin.credentials" ) );
+            return ERROR;
+        }
+
+        log.info( "user = {}", user );
+
+        internalUser = user;
+
+        validateCredentialsStrict();
+
+        UserManager userManager = super.securitySystem.getUserManager();
+
+        if ( userManager.userExists( config.getString( "redback.default.admin" ) ) )
+        {
+            // Means that the role name exist already.
+            // We need to fail fast and return to the previous page.
+            addActionError( getText( "admin.user.already.exists" ) );
+            return ERROR;
+        }
+
+        if ( hasActionErrors() || hasFieldErrors() )
+        {
+            return ERROR;
+        }
+
+        User u =
+            userManager.createUser( config.getString( "redback.default.admin" ), user.getFullName(), user.getEmail() );
+        if ( u == null )
+        {
+            addActionError( getText( "cannot.operate.on.null.user" ) );
+            return ERROR;
+        }
+
+        u.setPassword( user.getPassword() );
+        u.setLocked( false );
+        u.setPasswordChangeRequired( false );
+        u.setPermanent( true );
+
+        userManager.addUser( u );
+
+        AuditEvent event = new AuditEvent( getText( "log.account.create" ) );
+        event.setAffectedUser( u.getUsername() );
+        event.log();
+
+        try
+        {
+            roleManager.assignRole( "system-administrator", u.getPrincipal().toString() );
+            event = new AuditEvent( getText( "log.assign.role" ) );
+            event.setAffectedUser( u.getUsername() );
+            event.setRole( "system-administrator" );
+            event.log();
+        }
+        catch ( RoleManagerException rpe )
+        {
+            addActionError( getText( "cannot.assign.admin.role" ) );
+            return ERROR;
+        }
+
+        PasswordBasedAuthenticationDataSource authdatasource = new PasswordBasedAuthenticationDataSource();
+        authdatasource.setPrincipal( user.getUsername() );
+        authdatasource.setPassword( user.getPassword() );
+
+        return webLogin( authdatasource );
+    }
+
+    public EditUserCredentials getUser()
+    {
+        return user;
+    }
+
+    public void setUser( EditUserCredentials user )
+    {
+        this.user = user;
+    }
+
+    public SecureActionBundle initSecureActionBundle()
+        throws SecureActionException
+    {
+        return SecureActionBundle.OPEN;
+    }
+
+    /**
+     * 1) attempts to authentication based on the passed in data source
+     * 2) if successful sets cookies and returns LOGIN_SUCCESS
+     * 3) if failure then check what kinda failure and return error
+     *
+     * @param authdatasource
+     * @return
+     */
+    private String webLogin( AuthenticationDataSource authdatasource )
+    {
+        // An attempt should log out your authentication tokens first!
+        setAuthTokens( null );
+
+        clearErrorsAndMessages();
+
+        String principal = authdatasource.getPrincipal();
+
+        try
+        {
+            SecuritySession securitySession = securitySystem.authenticate( authdatasource );
+
+            if ( securitySession.getAuthenticationResult().isAuthenticated() )
+            {
+                // Success!  Create tokens.
+                setAuthTokens( securitySession );
+
+                setCookies( authdatasource );
+
+                AuditEvent event = new AuditEvent( getText( "log.login.success" ) );
+                event.setAffectedUser( principal );
+                event.log();
+
+                User u = securitySession.getUser();
+                u.setLastLoginDate( new Date() );
+                securitySystem.getUserManager().updateUser( u );
+
+                return LOGIN_SUCCESS;
+            }
+            else
+            {
+                log.debug( "Login Action failed against principal : {}",
+                           securitySession.getAuthenticationResult().getPrincipal(),
+                           securitySession.getAuthenticationResult().getException() );
+
+                AuthenticationResult result = securitySession.getAuthenticationResult();
+                if ( result.getExceptionsMap() != null && !result.getExceptionsMap().isEmpty() )
+                {
+                    if ( result.getExceptionsMap().get( AuthenticationConstants.AUTHN_NO_SUCH_USER ) != null )
+                    {
+                        addActionError( getText( "incorrect.username.password" ) );
+                    }
+                    else
+                    {
+                        addActionError( getText( "authentication.failed" ) );
+                    }
+                }
+                else
+                {
+                    addActionError( getText( "authentication.failed" ) );
+                }
+
+                AuditEvent event = new AuditEvent( getText( "log.login.fail" ) );
+                event.setAffectedUser( principal );
+                event.log();
+
+                return LOGIN_ERROR;
+            }
+        }
+        catch ( AuthenticationException ae )
+        {
+            addActionError( getText( "authentication.exception", Arrays.asList( (Object) ae.getMessage() ) ) );
+            return LOGIN_ERROR;
+        }
+        catch ( UserNotFoundException ue )
+        {
+            addActionError(
+                getText( "user.not.found.exception", Arrays.asList( (Object) principal, ue.getMessage() ) ) );
+
+            AuditEvent event = new AuditEvent( getText( "log.login.fail" ) );
+            event.setAffectedUser( principal );
+            event.log();
+            return LOGIN_ERROR;
+        }
+        catch ( AccountLockedException e )
+        {
+            addActionError( getText( "account.locked" ) );
+
+            AuditEvent event = new AuditEvent( getText( "log.login.fail.locked" ) );
+            event.setAffectedUser( principal );
+            event.log();
+            return ACCOUNT_LOCKED;
+        }
+        catch ( MustChangePasswordException e )
+        {
+            // TODO: preferably we would not set the cookies for this "partial" login state
+            setCookies( authdatasource );
+
+            AuditEvent event = new AuditEvent( getText( "log.login.fail.locked" ) );
+            event.setAffectedUser( principal );
+            event.log();
+            return PASSWORD_CHANGE;
+        }
+    }
+
+    private void setCookies( AuthenticationDataSource authdatasource )
+    {
+        autologinCookies.setSignonCookie( authdatasource.getPrincipal(), ServletActionContext.getResponse(),
+                                          ServletActionContext.getRequest() );
+    }
+}

Propchange: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/admin/AddAdminUserAction.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: archiva/redback/redback-core/trunk/redback-integrations/redback-struts2/redback-struts2-integration/src/main/java/org/codehaus/plexus/redback/struts2/action/admin/AddAdminUserAction.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision