| 1 | |
package org.apache.maven.archiva.security; |
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 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 | |
|
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | 0 | public class ArchivaStandardRolesCheck |
| 38 | |
implements EnvironmentCheck |
| 39 | |
{ |
| 40 | 0 | private Logger log = LoggerFactory.getLogger( ArchivaStandardRolesCheck.class ); |
| 41 | |
|
| 42 | |
|
| 43 | |
|
| 44 | |
|
| 45 | |
private RBACManager rbacManager; |
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 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 | |
} |