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.
39 public abstract class AbstractManagedRepositoriesAction
40 extends AbstractRepositoriesAdminAction
43 * @plexus.requirement role-hint="default"
45 protected RoleManager roleManager;
47 public static final String CONFIRM = "confirm";
49 public RoleManager getRoleManager()
54 public void setRoleManager( RoleManager roleManager )
56 this.roleManager = roleManager;
59 protected void addRepository( ManagedRepositoryConfiguration repository, Configuration configuration )
63 File file = new File( repository.getLocation() );
64 repository.setLocation( file.getCanonicalPath() );
69 if ( !file.exists() || !file.isDirectory() )
71 throw new IOException( "Unable to add repository - no write access, can not create the root directory: " + file );
74 configuration.addManagedRepository( repository );
78 protected void addRepositoryRoles( ManagedRepositoryConfiguration newRepository ) throws RoleManagerException
80 String repoId = newRepository.getId();
82 // TODO: double check these are configured on start up
83 // TODO: belongs in the business logic
85 if ( !roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, repoId ) )
87 roleManager.createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, repoId );
90 if ( !roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, repoId ) )
92 roleManager.createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, repoId );
96 protected void removeContents( ManagedRepositoryConfiguration existingRepository )
99 FileUtils.deleteDirectory( new File( existingRepository.getLocation() ) );
102 protected void removeRepository( String repoId, Configuration configuration )
104 ManagedRepositoryConfiguration toremove = configuration.findManagedRepositoryById( repoId );
105 if ( toremove != null )
107 configuration.removeManagedRepository( toremove );
111 protected void removeRepositoryRoles( ManagedRepositoryConfiguration existingRepository )
112 throws RoleManagerException
114 String repoId = existingRepository.getId();
116 if ( roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, repoId ) )
118 roleManager.removeTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, repoId );
121 if ( roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, repoId ) )
123 roleManager.removeTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, repoId );
126 getLogger().debug( "removed user roles associated with repository " + repoId );