Author: joakime
Date: Fri Oct 19 14:46:08 2007
New Revision: 586622

URL: http://svn.apache.org/viewvc?rev=586622&view=rev
Log:
[MRM-398] configure guest access by default for pre-configured repositories
* Moving redback initialization from a lazy init via xwork interceptor to 
archiva's startup process.
* Changing UserAssignment process to check/create assignment before assigning 
new roles.


Modified:
    
maven/archiva/trunk/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/startup/SecuritySynchronization.java
    maven/archiva/trunk/archiva-web/archiva-webapp/src/main/resources/xwork.xml

Modified: 
maven/archiva/trunk/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/startup/SecuritySynchronization.java
URL: 
http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/startup/SecuritySynchronization.java?rev=586622&r1=586621&r2=586622&view=diff
==============================================================================
--- 
maven/archiva/trunk/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/startup/SecuritySynchronization.java
 (original)
+++ 
maven/archiva/trunk/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/startup/SecuritySynchronization.java
 Fri Oct 19 14:46:08 2007
@@ -19,6 +19,7 @@
  * under the License.
  */
 
+import org.apache.commons.collections.CollectionUtils;
 import org.apache.maven.archiva.common.ArchivaException;
 import org.apache.maven.archiva.configuration.ArchivaConfiguration;
 import org.apache.maven.archiva.configuration.ConfigurationNames;
@@ -30,10 +31,14 @@
 import org.codehaus.plexus.redback.rbac.UserAssignment;
 import org.codehaus.plexus.redback.role.RoleManager;
 import org.codehaus.plexus.redback.role.RoleManagerException;
+import org.codehaus.plexus.redback.system.check.EnvironmentCheck;
 import org.codehaus.plexus.registry.Registry;
 import org.codehaus.plexus.registry.RegistryListener;
 
+import java.util.ArrayList;
 import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
 
 /**
  * ConfigurationSynchronization
@@ -52,13 +57,18 @@
      * @plexus.requirement role-hint="default"
      */
     private RoleManager roleManager;
-    
+
     /**
      * @plexus.requirement role-hint="cached"
      */
     private RBACManager rbacManager;
 
     /**
+     * @plexus.requirement 
role="org.codehaus.plexus.redback.system.check.EnvironmentCheck"
+     */
+    private Map<String, EnvironmentCheck> checkers;
+
+    /**
      * @plexus.requirement
      */
     private ArchivaConfiguration archivaConfiguration;
@@ -79,24 +89,24 @@
     private void synchConfiguration( List<ManagedRepositoryConfiguration> 
repos )
     {
         // NOTE: Remote Repositories do not have roles or security placed 
around them.
-        
+
         for ( ManagedRepositoryConfiguration repoConfig : repos )
         {
             // manage roles for repositories
             try
             {
-                if ( !roleManager.templatedRoleExists( 
ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, 
-                                                       repoConfig.getId() ) )
+                if ( !roleManager.templatedRoleExists( 
ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, repoConfig
+                    .getId() ) )
                 {
-                    roleManager.createTemplatedRole( 
ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, 
-                                                     repoConfig.getId() );
+                    roleManager.createTemplatedRole( 
ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, repoConfig
+                        .getId() );
                 }
 
-                if ( !roleManager.templatedRoleExists( 
ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, 
-                                                       repoConfig.getId() ) )
+                if ( !roleManager.templatedRoleExists( 
ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, repoConfig
+                    .getId() ) )
                 {
-                    roleManager.createTemplatedRole( 
ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, 
-                                                     repoConfig.getId() );
+                    roleManager.createTemplatedRole( 
ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, repoConfig
+                        .getId() );
                 }
             }
             catch ( RoleManagerException e )
@@ -110,30 +120,87 @@
     public void startup()
         throws ArchivaException
     {
+        executeEnvironmentChecks();
+
         synchConfiguration( 
archivaConfiguration.getConfiguration().getManagedRepositories() );
         archivaConfiguration.addChangeListener( this );
-        
+
         if ( archivaConfiguration.isDefaulted() )
         {
             assignRepositoryObserverToGuestUser( 
archivaConfiguration.getConfiguration().getManagedRepositories() );
         }
     }
 
+    private void executeEnvironmentChecks()
+        throws ArchivaException
+    {
+        if ( ( checkers == null ) || CollectionUtils.isEmpty( 
checkers.values() ) )
+        {
+            throw new ArchivaException( "Unable to initialize the Redback 
Security Environment, "
+                + "no Environment Check components found." );
+        }
+
+        List<String> violations = new ArrayList<String>();
+
+        for ( Entry<String, EnvironmentCheck> entry : checkers.entrySet() )
+        {
+            EnvironmentCheck check = entry.getValue();
+            getLogger().info( "Running Environment Check: " + entry.getKey() );
+            check.validateEnvironment( violations );
+        }
+
+        if ( CollectionUtils.isNotEmpty( violations ) )
+        {
+            StringBuffer msg = new StringBuffer();
+            msg.append( "EnvironmentCheck Failure.\n" );
+            msg.append( 
"======================================================================\n" );
+            msg.append( " ENVIRONMENT FAILURE !! \n" );
+            msg.append( "\n" );
+
+            for ( String violation : violations )
+            {
+                msg.append( violation ).append( "\n" );
+            }
+
+            msg.append( "\n" );
+            msg.append( 
"======================================================================" );
+            getLogger().fatalError( msg.toString() );
+
+            throw new ArchivaException( "Unable to initialize Redback Security 
Environment, [" + violations.size()
+                + "] violation(s) encountered, See log for details." );
+        }
+    }
+
     private void assignRepositoryObserverToGuestUser( 
List<ManagedRepositoryConfiguration> repos )
     {
         for ( ManagedRepositoryConfiguration repoConfig : repos )
         {
             String repoId = repoConfig.getId();
+            
+            // TODO: Use the Redback / UserConfiguration..getString( 
"redback.default.guest" ) to get the right name.
+            String principal = "guest";
+            
             try
             {
-                UserAssignment ua = rbacManager.getUserAssignment( 
ArchivaRoleConstants.GUEST_ROLE );
+                UserAssignment ua;
+
+                if ( rbacManager.userAssignmentExists( principal ) )
+                {
+                    ua = rbacManager.getUserAssignment( principal );
+                }
+                else
+                {
+                    ua = rbacManager.createUserAssignment( principal );
+                }
+
                 ua.addRoleName( 
ArchivaRoleConstants.REPOSITORY_OBSERVER_ROLE_PREFIX + " - " + repoId );
                 rbacManager.saveUserAssignment( ua );
             }
             catch ( RbacManagerException e )
             {
-                getLogger().warn( "Unable to add role [" + 
ArchivaRoleConstants.REPOSITORY_OBSERVER_ROLE_PREFIX + " - "
-                                      + repoId + "] to Guest user.", e );
+                getLogger().warn(
+                                  "Unable to add role [" + 
ArchivaRoleConstants.REPOSITORY_OBSERVER_ROLE_PREFIX + " - "
+                                      + repoId + "] to " + principal + " 
user.", e );
             }
         }
     }

Modified: 
maven/archiva/trunk/archiva-web/archiva-webapp/src/main/resources/xwork.xml
URL: 
http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-web/archiva-webapp/src/main/resources/xwork.xml?rev=586622&r1=586621&r2=586622&view=diff
==============================================================================
--- maven/archiva/trunk/archiva-web/archiva-webapp/src/main/resources/xwork.xml 
(original)
+++ maven/archiva/trunk/archiva-web/archiva-webapp/src/main/resources/xwork.xml 
Fri Oct 19 14:46:08 2007
@@ -35,12 +35,10 @@
       <interceptor name="redbackSecureActions" 
class="redbackSecureActionInterceptor"/>
       <interceptor name="redbackAutoLogin" 
class="redbackAutoLoginInterceptor"/>
       <interceptor name="redbackPolicyEnforcement" 
class="redbackPolicyEnforcementInterceptor"/>
-      <interceptor name="redbackEnvironmentChecker" 
class="redbackEnvironmentCheckInterceptor"/>
       <interceptor name="paramFilter" 
class="com.opensymphony.xwork.interceptor.ParameterFilterInterceptor"/>
 
       <interceptor-stack name="configuredArchivaStack">
         <interceptor-ref name="redbackForceAdminUser"/>
-        <interceptor-ref name="redbackEnvironmentChecker"/>
         <interceptor-ref name="redbackAutoLogin"/>
         <interceptor-ref name="defaultStack"/>
         <interceptor-ref name="paramFilter">


Reply via email to