public static final String OPERATION_EDIT_REPOSITORY = "archiva-edit-repository";
public static final String OPERATION_REPOSITORY_UPLOAD = "archiva-upload-repository";
+
+ // Role templates
+ public static final String TEMPLATE_REPOSITORY_MANAGER = "archiva-repository-manager";
+ public static final String TEMPLATE_REPOSITORY_OBSERVER = "archiva-repository-observer";
}
import org.apache.commons.io.FileUtils;
import org.apache.maven.archiva.configuration.Configuration;
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
+import org.apache.maven.archiva.security.ArchivaRoleConstants;
+import org.codehaus.plexus.redback.rbac.RBACManager;
+import org.codehaus.plexus.redback.rbac.RbacManagerException;
+import org.codehaus.plexus.redback.rbac.UserAssignment;
import org.codehaus.plexus.redback.role.RoleManager;
import org.codehaus.plexus.redback.role.RoleManagerException;
* @plexus.requirement role-hint="default"
*/
protected RoleManager roleManager;
+
+ /**
+ * @plexus.requirement role-hint="cached"
+ */
+ protected RBACManager rbacManager;
public RoleManager getRoleManager()
{
protected void addRepositoryRoles( ManagedRepositoryConfiguration newRepository ) throws RoleManagerException
{
+ String repoId = newRepository.getId();
+
// TODO: double check these are configured on start up
// TODO: belongs in the business logic
- roleManager.createTemplatedRole( "archiva-repository-manager", newRepository.getId() );
- roleManager.createTemplatedRole( "archiva-repository-observer", newRepository.getId() );
+
+ if ( !roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, repoId ) )
+ {
+ roleManager.createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, repoId );
+ }
+
+ if ( !roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, repoId ) )
+ {
+ roleManager.createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, repoId );
+ }
+
+ try
+ {
+ UserAssignment ua = rbacManager.getUserAssignment( ArchivaRoleConstants.GUEST_ROLE );
+ ua.addRoleName( ArchivaRoleConstants.REPOSITORY_OBSERVER_ROLE_PREFIX + " - " + repoId );
+ rbacManager.saveUserAssignment( ua );
+ }
+ catch ( RbacManagerException e )
+ {
+ getLogger().warn( "Unable to add role [" + ArchivaRoleConstants.REPOSITORY_OBSERVER_ROLE_PREFIX + " - "
+ + repoId + "] to Guest user.", e );
+ }
}
protected void removeContents( ManagedRepositoryConfiguration existingRepository )
protected void removeRepositoryRoles( ManagedRepositoryConfiguration existingRepository )
throws RoleManagerException
{
- roleManager.removeTemplatedRole( "archiva-repository-manager", existingRepository.getId() );
- roleManager.removeTemplatedRole( "archiva-repository-observer", existingRepository.getId() );
+ String repoId = existingRepository.getId();
+
+ if ( roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, repoId ) )
+ {
+ roleManager.removeTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, repoId );
+ }
+
+ if ( roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, repoId ) )
+ {
+ roleManager.removeTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, repoId );
+ }
- getLogger().debug( "removed user roles associated with repository " + existingRepository.getId() );
+ getLogger().debug( "removed user roles associated with repository " + repoId );
}
}
+++ /dev/null
-package org.apache.maven.archiva.web.check;
-
-/*
- * 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.archiva.configuration.ArchivaConfiguration;
-import org.apache.maven.archiva.configuration.Configuration;
-import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
-import org.apache.maven.archiva.database.ArchivaDAO;
-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.List;
-
-/**
- * RoleExistanceEnvironmentCheck:
- * <p/>
- * Under certain circumstances it is possible that the user store and/or role store
- * have been wiped or reset and its important to see if there are repositories already
- * configured in archiva that need to reinitialized in terms of having their roles created.
- *
- * @author: Jesse McConnell <jmcconnell@apache.org>
- * @version: $ID:
- * @plexus.component role="org.codehaus.plexus.security.system.check.EnvironmentCheck"
- * role-hint="repository-role-check"
- */
-public class RoleExistanceEnvironmentCheck
- extends AbstractLogEnabled
- implements EnvironmentCheck
-{
- /**
- * @plexus.requirement role-hint="jdo"
- */
- private ArchivaDAO dao;
-
- /**
- * @plexus.requirement role-hint="default"
- */
- private RoleManager roleManager;
-
- /**
- * @plexus.requirement
- */
- private ArchivaConfiguration configuration;
-
- private boolean checked;
-
- public void validateEnvironment( List list )
- {
- if ( !checked )
- {
- try
- {
- Configuration config = configuration.getConfiguration();
- for ( ManagedRepositoryConfiguration repository : config.getManagedRepositoriesAsMap().values() )
- {
- if ( !roleManager.templatedRoleExists( "archiva-repository-manager", repository.getId() ) )
- {
- roleManager.createTemplatedRole( "archiva-repository-manager", repository.getId() );
- }
-
- if ( !roleManager.templatedRoleExists( "archiva-repository-observer", repository.getId() ) )
- {
- roleManager.createTemplatedRole( "archiva-repository-observer", repository.getId() );
- }
- }
- }
- catch ( RoleManagerException rpe )
- {
- list.add( this.getClass().getName() + "error initializing roles: " + rpe.getMessage() );
- getLogger().info( "error initializing roles", rpe );
- }
-
- checked = true;
- }
- }
-
-}
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
import org.apache.maven.archiva.configuration.ConfigurationNames;
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
+import org.apache.maven.archiva.security.ArchivaRoleConstants;
import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.codehaus.plexus.redback.role.RoleManager;
import org.codehaus.plexus.redback.role.RoleManagerException;
private void synchConfiguration( List<ManagedRepositoryConfiguration> repos )
{
+ // NOTE: Remote Repositories do not have roles or security placed around them.
+
for ( ManagedRepositoryConfiguration repoConfig : repos )
{
// manage roles for repositories
try
{
- if ( !roleManager.templatedRoleExists( "archiva-repository-observer", repoConfig.getId() ) )
+ if ( !roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER,
+ repoConfig.getId() ) )
{
- roleManager.createTemplatedRole( "archiva-repository-observer", repoConfig.getId() );
+ roleManager.createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER,
+ repoConfig.getId() );
}
- if ( !roleManager.templatedRoleExists( "archiva-repository-manager", repoConfig.getId() ) )
+ if ( !roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER,
+ repoConfig.getId() ) )
{
- roleManager.createTemplatedRole( "archiva-repository-manager", repoConfig.getId() );
+ roleManager.createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER,
+ repoConfig.getId() );
}
}
catch ( RoleManagerException e )
// Log error.
getLogger().error( "Unable to create roles for configured repositories: " + e.getMessage(), e );
}
-
}
}
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
import org.apache.maven.archiva.configuration.Configuration;
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
+import org.apache.maven.archiva.security.ArchivaRoleConstants;
import org.codehaus.plexus.PlexusTestCase;
import org.codehaus.plexus.redback.role.RoleManager;
import org.codehaus.plexus.redback.xwork.interceptor.SecureActionBundle;
{
FileUtils.deleteDirectory( location );
- // TODO: should be in the business model
- roleManager.createTemplatedRole( "archiva-repository-manager", REPO_ID );
- roleManager.createTemplatedRole( "archiva-repository-observer", REPO_ID );
+ roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, REPO_ID );
+ roleManagerControl.setReturnValue( false );
+ roleManager.createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, REPO_ID );
+ roleManagerControl.setVoidCallable();
+ roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, REPO_ID );
+ roleManagerControl.setReturnValue( false );
+ roleManager.createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, REPO_ID );
+ roleManagerControl.setVoidCallable();
roleManagerControl.replay();
import org.apache.maven.archiva.configuration.Configuration;
import org.apache.maven.archiva.configuration.IndeterminateConfigurationException;
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
+import org.apache.maven.archiva.security.ArchivaRoleConstants;
import org.codehaus.plexus.PlexusTestCase;
import org.codehaus.plexus.redback.role.RoleManager;
+import org.codehaus.plexus.redback.role.RoleManagerException;
import org.codehaus.plexus.redback.xwork.interceptor.SecureActionBundle;
import org.codehaus.plexus.redback.xwork.interceptor.SecureActionException;
import org.codehaus.plexus.registry.RegistryException;
}
public void testDeleteRepositoryKeepContent()
- throws RegistryException, IndeterminateConfigurationException
+ throws Exception
{
+ prepareRoleManagerMock();
+
Configuration configuration = prepDeletionTest( createRepository(), "delete-entry" );
String status = action.deleteEntry();
assertEquals( Action.SUCCESS, status );
}
public void testDeleteRepositoryDeleteContent()
- throws RegistryException, IndeterminateConfigurationException
+ throws Exception
{
+ prepareRoleManagerMock();
+
Configuration configuration = prepDeletionTest( createRepository(), "delete-contents" );
String status = action.deleteContents();
assertEquals( Action.SUCCESS, status );
repository.setDeleteReleasedSnapshots( true );
}
+ private void prepareRoleManagerMock()
+ throws RoleManagerException
+ {
+ roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, REPO_ID );
+ roleManagerControl.setReturnValue( true );
+ roleManager.removeTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, REPO_ID );
+ roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, REPO_ID );
+ roleManagerControl.setReturnValue( true );
+ roleManager.removeTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, REPO_ID );
+ roleManagerControl.replay();
+ }
}
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
import org.apache.maven.archiva.configuration.Configuration;
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
+import org.apache.maven.archiva.security.ArchivaRoleConstants;
import org.codehaus.plexus.PlexusTestCase;
import org.codehaus.plexus.redback.role.RoleManager;
import org.codehaus.plexus.redback.xwork.interceptor.SecureActionBundle;
public void testEditRepository()
throws Exception
{
- // TODO: should be in the business model
- roleManager.createTemplatedRole( "archiva-repository-manager", REPO_ID );
- roleManager.createTemplatedRole( "archiva-repository-observer", REPO_ID );
+ roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, REPO_ID );
+ roleManagerControl.setReturnValue( false );
+ roleManager.createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, REPO_ID );
+ roleManagerControl.setVoidCallable();
+ roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, REPO_ID );
+ roleManagerControl.setReturnValue( false );
+ roleManager.createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, REPO_ID );
+ roleManagerControl.setVoidCallable();
roleManagerControl.replay();