1 package org.apache.maven.archiva.security;
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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
22 import java.util.List;
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;
30 * ArchivaStandardRolesCheck tests for the existance of expected / standard roles and permissions.
34 * @plexus.component role="org.codehaus.plexus.redback.system.check.EnvironmentCheck"
35 * role-hint="required-roles"
37 public class ArchivaStandardRolesCheck
38 implements EnvironmentCheck
40 private Logger log = LoggerFactory.getLogger( ArchivaStandardRolesCheck.class );
43 * @plexus.requirement role-hint="cached"
45 private RBACManager rbacManager;
48 * boolean detailing if this environment check has been executed
50 private boolean checked = false;
52 @SuppressWarnings("unchecked")
53 public void validateEnvironment( List violations )
57 String expectedRoles[] = new String[] {
58 ArchivaRoleConstants.SYSTEM_ADMINISTRATOR_ROLE,
59 ArchivaRoleConstants.GLOBAL_REPOSITORY_MANAGER_ROLE,
60 ArchivaRoleConstants.GLOBAL_REPOSITORY_OBSERVER_ROLE,
61 ArchivaRoleConstants.GUEST_ROLE,
62 ArchivaRoleConstants.REGISTERED_USER_ROLE,
63 ArchivaRoleConstants.USER_ADMINISTRATOR_ROLE };
65 log.info( "Checking the existance of required roles." );
67 for ( String roleName : expectedRoles )
69 if ( !rbacManager.roleExists( roleName ) )
71 violations.add( "Unable to validate the existances of the '" + roleName + "' role." );
75 String expectedOperations[] = new String[] {
76 ArchivaRoleConstants.OPERATION_MANAGE_USERS,
77 ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION,
78 ArchivaRoleConstants.OPERATION_REGENERATE_INDEX,
79 ArchivaRoleConstants.OPERATION_RUN_INDEXER,
80 ArchivaRoleConstants.OPERATION_ACCESS_REPORT,
81 ArchivaRoleConstants.OPERATION_ADD_REPOSITORY,
82 ArchivaRoleConstants.OPERATION_DELETE_REPOSITORY,
83 ArchivaRoleConstants.OPERATION_REPOSITORY_ACCESS,
84 ArchivaRoleConstants.OPERATION_EDIT_REPOSITORY,
85 ArchivaRoleConstants.OPERATION_REPOSITORY_UPLOAD,
86 ArchivaRoleConstants.OPERATION_REPOSITORY_ACCESS,
89 log.info( "Checking the existance of required operations." );
91 for ( String operation : expectedOperations )
93 if ( !rbacManager.operationExists( operation ) )
95 violations.add( "Unable to validate the existances of the '" + operation + "' operation." );