This project has retired. For details please refer to its Attic page.
RequiredRolesEnvironmentCheck xref
View Javadoc

1   package org.apache.archiva.redback.integration.checks.security;
2   
3   /*
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
11   *
12   * http://www.apache.org/licenses/LICENSE-2.0
13   *
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
19   * under the License.
20   */
21  
22  import java.util.List;
23  
24  import javax.inject.Inject;
25  
26  import org.apache.archiva.redback.role.RoleManager;
27  import org.apache.archiva.redback.role.RoleManagerException;
28  import org.apache.archiva.redback.system.check.EnvironmentCheck;
29  import org.slf4j.Logger;
30  import org.slf4j.LoggerFactory;
31  import org.springframework.stereotype.Service;
32  
33  /**
34   * RequiredRolesEnvironmentCheck: this environment check will check that the
35   * required roles of the redback-xwork-integration artifact exist to be
36   * assigned.
37   *
38   * @author: Jesse McConnell <jesse@codehaus.org>
39   *
40   */
41  @Service("environmentCheck#required-roles")
42  public class RequiredRolesEnvironmentCheck
43      implements EnvironmentCheck
44  {
45  
46      protected Logger log = LoggerFactory.getLogger( getClass() );
47      
48      @Inject
49      private RoleManager roleManager;
50  
51      /**
52       * boolean detailing if this environment check has been executed
53       */
54      private boolean checked = false;
55  
56      /**
57       * @param violations
58       */
59      public void validateEnvironment( List<String> violations )
60      {
61          if ( !checked )
62          {
63              log.info( "Checking the existence of required roles." );
64  
65              try
66              {
67                  if ( !roleManager.roleExists( "registered-user" ) )
68                  {
69                      violations.add( "unable to validate existence of the registered-user role" );
70                  }
71  
72                  if ( !roleManager.roleExists( "user-administrator" ) )
73                  {
74                      violations.add( "unable to validate existence of the user-administator role" );
75                  }
76  
77                  if ( !roleManager.roleExists( "system-administrator" ) )
78                  {
79                      violations.add( "unable to validate existence of the system-administrator role" );
80                  }
81              }
82              catch ( RoleManagerException e )
83              {
84                  violations.add( "unable to check required roles: " + e.getMessage() );
85              }
86  
87              checked = true;
88          }
89      }
90  }