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 static final String CONFIRM = "confirm";
50 public RoleManager getRoleManager()
55 public void setRoleManager( RoleManager roleManager )
57 this.roleManager = roleManager;
60 protected void addRepository( ManagedRepositoryConfiguration repository, Configuration configuration )
64 File file = new File( repository.getLocation() );
65 repository.setLocation( file.getCanonicalPath() );
70 if ( !file.exists() || !file.isDirectory() )
72 throw new IOException( "unable to add repository - can not create the root directory: " + file );
75 configuration.addManagedRepository( repository );
79 protected void addRepositoryRoles( ManagedRepositoryConfiguration newRepository ) throws RoleManagerException
81 String repoId = newRepository.getId();
83 // TODO: double check these are configured on start up
84 // TODO: belongs in the business logic
86 if ( !roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, repoId ) )
88 roleManager.createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, repoId );
91 if ( !roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, repoId ) )
93 roleManager.createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, repoId );
97 protected void removeContents( ManagedRepositoryConfiguration existingRepository )
100 FileUtils.deleteDirectory( new File( existingRepository.getLocation() ) );
103 protected void removeRepository( String repoId, Configuration configuration )
105 ManagedRepositoryConfiguration toremove = configuration.findManagedRepositoryById( repoId );
106 if ( toremove != null )
108 configuration.removeManagedRepository( toremove );
112 protected void removeRepositoryRoles( ManagedRepositoryConfiguration existingRepository )
113 throws RoleManagerException
115 String repoId = existingRepository.getId();
117 if ( roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, repoId ) )
119 roleManager.removeTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, repoId );
122 if ( roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, repoId ) )
124 roleManager.removeTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, repoId );
127 getLogger().debug( "removed user roles associated with repository " + repoId );