1 package org.apache.archiva.redback.integration.checks.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 org.apache.archiva.redback.configuration.UserConfiguration;
23 import org.apache.archiva.redback.configuration.UserConfigurationKeys;
24 import org.apache.archiva.redback.policy.UserSecurityPolicy;
25 import org.apache.archiva.redback.role.RoleManagerException;
26 import org.apache.archiva.redback.users.User;
27 import org.apache.archiva.redback.users.UserManagerException;
28 import org.apache.archiva.redback.users.UserNotFoundException;
29 import org.apache.archiva.redback.role.RoleManager;
30 import org.apache.archiva.redback.system.SecuritySystem;
31 import org.apache.archiva.redback.system.check.EnvironmentCheck;
32 import org.apache.archiva.redback.users.UserManager;
33 import org.springframework.stereotype.Service;
35 import javax.inject.Inject;
36 import javax.inject.Named;
37 import java.util.List;
40 * RequiredRolesEnvironmentCheck:
42 * @author: Jesse McConnell <jesse@codehaus.org>
44 @Service("environmentCheck#guest-user-check")
45 public class GuestUserEnvironmentCheck
46 implements EnvironmentCheck
50 private RoleManager roleManager;
53 private SecuritySystem securitySystem;
56 @Named(value = "userConfiguration#default")
57 private UserConfiguration config;
60 * boolean detailing if this environment check has been executed
62 private boolean checked = false;
67 public void validateEnvironment( List<String> violations )
71 UserManager userManager = securitySystem.getUserManager();
72 UserSecurityPolicy policy = securitySystem.getPolicy();
77 guest = userManager.getGuestUser();
79 catch ( UserManagerException e )
81 policy.setEnabled( false );
84 guest = userManager.createGuestUser();
86 catch ( UserManagerException ume )
88 violations.add( "unable to initialize guest user properly: " + ume.getMessage() );
92 policy.setEnabled( true );
100 roleManager.assignRole( config.getString( UserConfigurationKeys.DEFAULT_GUEST_ROLE, "Guest" ),
101 guest.getUsername() );
103 catch ( RoleManagerException rpe )
105 violations.add( "unable to initialize guest user properly: " + rpe.getMessage() );
110 violations.add( "cannot find neither create guest user" );