Author: jmcconnell
Date: Mon Sep 11 12:24:10 2006
New Revision: 442298

URL: http://svn.apache.org/viewvc?view=rev&rev=442298
Log:
improved the flow of login / registration and decorator

Modified:
    
maven/archiva/trunk/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/NewUserAction.java
    
maven/archiva/trunk/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/UserManagementAction.java
    maven/archiva/trunk/archiva-webapp/src/main/resources/xwork.xml
    
maven/archiva/trunk/archiva-webapp/src/main/webapp/WEB-INF/jsp/decorators/default.jsp
    maven/archiva/trunk/archiva-webapp/src/main/webapp/WEB-INF/jsp/user.jsp

Modified: 
maven/archiva/trunk/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/NewUserAction.java
URL: 
http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/NewUserAction.java?view=diff&rev=442298&r1=442297&r2=442298
==============================================================================
--- 
maven/archiva/trunk/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/NewUserAction.java
 (original)
+++ 
maven/archiva/trunk/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/NewUserAction.java
 Mon Sep 11 12:24:10 2006
@@ -1,22 +1,22 @@
 package org.apache.maven.archiva.web.action.admin;
 
-
 /*
- * Copyright 2005 The Apache Software Foundation.
- *
- * 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.
- */
+* Copyright 2005 The Apache Software Foundation.
+*
+* 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.maven.archiva.web.util.RoleManager;
 import org.codehaus.plexus.security.system.SecuritySystem;
 import org.codehaus.plexus.security.user.User;
 import org.codehaus.plexus.security.user.UserManager;
@@ -24,7 +24,6 @@
 import org.codehaus.plexus.security.user.policy.PasswordRuleViolations;
 import org.codehaus.plexus.util.StringUtils;
 import org.codehaus.plexus.xwork.action.PlexusActionSupport;
-import org.apache.maven.archiva.web.util.RoleManager;
 
 import java.util.Iterator;
 import java.util.List;
@@ -90,31 +89,38 @@
 
         UserManager um = securitySystem.getUserManager();
 
-        User user = um.createUser( username, fullName, email );
-
-        user.setPassword( password );
-
-        try
+        if ( um.userExists( username ) )
         {
-            um.addUser( user );
+            addActionError( "User already exists!" );
         }
-        catch ( PasswordRuleViolationException e )
+        else
         {
-            PasswordRuleViolations violations = e.getViolations();
-            List violationList = violations.getLocalizedViolations();
-            Iterator it = violationList.iterator();
-            while ( it.hasNext() )
+            User user = um.createUser( username, fullName, email );
+
+            user.setPassword( password );
+
+            try
             {
-                addActionError( (String) it.next() );
+                um.addUser( user );
             }
-        }
+            catch ( PasswordRuleViolationException e )
+            {
+                PasswordRuleViolations violations = e.getViolations();
+                List violationList = violations.getLocalizedViolations();
+                Iterator it = violationList.iterator();
+                while ( it.hasNext() )
+                {
+                    addActionError( (String) it.next() );
+                }
+            }
+            roleManager.addUser( user.getPrincipal().toString() );
 
+        }
+        
         if ( hasActionErrors() )
         {
             return ERROR;
         }
-
-        roleManager.addUser( user.getPrincipal().toString() );
 
         return SUCCESS;
     }

Modified: 
maven/archiva/trunk/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/UserManagementAction.java
URL: 
http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/UserManagementAction.java?view=diff&rev=442298&r1=442297&r2=442298
==============================================================================
--- 
maven/archiva/trunk/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/UserManagementAction.java
 (original)
+++ 
maven/archiva/trunk/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/UserManagementAction.java
 Mon Sep 11 12:24:10 2006
@@ -17,18 +17,19 @@
  * limitations under the License.
  */
 
-import com.opensymphony.xwork.ModelDriven;
-import com.opensymphony.xwork.Preparable;
 import org.codehaus.plexus.security.rbac.RBACManager;
 import org.codehaus.plexus.security.user.User;
 import org.codehaus.plexus.security.user.UserManager;
+import org.codehaus.plexus.security.user.UserNotFoundException;
+import org.codehaus.plexus.security.system.SecuritySession;
 import org.codehaus.plexus.xwork.action.PlexusActionSupport;
 
 import java.util.ArrayList;
 import java.util.List;
 
 /**
- * LoginAction:
+ * UserManagementAction: pulled from the class of the same name in 
plexus-security-ui-web
+ * for integrating rbac with user information
  *
  * @author Jesse McConnell <[EMAIL PROTECTED]>
  * @version $Id:$
@@ -37,7 +38,6 @@
  */
 public class UserManagementAction
     extends PlexusActionSupport
-    implements ModelDriven, Preparable
 {
 
     /**
@@ -52,6 +52,12 @@
 
     private User user;
 
+    private String email;
+
+    private String fullName;
+
+    private boolean locked;
+
     private String username;
 
     private String principal;
@@ -64,41 +70,58 @@
 
     private String resourceName;
 
-    public void prepare()
-        throws Exception
+    /**
+     * for this method username should be populated
+     * 
+     * @return
+     */
+    public String findUser()
     {
-        if ( username == null )
+        try
         {
-            username = ( (User) session.get( "user" ) ).getUsername();
-            user = userManager.findUser( username );
+            user = userManager.findUser( username );                 
+            return SUCCESS;
         }
-        else
+        catch ( UserNotFoundException ne )
         {
-            user = userManager.findUser( username );
+            addActionError( "user could not be found "  + username );
+            return ERROR;
         }
+    }
 
-        resources = rbacManager.getAllResources();
-
-        availableRoles = rbacManager.getAllAssignableRoles();
+    /**
+     * For this method, principal should be populated
+     *
+     * @throws Exception
+     */
+    public String display()
+        throws Exception
+    {
+        if ( principal == null )
+        {
+            addActionError( "a principal is required for this operation" );
+            return ERROR;
+        }
 
-        principal = ( (User) session.get( "user" ) ).getPrincipal().toString();
+        // for displaying the potential repositories to be displayed, remove 
the global resource
+        // from the list
+        resources = rbacManager.getAllResources();
+        resources.remove( rbacManager.getGlobalResource() );
 
+        // check if the user has any roles assigned to them, and populate the 
lists for
+        // rendering assign and remove roles links
         if ( principal != null && rbacManager.userAssignmentExists( principal 
) )
         {
-            getLogger().info( "recovering assigned roles" );
             assignedRoles = new ArrayList( rbacManager.getAssignedRoles( 
principal ) );
             availableRoles = new ArrayList( rbacManager.getUnassignedRoles( 
principal ) );
         }
         else
         {
-            getLogger().info( "new assigned roles" );
             assignedRoles = new ArrayList();
             availableRoles = rbacManager.getAllAssignableRoles();
-
         }
 
-        getLogger().info( "assigned roles: " + assignedRoles.size() );
-        getLogger().info( "available roles: " + availableRoles.size() );
+        return SUCCESS;
     }
 
     public String save()
@@ -106,20 +129,23 @@
     {
         User temp = userManager.findUser( username );
 
-        temp.setEmail( user.getEmail() );
-        temp.setFullName( user.getFullName() );
-        temp.setLocked( user.isLocked() );
-
-        userManager.updateUser( temp );
+        temp.setEmail( email );
+        temp.setFullName( fullName );
+        temp.setLocked( locked );
+
+        temp = userManager.updateUser( temp );
+
+        // overwrite the user in the session with the saved one if and only if 
it is the
+        // save user as the person currently logged in
+        User activeUser = (User) session.get( SecuritySession.USERKEY );
+        if ( temp.getPrincipal().toString().equals( 
activeUser.getPrincipal().toString() ) )
+        {
+            session.put( SecuritySession.USERKEY, temp );
+        }
 
         return SUCCESS;
     }
 
-    public Object getModel()
-    {
-        return user;
-    }
-
     public String getUsername()
     {
         return username;
@@ -133,6 +159,41 @@
     public User getUser()
     {
         return user;
+    }
+
+    public void setUser( User user )
+    {
+        this.user = user;
+    }
+
+    public String getEmail()
+    {
+        return email;
+    }
+
+    public void setEmail( String email )
+    {
+        this.email = email;
+    }
+
+    public String getFullName()
+    {
+        return fullName;
+    }
+
+    public void setFullName( String fullName )
+    {
+        this.fullName = fullName;
+    }
+
+    public boolean isLocked()
+    {
+        return locked;
+    }
+
+    public void setLocked( boolean locked )
+    {
+        this.locked = locked;
     }
 
     public String getPrincipal()

Modified: maven/archiva/trunk/archiva-webapp/src/main/resources/xwork.xml
URL: 
http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-webapp/src/main/resources/xwork.xml?view=diff&rev=442298&r1=442297&r2=442298
==============================================================================
--- maven/archiva/trunk/archiva-webapp/src/main/resources/xwork.xml (original)
+++ maven/archiva/trunk/archiva-webapp/src/main/resources/xwork.xml Mon Sep 11 
12:24:10 2006
@@ -244,12 +244,13 @@
 
     <!-- plexus security actions -->
 
-    <action name="userDetails" class="plexusSecurityUserManagement" 
method="save">
+    <action name="userDetails" class="userManagement" method="save">
       <result name="success">/WEB-INF/jsp/userDetails.jsp</result>
     </action>
 
-    <action name="userManagement" class="plexusSecurityUserManagement">
-      <result name="success">/WEB-INF/jsp/findUser.jsp</result>
+    <action name="userManagement" class="userManagement" method="findUser">
+      <result name="input">/WEB-INF/jsp/findUser.jsp</result>
+      <result name="success" type="redirect-action">user</result>
     </action>
 
     <action name="assignRoleToUser" class="plexusSecurityUserAssignment" 
method="assignRole">

Modified: 
maven/archiva/trunk/archiva-webapp/src/main/webapp/WEB-INF/jsp/decorators/default.jsp
URL: 
http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-webapp/src/main/webapp/WEB-INF/jsp/decorators/default.jsp?view=diff&rev=442298&r1=442297&r2=442298
==============================================================================
--- 
maven/archiva/trunk/archiva-webapp/src/main/webapp/WEB-INF/jsp/decorators/default.jsp
 (original)
+++ 
maven/archiva/trunk/archiva-webapp/src/main/webapp/WEB-INF/jsp/decorators/default.jsp
 Mon Sep 11 12:24:10 2006
@@ -59,16 +59,19 @@
 
 <div id="breadcrumbs">
   <div class="xleft">
-    <ww:url id="loginUrl" action="login" namespace="/"/>
-    <ww:url id="logoutUrl" action="logout" namespace="/"/>
-    <ww:url id="manageUserUrl" action="user" namespace="/admin"/>
+    <ww:url id="loginUrl" action="login" namespace="/" includeParams="none"/>
 
     <ww:if test="${sessionScope.authStatus != true}">
       <ww:a href="%{loginUrl}">Login/Register</ww:a>
 
     </ww:if>
     <ww:else>
-      Welcome, <b>${sessionScope.user.username}</b> -
+      <ww:url id="logoutUrl" action="logout" namespace="/" 
includeParams="none"/>
+      <ww:url id="manageUserUrl" action="user" namespace="/admin">
+        <ww:param 
name="principal">${sessionScope.SecuritySessionUser.principal}</ww:param>
+      </ww:url>
+
+      Welcome, <b>${sessionScope.SecuritySessionUser.username}</b> -
       <ww:a href="%{manageUserUrl}">Settings</ww:a> -
       <ww:a href="%{logoutUrl}">Logout</ww:a>
     </ww:else>

Modified: 
maven/archiva/trunk/archiva-webapp/src/main/webapp/WEB-INF/jsp/user.jsp
URL: 
http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-webapp/src/main/webapp/WEB-INF/jsp/user.jsp?view=diff&rev=442298&r1=442297&r2=442298
==============================================================================
--- maven/archiva/trunk/archiva-webapp/src/main/webapp/WEB-INF/jsp/user.jsp 
(original)
+++ maven/archiva/trunk/archiva-webapp/src/main/webapp/WEB-INF/jsp/user.jsp Mon 
Sep 11 12:24:10 2006
@@ -29,23 +29,23 @@
         <div style="float: right">
           <pss:ifAnyAuthorized permissions="edit-all-users,edit-user" 
resource="${username}">
             <ww:url id="userDetailsUrl" action="userDetails">
-              <ww:param name="username">${username}</ww:param>
+              <ww:param 
name="username">${sessionScope.SecuritySessionUser.username}</ww:param>
             </ww:url>
             <ww:a href="%{userDetailsUrl}">Edit details</ww:a>
           </pss:ifAnyAuthorized>
         </div>
 
-        <h2>${user.fullName}</h2>
+        <h2>${sessionScope.SecuritySessionUser.fullName}</h2>
 
         <table class="bodyTable">
           <tr class="a">
             <th>Username</th>
 
-            <td>${user.username}</td>
+            <td>${sessionScope.SecuritySessionUser.username}</td>
           </tr>
           <tr class="b">
             <th>Email</th>
-            <td>${user.email}</td>
+            <td>${sessionScope.SecuritySessionUser.email}</td>
           </tr>
         </table>
 
@@ -54,8 +54,8 @@
         <table class="bodyTable">
           <ww:iterator id="role" value="assignedRoles">
             <ww:url id="removeAssignedRoleUrl" action="removeRoleFromUser">
-              <ww:param name="principal">${principal}</ww:param>
-              <ww:param name="roleName">${role.name}</ww:param>
+              <ww:param 
name="principal">${sessionScope.SecuritySessionUser.principal}</ww:param>
+              <ww:param 
name="roleName">${sessionScope.SecuritySessionUser.name}</ww:param>
             </ww:url>
             <tr class="a">
              <td>
@@ -73,13 +73,13 @@
         <p>
           <ww:iterator id="role" value="availableRoles">
             <ww:url id="addRoleUrl" action="assignRoleToUser">
-              <ww:param 
name="principal">${sessionScope.user.principal}</ww:param>
+              <ww:param 
name="principal">${sessionScope.SecuritySessionUser.principal}</ww:param>
               <ww:param name="roleName">${role.name}</ww:param>
             </ww:url>
             <ww:a href="%{addRoleUrl}">${role.name}</ww:a><br/>
           </ww:iterator>
            </p>
-
+           <%--
           <p>
             This following screen needs have the various roles worked into it.
           </p>
@@ -114,7 +114,7 @@
                 of
                 <ww:select name="resourceName" list="resources" 
listKey="identifier" listValue="identifier" headerKey="" headerValue="(Please 
Select)"/>
               </td>
-            </tr>
+            </tr> --%>
                  <%--  add in for project level security
             <tr class="b">
               <td>


Reply via email to