View Javadoc

1   package org.apache.maven.continuum.web.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 org.apache.maven.continuum.Continuum;
23  import org.apache.maven.continuum.model.project.ProjectGroup;
24  import org.codehaus.plexus.redback.role.RoleManager;
25  import org.codehaus.plexus.redback.role.RoleManagerException;
26  import org.codehaus.plexus.redback.system.check.EnvironmentCheck;
27  import org.slf4j.Logger;
28  import org.slf4j.LoggerFactory;
29  
30  import java.util.Collection;
31  import java.util.List;
32  
33  /**
34   * RoleProfileEnvironmentCheck:
35   *
36   * @author: Jesse McConnell <jmcconnell@apache.org>
37   * @version: $Id: RoleProfileEnvironmentCheck.java 1372260 2012-08-13 04:29:09Z brett $
38   * @plexus.component role="org.codehaus.plexus.redback.system.check.EnvironmentCheck"
39   * role-hint="continuum-role-profile-check"
40   */
41  public class RoleProfileEnvironmentCheck
42      implements EnvironmentCheck
43  {
44      private static final Logger log = LoggerFactory.getLogger( RoleProfileEnvironmentCheck.class );
45  
46      /**
47       * @plexus.requirement role-hint="default"
48       */
49      private RoleManager roleManager;
50  
51      /**
52       * @plexus.requirement
53       */
54      private Continuum continuum;
55  
56      public void validateEnvironment( List list )
57      {
58          try
59          {
60              log.info( "Checking roles list." );
61  
62              Collection<ProjectGroup> projectGroups = continuum.getAllProjectGroups();
63  
64              for ( ProjectGroup group : projectGroups )
65              {
66                  // gets the role, making it if it doesn't exist
67                  //TODO: use continuum.executeAction( "add-assignable-roles", context ); or something like that to avoid code duplication
68                  if ( !roleManager.templatedRoleExists( "project-administrator", group.getName() ) )
69                  {
70                      roleManager.createTemplatedRole( "project-administrator", group.getName() );
71                  }
72                  if ( !roleManager.templatedRoleExists( "project-developer", group.getName() ) )
73                  {
74                      roleManager.createTemplatedRole( "project-developer", group.getName() );
75                  }
76  
77                  if ( !roleManager.templatedRoleExists( "project-user", group.getName() ) )
78                  {
79                      roleManager.createTemplatedRole( "project-user", group.getName() );
80                  }
81              }
82  
83          }
84          catch ( RoleManagerException rpe )
85          {
86              rpe.printStackTrace();
87              list.add( "error checking existence of roles for groups" );
88          }
89      }
90  }