1 package org.apache.maven.archiva.web.action.admin;
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.maven.archiva.configuration.AbstractRepositoryConfiguration;
23 import org.apache.maven.archiva.configuration.ArchivaConfiguration;
24 import org.apache.maven.archiva.configuration.Configuration;
25 import org.apache.maven.archiva.configuration.InvalidConfigurationException;
26 import org.apache.maven.archiva.security.ArchivaRoleConstants;
27 import org.codehaus.plexus.rbac.profile.RoleProfileManager;
28 import org.codehaus.plexus.registry.RegistryException;
29 import org.codehaus.plexus.security.rbac.Resource;
30 import org.codehaus.plexus.security.ui.web.interceptor.SecureAction;
31 import org.codehaus.plexus.security.ui.web.interceptor.SecureActionBundle;
32 import org.codehaus.plexus.security.ui.web.interceptor.SecureActionException;
33 import org.codehaus.plexus.xwork.action.PlexusActionSupport;
35 import java.io.IOException;
38 * Base action for repository removal actions.
40 * @author <a href="mailto:brett@apache.org">Brett Porter</a>
42 public abstract class AbstractDeleteRepositoryAction
43 extends PlexusActionSupport
44 implements SecureAction
49 private ArchivaConfiguration archivaConfiguration;
52 * The repository ID to lookup when editing a repository.
54 protected String repoId;
57 * Which operation to select.
59 private String operation = "unmodified";
62 * @plexus.requirement role-hint="archiva"
64 protected RoleProfileManager roleProfileManager;
66 public String execute()
67 throws IOException, InvalidConfigurationException, RegistryException
69 // TODO: if this didn't come from the form, go to configure.action instead of going through with re-saving what was just loaded
71 if ( "delete-entry".equals( operation ) || "delete-contents".equals( operation ) )
73 Configuration configuration = archivaConfiguration.getConfiguration();
75 AbstractRepositoryConfiguration existingRepository = getRepository( configuration );
76 if ( existingRepository == null )
78 addActionError( "A repository with that id does not exist" );
82 // TODO: remove from index too!
84 removeRepository( configuration, existingRepository );
86 archivaConfiguration.save( configuration );
88 if ( "delete-contents".equals( operation ) )
90 removeContents( existingRepository );
97 protected abstract void removeContents( AbstractRepositoryConfiguration existingRepository )
100 protected abstract AbstractRepositoryConfiguration getRepository( Configuration configuration );
102 protected abstract void removeRepository( Configuration configuration,
103 AbstractRepositoryConfiguration existingRepository );
105 public String input()
110 public String getRepoId()
115 public void setRepoId( String repoId )
117 this.repoId = repoId;
120 public String getOperation()
125 public void setOperation( String operation )
127 this.operation = operation;
130 public SecureActionBundle getSecureActionBundle()
131 throws SecureActionException
133 SecureActionBundle bundle = new SecureActionBundle();
135 bundle.setRequiresAuthentication( true );
137 if ( getRepoId() != null )
139 // TODO: not right. We only care about this permission on managed repositories. Otherwise, it's configuration
140 bundle.addRequiredAuthorization( ArchivaRoleConstants.OPERATION_DELETE_REPOSITORY, getRepoId() );
144 bundle.addRequiredAuthorization( ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION, Resource.GLOBAL );