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.rbac.RbacManagerException;
23 import org.apache.archiva.redback.system.check.EnvironmentCheck;
24 import org.apache.archiva.redback.users.UserNotFoundException;
25 import org.apache.archiva.redback.rbac.RBACManager;
26 import org.apache.archiva.redback.rbac.UserAssignment;
27 import org.apache.archiva.redback.users.User;
28 import org.apache.archiva.redback.users.UserManager;
29 import org.apache.archiva.redback.integration.role.RoleConstants;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32 import org.springframework.stereotype.Service;
34 import javax.inject.Inject;
35 import javax.inject.Named;
36 import java.util.ArrayList;
37 import java.util.List;
40 * LockedAdminEnvironmentCheck: checks if accounts marked as system administrator are locked
41 * and unlocks them on startup.
43 * @author: Jesse McConnell <jesse@codehaus.org>
46 @Service( "environmentCheck#locked-admin-check" )
47 public class LockedAdminEnvironmentCheck
48 implements EnvironmentCheck
51 protected Logger log = LoggerFactory.getLogger( getClass() );
54 @Named( value = "userManager#configurable" )
55 private UserManager userManager;
58 @Named( value = "rBACManager#cached" )
59 private RBACManager rbacManager;
62 * boolean detailing if this environment check has been executed
64 private boolean checked = false;
67 * This environment check will unlock system administrator accounts that are locked on the restart of the
68 * application when the environment checks are processed.
72 public void validateEnvironment( List<String> violations )
74 if ( !checked && !userManager.isReadOnly() )
76 List<String> roles = new ArrayList<String>();
77 roles.add( RoleConstants.SYSTEM_ADMINISTRATOR_ROLE );
79 List<UserAssignment> systemAdminstrators;
82 systemAdminstrators = rbacManager.getUserAssignmentsForRoles( roles );
84 for ( UserAssignment userAssignment : systemAdminstrators )
88 User admin = userManager.findUser( userAssignment.getPrincipal() );
90 if ( admin.isLocked() )
92 log.info( "Unlocking system administrator: {}", admin.getUsername() );
93 admin.setLocked( false );
94 userManager.updateUser( admin );
97 catch ( UserNotFoundException ne )
99 log.warn( "Dangling UserAssignment -> {}", userAssignment.getPrincipal() );
103 catch ( RbacManagerException e )
105 log.warn( "Exception when checking for locked admin user: " + e.getMessage(), e );