1 package org.apache.maven.archiva.web.action.admin.repositories;
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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
22 import org.apache.commons.io.FileUtils;
23 import org.apache.maven.archiva.configuration.Configuration;
24 import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
25 import org.apache.maven.archiva.security.ArchivaRoleConstants;
26 import org.codehaus.plexus.redback.role.RoleManager;
27 import org.codehaus.plexus.redback.role.RoleManagerException;
30 import java.io.IOException;
33 * Abstract ManagedRepositories Action.
35 * Place for all generic methods used in Managed Repository Administration.
37 * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
40 public abstract class AbstractManagedRepositoriesAction
41 extends AbstractRepositoriesAdminAction
44 * @plexus.requirement role-hint="default"
46 protected RoleManager roleManager;
48 public RoleManager getRoleManager()
53 public void setRoleManager( RoleManager roleManager )
55 this.roleManager = roleManager;
58 protected void addRepository( ManagedRepositoryConfiguration repository, Configuration configuration )
62 File file = new File( repository.getLocation() );
63 repository.setLocation( file.getCanonicalPath() );
68 if ( !file.exists() || !file.isDirectory() )
70 throw new IOException( "unable to add repository - can not create the root directory: " + file );
73 configuration.addManagedRepository( repository );
77 protected void addRepositoryRoles( ManagedRepositoryConfiguration newRepository ) throws RoleManagerException
79 String repoId = newRepository.getId();
81 // TODO: double check these are configured on start up
82 // TODO: belongs in the business logic
84 if ( !roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, repoId ) )
86 roleManager.createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, repoId );
89 if ( !roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, repoId ) )
91 roleManager.createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, repoId );
95 protected void removeContents( ManagedRepositoryConfiguration existingRepository )
98 FileUtils.deleteDirectory( new File( existingRepository.getLocation() ) );
101 protected void removeRepository( String repoId, Configuration configuration )
103 ManagedRepositoryConfiguration toremove = configuration.findManagedRepositoryById( repoId );
104 if ( toremove != null )
106 configuration.removeManagedRepository( toremove );
110 protected void removeRepositoryRoles( ManagedRepositoryConfiguration existingRepository )
111 throws RoleManagerException
113 String repoId = existingRepository.getId();
115 if ( roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, repoId ) )
117 roleManager.removeTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, repoId );
120 if ( roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, repoId ) )
122 roleManager.removeTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, repoId );
125 getLogger().debug( "removed user roles associated with repository " + repoId );