Coverage Report - org.apache.maven.archiva.security.ArchivaStandardRolesCheck
 
Classes in this File Line Coverage Branch Coverage Complexity
ArchivaStandardRolesCheck
0%
0/16
0%
0/10
0
 
 1  
 package org.apache.maven.archiva.security;
 2  
 
 3  
 /*
 4  
  * Licensed to the Apache Software Foundation (ASF) under one
 5  
  * or more contributor license agreements.  See the NOTICE file
 6  
  * distributed with this work for additional information
 7  
  * regarding copyright ownership.  The ASF licenses this file
 8  
  * to you under the Apache License, Version 2.0 (the
 9  
  * "License"); you may not use this file except in compliance
 10  
  * with the License.  You may obtain a copy of the License at
 11  
  *
 12  
  *  http://www.apache.org/licenses/LICENSE-2.0
 13  
  *
 14  
  * Unless required by applicable law or agreed to in writing,
 15  
  * software distributed under the License is distributed on an
 16  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 17  
  * KIND, either express or implied.  See the License for the
 18  
  * specific language governing permissions and limitations
 19  
  * under the License.
 20  
  */
 21  
 
 22  
 import java.util.List;
 23  
 
 24  
 import org.codehaus.plexus.redback.rbac.RBACManager;
 25  
 import org.codehaus.plexus.redback.system.check.EnvironmentCheck;
 26  
 import org.slf4j.Logger;
 27  
 import org.slf4j.LoggerFactory;
 28  
 
 29  
 /**
 30  
  * ArchivaStandardRolesCheck tests for the existance of expected / standard roles and permissions. 
 31  
  *
 32  
  * @version $Id: ArchivaStandardRolesCheck.java 750975 2009-03-06 16:54:34Z brett $
 33  
  * 
 34  
  * @plexus.component role="org.codehaus.plexus.redback.system.check.EnvironmentCheck"
 35  
  *                   role-hint="required-roles"
 36  
  */
 37  0
 public class ArchivaStandardRolesCheck
 38  
     implements EnvironmentCheck
 39  
 {
 40  0
     private Logger log = LoggerFactory.getLogger( ArchivaStandardRolesCheck.class );
 41  
     
 42  
     /**
 43  
      * @plexus.requirement role-hint="cached"
 44  
      */
 45  
     private RBACManager rbacManager;
 46  
 
 47  
     /**
 48  
      * boolean detailing if this environment check has been executed
 49  
      */
 50  0
     private boolean checked = false;
 51  
 
 52  
     public void validateEnvironment( List<String> violations )
 53  
     {
 54  0
         if ( !checked )
 55  
         {
 56  0
             String expectedRoles[] = new String[] {
 57  
                 ArchivaRoleConstants.SYSTEM_ADMINISTRATOR_ROLE,
 58  
                 ArchivaRoleConstants.GLOBAL_REPOSITORY_MANAGER_ROLE,
 59  
                 ArchivaRoleConstants.GLOBAL_REPOSITORY_OBSERVER_ROLE,
 60  
                 ArchivaRoleConstants.GUEST_ROLE,
 61  
                 ArchivaRoleConstants.REGISTERED_USER_ROLE,
 62  
                 ArchivaRoleConstants.USER_ADMINISTRATOR_ROLE };
 63  
 
 64  0
             log.info( "Checking the existance of required roles." );
 65  
 
 66  0
             for ( String roleName : expectedRoles )
 67  
             {
 68  0
                 if ( !rbacManager.roleExists( roleName ) )
 69  
                 {
 70  0
                     violations.add( "Unable to validate the existances of the '" + roleName + "' role." );
 71  
                 }
 72  
             }
 73  
 
 74  0
             String expectedOperations[] = new String[] {
 75  
                 ArchivaRoleConstants.OPERATION_MANAGE_USERS,
 76  
                 ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION,
 77  
                 ArchivaRoleConstants.OPERATION_REGENERATE_INDEX,
 78  
                 ArchivaRoleConstants.OPERATION_RUN_INDEXER,
 79  
                 ArchivaRoleConstants.OPERATION_ACCESS_REPORT,
 80  
                 ArchivaRoleConstants.OPERATION_ADD_REPOSITORY,
 81  
                 ArchivaRoleConstants.OPERATION_DELETE_REPOSITORY,
 82  
                 ArchivaRoleConstants.OPERATION_REPOSITORY_ACCESS,
 83  
                 ArchivaRoleConstants.OPERATION_EDIT_REPOSITORY,
 84  
                 ArchivaRoleConstants.OPERATION_REPOSITORY_UPLOAD,
 85  
                 ArchivaRoleConstants.OPERATION_REPOSITORY_ACCESS,
 86  
                 "archiva-guest" };
 87  
 
 88  0
             log.info( "Checking the existance of required operations." );
 89  
 
 90  0
             for ( String operation : expectedOperations )
 91  
             {
 92  0
                 if ( !rbacManager.operationExists( operation ) )
 93  
                 {
 94  0
                     violations.add( "Unable to validate the existances of the '" + operation + "' operation." );
 95  
                 }
 96  
             }
 97  
 
 98  0
             checked = true;
 99  
         }
 100  
 
 101  0
     }
 102  
 
 103  
 }