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