archiva-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmcconn...@apache.org
Subject svn commit: r442742 - in /maven/archiva/trunk/archiva-webapp/src/main: java/org/apache/maven/archiva/web/action/admin/ java/org/apache/maven/archiva/web/interceptor/ java/org/apache/maven/archiva/web/util/ resources/ resources/META-INF/plexus/ webapp/W...
Date Tue, 12 Sep 2006 22:31:03 GMT
Author: jmcconnell
Date: Tue Sep 12 15:31:02 2006
New Revision: 442742

URL: http://svn.apache.org/viewvc?view=rev&rev=442742
Log:
new setup wizard that forces the creation of an administrator user

Added:
    maven/archiva/trunk/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/registerAdmin.jsp
  (with props)
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/interceptor/ConfigurationInterceptor.java
    maven/archiva/trunk/archiva-webapp/src/main/java/org/apache/maven/archiva/web/util/DefaultRoleManager.java
    maven/archiva/trunk/archiva-webapp/src/main/java/org/apache/maven/archiva/web/util/RoleManager.java
    maven/archiva/trunk/archiva-webapp/src/main/resources/META-INF/plexus/plexus-security.properties
    maven/archiva/trunk/archiva-webapp/src/main/resources/xwork.xml

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=442742&r1=442741&r2=442742
==============================================================================
--- 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
Tue Sep 12 15:31:02 2006
@@ -22,6 +22,7 @@
 import org.codehaus.plexus.security.user.UserManager;
 import org.codehaus.plexus.security.user.policy.PasswordRuleViolationException;
 import org.codehaus.plexus.security.user.policy.PasswordRuleViolations;
+import org.codehaus.plexus.security.rbac.RBACManager;
 import org.codehaus.plexus.util.StringUtils;
 import org.codehaus.plexus.xwork.action.PlexusActionSupport;
 
@@ -51,6 +52,11 @@
      */
     private RoleManager roleManager;
 
+    /**
+     * @plexus.requirement
+     */
+    private RBACManager rbacManager;
+
     private String username;
 
     private String password;
@@ -118,11 +124,82 @@
                     addActionError( (String) it.next() );
                 }
             }
+
             roleManager.addUser( user.getPrincipal().toString() );
 
             addActionMessage( "user " + username + " was successfully registered!");
         }
         
+        if ( hasActionErrors() )
+        {
+            return INPUT;
+        }
+
+        return SUCCESS;
+    }
+
+    public String createAdminUser()
+    {
+        if ( username == null )
+        {
+            return INPUT;
+        }
+
+        // TODO: use commons-validator for these fields.
+
+        if ( StringUtils.isEmpty( username ) )
+        {
+            addActionError( "User Name is required." );
+        }
+
+        if ( StringUtils.isEmpty( fullName ) )
+        {
+            addActionError( "Full Name is required." );
+        }
+
+        if ( StringUtils.isEmpty( email ) )
+        {
+            addActionError( "Email Address is required." );
+        }
+
+        // TODO: Validate Email Address (use commons-validator)
+
+        if ( StringUtils.equals( password, passwordConfirm ) )
+        {
+            addActionError( "Passwords do not match." );
+        }
+
+        UserManager um = securitySystem.getUserManager();
+
+        if ( um.userExists( username ) )
+        {
+            addActionError( "User already exists!" );
+        }
+        else
+        {
+            User user = um.createUser( username, fullName, email );
+
+            user.setPassword( password );
+
+            try
+            {
+                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.addAdminUser( user.getPrincipal().toString() );
+            
+        }
+
         if ( hasActionErrors() )
         {
             return INPUT;

Modified: maven/archiva/trunk/archiva-webapp/src/main/java/org/apache/maven/archiva/web/interceptor/ConfigurationInterceptor.java
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-webapp/src/main/java/org/apache/maven/archiva/web/interceptor/ConfigurationInterceptor.java?view=diff&rev=442742&r1=442741&r2=442742
==============================================================================
--- maven/archiva/trunk/archiva-webapp/src/main/java/org/apache/maven/archiva/web/interceptor/ConfigurationInterceptor.java
(original)
+++ maven/archiva/trunk/archiva-webapp/src/main/java/org/apache/maven/archiva/web/interceptor/ConfigurationInterceptor.java
Tue Sep 12 15:31:02 2006
@@ -22,6 +22,7 @@
 import org.apache.maven.archiva.configuration.ConfigurationStore;
 import org.apache.maven.archiva.web.util.RoleManager;
 import org.codehaus.plexus.logging.AbstractLogEnabled;
+import org.codehaus.plexus.security.rbac.RBACManager;
 
 /**
  * An interceptor that makes the application configuration available
@@ -44,6 +45,11 @@
     private RoleManager roleManager;
 
     /**
+     * @plexus.requirement
+     */
+    private RBACManager rbacManager;
+
+    /**
      *
      * @param actionInvocation
      * @return
@@ -52,6 +58,13 @@
     public String intercept( ActionInvocation actionInvocation )
         throws Exception
     {
+
+        if ( rbacManager.getAllUserAssignments().size() == 0 )
+        {
+            getLogger().info( "no accounts setup, create user account, forwarding to registration"
);
+            return "admin-account-needed";
+        }
+
         Configuration configuration = configurationStore.getConfigurationFromStore();
 
         if ( !configuration.isValid() )

Modified: maven/archiva/trunk/archiva-webapp/src/main/java/org/apache/maven/archiva/web/util/DefaultRoleManager.java
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-webapp/src/main/java/org/apache/maven/archiva/web/util/DefaultRoleManager.java?view=diff&rev=442742&r1=442741&r2=442742
==============================================================================
--- maven/archiva/trunk/archiva-webapp/src/main/java/org/apache/maven/archiva/web/util/DefaultRoleManager.java
(original)
+++ maven/archiva/trunk/archiva-webapp/src/main/java/org/apache/maven/archiva/web/util/DefaultRoleManager.java
Tue Sep 12 15:31:02 2006
@@ -253,6 +253,28 @@
 
     }
 
+    /**
+     * helper method for just creating an admin user assignment
+     *
+     * @param principal
+     * @throws RbacStoreException
+     * @throws RbacObjectNotFoundException
+     */
+    public void addAdminUser( String principal )
+        throws RbacStoreException
+    {
+        try
+        {
+            UserAssignment assignment = manager.createUserAssignment( principal );
+            assignment.addRole( manager.getRole( "System Administrator" ) );
+            manager.saveUserAssignment( assignment );
+        }
+        catch ( RbacObjectNotFoundException ne )
+        {
+            throw new RbacStoreException( "unable to find administrator role, this of course
is bad", ne );
+        }
+    }
+
     public void addRepository( String repositoryName )
         throws RbacStoreException
     {

Modified: maven/archiva/trunk/archiva-webapp/src/main/java/org/apache/maven/archiva/web/util/RoleManager.java
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-webapp/src/main/java/org/apache/maven/archiva/web/util/RoleManager.java?view=diff&rev=442742&r1=442741&r2=442742
==============================================================================
--- maven/archiva/trunk/archiva-webapp/src/main/java/org/apache/maven/archiva/web/util/RoleManager.java
(original)
+++ maven/archiva/trunk/archiva-webapp/src/main/java/org/apache/maven/archiva/web/util/RoleManager.java
Tue Sep 12 15:31:02 2006
@@ -35,5 +35,8 @@
     public void addUser( String principal )
         throws RbacStoreException;
 
+    public void addAdminUser( String principal )
+        throws RbacStoreException;
+
     public boolean isInitialized();
 }

Modified: maven/archiva/trunk/archiva-webapp/src/main/resources/META-INF/plexus/plexus-security.properties
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-webapp/src/main/resources/META-INF/plexus/plexus-security.properties?view=diff&rev=442742&r1=442741&r2=442742
==============================================================================
--- maven/archiva/trunk/archiva-webapp/src/main/resources/META-INF/plexus/plexus-security.properties
(original)
+++ maven/archiva/trunk/archiva-webapp/src/main/resources/META-INF/plexus/plexus-security.properties
Tue Sep 12 15:31:02 2006
@@ -1,4 +1,8 @@
 #
+# properties that might be used in plexus-security initialization
+#
+
+#
 # operations
 #
 addRepositoryOperation=add-repository

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=442742&r1=442741&r2=442742
==============================================================================
--- maven/archiva/trunk/archiva-webapp/src/main/resources/xwork.xml (original)
+++ maven/archiva/trunk/archiva-webapp/src/main/resources/xwork.xml Tue Sep 12 15:31:02 2006
@@ -46,6 +46,11 @@
         <param name="namespace">/admin</param>
         <param name="actionName">configure</param>
       </result>
+      <result name="admin-account-needed" type="redirect-action">
+        <param name="namespace">/admin</param>
+        <param name="actionName">registerAdminAccount</param>
+        <param name="method">input</param>
+      </result>
       <result name="config-repository-needed" type="redirect-action">
         <param name="namespace">/admin</param>
         <param name="actionName">addRepository</param>
@@ -145,6 +150,13 @@
 
   <!-- Configuration for the admin package. -->
   <package name="admin" namespace="/admin" extends="base">
+    <action name="registerAdminAccount" class="newUser" method="createAdminUser">
+      <result name="input">/WEB-INF/jsp/admin/registerAdmin.jsp</result>
+      <result name="error">/WEB-INF/jsp/admin/registerAdmin.jsp</result>
+      <result type="redirect-action">index</result>
+      <interceptor-ref name="defaultStack"/>
+    </action>
+
     <action name="index" class="configureAction" method="input">
       <result name="input">/WEB-INF/jsp/admin/index.jsp</result>
     </action>

Added: maven/archiva/trunk/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/registerAdmin.jsp
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/registerAdmin.jsp?view=auto&rev=442742
==============================================================================
--- maven/archiva/trunk/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/registerAdmin.jsp
(added)
+++ maven/archiva/trunk/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/registerAdmin.jsp
Tue Sep 12 15:31:02 2006
@@ -0,0 +1,99 @@
+<%--
+  ~ Copyright 2005-2006 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.
+  --%>
+
+<%@ taglib prefix="ww" uri="/webwork" %>
+<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
+
+<html>
+<head>
+  <title>Adminsitrator Registration Page</title>
+  <ww:head/>
+</head>
+
+<body>
+
+<div id="contentArea">
+  <div id="searchBox">
+    <p>
+      <ww:actionmessage/>
+      <ww:actionerror/>
+    </p>
+
+    <h2>Setup an Administrator Account</h2>
+    <ww:form action="registerAdminAccount" method="post" namespace="/admin">
+      <table class="bodyTable">
+        <tr class="b">
+          <th>
+            Username
+          </th>
+          <td>
+            <ww:textfield name="username" size="30"/>
+          </td>
+        </tr>
+        <tr class="a">
+          <th>
+            Password
+          </th>
+          <td>
+            <ww:password name="password" size="20"/>
+          </td>
+        </tr>
+        <tr class="b">
+          <th>
+            Confirm Password
+          </th>
+          <td>
+            <ww:password name="confirmPassword" size="20"/>
+          </td>
+
+        </tr>
+        <tr class="a">
+          <th>
+            Full Name
+          </th>
+          <td>
+            <ww:textfield name="fullName" size="30"/>
+          </td>
+        </tr>
+
+        <tr class="b">
+          <th>
+            Email
+          </th>
+          <td>
+            <ww:textfield name="email" size="50 "/>
+          </td>
+        </tr>
+        <tr class="a">
+          <td></td>
+          <td>
+            <ww:submit value="Register"/>
+          </td>
+        </tr>
+      </table>
+    </ww:form>
+
+  </div>
+</div>
+
+
+<div class="clear">
+  <hr/>
+</div>
+
+</body>
+
+</html>

Propchange: maven/archiva/trunk/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/registerAdmin.jsp
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message