001package org.apache.archiva.redback.integration.checks.security; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022import org.apache.archiva.redback.role.RoleManager; 023import org.apache.archiva.redback.role.RoleManagerException; 024import org.apache.archiva.redback.system.check.EnvironmentCheck; 025import org.slf4j.Logger; 026import org.slf4j.LoggerFactory; 027import org.springframework.stereotype.Service; 028 029import javax.inject.Inject; 030import java.util.List; 031 032/** 033 * RequiredRolesEnvironmentCheck: this environment check will check that the 034 * required roles of the redback-xwork-integration artifact exist to be 035 * assigned. 036 * 037 * @author: Jesse McConnell 038 * 039 */ 040@Service("environmentCheck#required-roles") 041public class RequiredRolesEnvironmentCheck 042 implements EnvironmentCheck 043{ 044 045 protected Logger log = LoggerFactory.getLogger( getClass() ); 046 047 @Inject 048 private RoleManager roleManager; 049 050 /** 051 * boolean detailing if this environment check has been executed 052 */ 053 private boolean checked = false; 054 055 /** 056 * @param violations 057 */ 058 public void validateEnvironment( List<String> violations ) 059 { 060 if ( !checked ) 061 { 062 log.info( "Checking the existence of required roles." ); 063 064 try 065 { 066 if ( !roleManager.roleExists( "registered-user" ) ) 067 { 068 violations.add( "unable to validate existence of the registered-user role" ); 069 } 070 071 if ( !roleManager.roleExists( "user-administrator" ) ) 072 { 073 violations.add( "unable to validate existence of the user-administator role" ); 074 } 075 076 if ( !roleManager.roleExists( "system-administrator" ) ) 077 { 078 violations.add( "unable to validate existence of the system-administrator role" ); 079 } 080 } 081 catch ( RoleManagerException e ) 082 { 083 violations.add( "unable to check required roles: " + e.getMessage() ); 084 } 085 086 checked = true; 087 } 088 } 089}