1package org.apache.archiva.redback.integration.checks.security;
23/*4 * Licensed to the Apache Software Foundation (ASF) under one5 * or more contributor license agreements. See the NOTICE file6 * distributed with this work for additional information7 * regarding copyright ownership. The ASF licenses this file8 * to you under the Apache License, Version 2.0 (the9 * "License"); you may not use this file except in compliance10 * with the License. You may obtain a copy of the License at11 *12 * http://www.apache.org/licenses/LICENSE-2.013 *14 * Unless required by applicable law or agreed to in writing,15 * software distributed under the License is distributed on an16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY17 * KIND, either express or implied. See the License for the18 * specific language governing permissions and limitations19 * under the License.20 */2122import java.util.List;
2324import javax.inject.Inject;
2526import org.apache.archiva.redback.role.RoleManager;
27import org.apache.archiva.redback.role.RoleManagerException;
28import org.apache.archiva.redback.system.check.EnvironmentCheck;
29import org.slf4j.Logger;
30import org.slf4j.LoggerFactory;
31import org.springframework.stereotype.Service;
3233/**34 * RequiredRolesEnvironmentCheck: this environment check will check that the35 * required roles of the redback-xwork-integration artifact exist to be36 * assigned.37 *38 * @author: Jesse McConnell <jesse@codehaus.org>39 *40 */41 @Service("environmentCheck#required-roles")
42publicclassRequiredRolesEnvironmentCheck43implementsEnvironmentCheck44 {
4546protected Logger log = LoggerFactory.getLogger( getClass() );
4748 @Inject
49privateRoleManager roleManager;
5051/**52 * boolean detailing if this environment check has been executed53 */54privateboolean checked = false;
5556/**57 * @param violations58 */59publicvoid validateEnvironment( List<String> violations )
60 {
61if ( !checked )
62 {
63 log.info( "Checking the existence of required roles." );
6465try66 {
67if ( !roleManager.roleExists( "registered-user" ) )
68 {
69 violations.add( "unable to validate existence of the registered-user role" );
70 }
7172if ( !roleManager.roleExists( "user-administrator" ) )
73 {
74 violations.add( "unable to validate existence of the user-administator role" );
75 }
7677if ( !roleManager.roleExists( "system-administrator" ) )
78 {
79 violations.add( "unable to validate existence of the system-administrator role" );
80 }
81 }
82catch ( RoleManagerException e )
83 {
84 violations.add( "unable to check required roles: " + e.getMessage() );
85 }
8687 checked = true;
88 }
89 }
90 }