package org.apache.maven.continuum.web.checks.security;

/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

import org.apache.maven.continuum.Continuum;
import org.apache.maven.continuum.model.project.ProjectGroup;
import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.codehaus.plexus.redback.role.RoleManager;
import org.codehaus.plexus.redback.role.RoleManagerException;
import org.codehaus.plexus.redback.system.check.EnvironmentCheck;

import java.util.Collection;
import java.util.Iterator;
import java.util.List;

/**
 * RoleProfileEnvironmentCheck:
 *
 * @author: Jesse McConnell <jmcconnell@apache.org>
 * @version: $ID:$
 * @plexus.component role="org.codehaus.plexus.security.system.check.EnvironmentCheck"
 * role-hint="continuum-role-profile-check"
 */
public class RoleProfileEnvironmentCheck
    extends AbstractLogEnabled
    implements EnvironmentCheck
{
    /**
     * @plexus.requirement role-hint="default"
     */
    private RoleManager roleManager;

    /**
     * @plexus.requirement
     */
    private Continuum continuum;

    public void validateEnvironment( List list )
    {
        try
        {
            Collection projectGroups = continuum.getAllProjectGroups();

            for ( Iterator i = projectGroups.iterator(); i.hasNext(); )
            {
                ProjectGroup group = (ProjectGroup) i.next();

                // gets the role, making it if it doesn't exist
                //TODO: use continuum.executeAction( "add-assignable-roles", context ); or something like that to avoid code duplication
                if ( !roleManager.templatedRoleExists( "project-administrator", group.getName() ) )
                {
                    roleManager.createTemplatedRole( "project-administrator", group.getName() );
                }
                if ( !roleManager.templatedRoleExists( "project-developer", group.getName() ) )
                {
                    roleManager.createTemplatedRole( "project-developer", group.getName() );
                }

                if ( !roleManager.templatedRoleExists( "project-user", group.getName() ) )
                {
                    roleManager.createTemplatedRole( "project-user", group.getName() );
                }
            }

        }
        catch ( RoleManagerException rpe )
        {
            rpe.printStackTrace();
            list.add( "error checking existence of roles for groups" );
        }
    }
}

@@ -1440,24 +1440,23 @@
 .plexus.
-security
+redback
 .system.
@@ -1880,32 +1880,89 @@
   try%0A        %7B%0A
+            getLogger().info( %22Checking roles list.%22 );%0A%0A
             Coll

Fix plexus role for redback environment check