1 package org.apache.maven.archiva.web.action.admin;
4 * Copyright 2005-2006 The Apache Software Foundation.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
19 import org.apache.maven.archiva.configuration.AbstractRepositoryConfiguration;
20 import org.apache.maven.archiva.configuration.Configuration;
21 import org.apache.maven.archiva.configuration.ConfigurationChangeException;
22 import org.apache.maven.archiva.configuration.ConfigurationStore;
23 import org.apache.maven.archiva.configuration.ConfigurationStoreException;
24 import org.apache.maven.archiva.configuration.InvalidConfigurationException;
25 import org.apache.maven.archiva.security.ArchivaRoleConstants;
26 import org.codehaus.plexus.security.rbac.Resource;
27 import org.codehaus.plexus.security.ui.web.interceptor.SecureAction;
28 import org.codehaus.plexus.security.ui.web.interceptor.SecureActionBundle;
29 import org.codehaus.plexus.security.ui.web.interceptor.SecureActionException;
30 import org.codehaus.plexus.xwork.action.PlexusActionSupport;
31 import org.codehaus.plexus.rbac.profile.RoleProfileManager;
32 import org.codehaus.plexus.rbac.profile.RoleProfileException;
34 import java.io.IOException;
37 * Base action for repository removal actions.
39 * @author <a href="mailto:brett@apache.org">Brett Porter</a>
41 public abstract class AbstractDeleteRepositoryAction
42 extends PlexusActionSupport
43 implements SecureAction
48 private ConfigurationStore configurationStore;
51 * The repository ID to lookup when editing a repository.
53 protected String repoId;
56 * Which operation to select.
58 private String operation = "unmodified";
61 * @plexus.requirement role-hint="archiva"
63 protected RoleProfileManager roleProfileManager;
64 public String execute()
65 throws ConfigurationStoreException, IOException, InvalidConfigurationException, ConfigurationChangeException
67 // TODO: if this didn't come from the form, go to configure.action instead of going through with re-saving what was just loaded
69 if ( "delete-entry".equals( operation ) || "delete-contents".equals( operation ) )
71 Configuration configuration = configurationStore.getConfigurationFromStore();
73 AbstractRepositoryConfiguration existingRepository = getRepository( configuration );
74 if ( existingRepository == null )
76 addActionError( "A repository with that id does not exist" );
80 // TODO: remove from index too!
82 removeRepository( configuration, existingRepository );
84 configurationStore.storeConfiguration( configuration );
86 if ( "delete-contents".equals( operation ) )
88 removeContents( existingRepository );
95 protected abstract void removeContents( AbstractRepositoryConfiguration existingRepository )
98 protected abstract AbstractRepositoryConfiguration getRepository( Configuration configuration );
100 protected abstract void removeRepository( Configuration configuration,
101 AbstractRepositoryConfiguration existingRepository );
103 public String input()
108 public String getRepoId()
113 public void setRepoId( String repoId )
115 this.repoId = repoId;
118 public String getOperation()
123 public void setOperation( String operation )
125 this.operation = operation;
128 public SecureActionBundle getSecureActionBundle()
129 throws SecureActionException
131 SecureActionBundle bundle = new SecureActionBundle();
133 bundle.setRequiresAuthentication( true );
135 if ( getRepoId() != null )
137 // TODO: not right. We only care about this permission on managed repositories. Otherwise, it's configuration
138 bundle.addRequiredAuthorization( ArchivaRoleConstants.OPERATION_DELETE_REPOSITORY, getRepoId() );
142 bundle.addRequiredAuthorization( ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION, Resource.GLOBAL );