]> source.dussan.org Git - archiva.git/blob
b5f792092caa2e51b2f83dbfa1c95c710188b7e9
[archiva.git] /
1 package org.apache.maven.archiva.web.action.admin;
2
3 /*
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
11  *
12  *   http://www.apache.org/licenses/LICENSE-2.0
13  *
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
19  * under the License.
20  */
21
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;
34
35 import java.io.IOException;
36
37 /**
38  * Base action for repository removal actions.
39  *
40  * @author <a href="mailto:brett@apache.org">Brett Porter</a>
41  */
42 public abstract class AbstractDeleteRepositoryAction
43     extends PlexusActionSupport
44     implements SecureAction
45 {
46     /**
47      * @plexus.requirement
48      */
49     private ArchivaConfiguration archivaConfiguration;
50
51     /**
52      * The repository ID to lookup when editing a repository.
53      */
54     protected String repoId;
55
56     /**
57      * Which operation to select.
58      */
59     private String operation = "unmodified";
60
61     /**
62      * @plexus.requirement role-hint="archiva"
63      */
64     protected RoleProfileManager roleProfileManager;
65
66     public String execute()
67         throws IOException, InvalidConfigurationException, RegistryException
68     {
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
70
71         if ( "delete-entry".equals( operation ) || "delete-contents".equals( operation ) )
72         {
73             Configuration configuration = archivaConfiguration.getConfiguration();
74
75             AbstractRepositoryConfiguration existingRepository = getRepository( configuration );
76             if ( existingRepository == null )
77             {
78                 addActionError( "A repository with that id does not exist" );
79                 return ERROR;
80             }
81
82             // TODO: remove from index too!
83
84             removeRepository( configuration, existingRepository );
85
86             archivaConfiguration.save( configuration );
87
88             if ( "delete-contents".equals( operation ) )
89             {
90                 removeContents( existingRepository );
91             }
92         }
93
94         return SUCCESS;
95     }
96
97     protected abstract void removeContents( AbstractRepositoryConfiguration existingRepository )
98         throws IOException;
99
100     protected abstract AbstractRepositoryConfiguration getRepository( Configuration configuration );
101
102     protected abstract void removeRepository( Configuration configuration,
103                                               AbstractRepositoryConfiguration existingRepository );
104
105     public String input()
106     {
107         return INPUT;
108     }
109
110     public String getRepoId()
111     {
112         return repoId;
113     }
114
115     public void setRepoId( String repoId )
116     {
117         this.repoId = repoId;
118     }
119
120     public String getOperation()
121     {
122         return operation;
123     }
124
125     public void setOperation( String operation )
126     {
127         this.operation = operation;
128     }
129
130     public SecureActionBundle getSecureActionBundle()
131         throws SecureActionException
132     {
133         SecureActionBundle bundle = new SecureActionBundle();
134
135         bundle.setRequiresAuthentication( true );
136
137         if ( getRepoId() != null )
138         {
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() );
141         }
142         else
143         {
144             bundle.addRequiredAuthorization( ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION, Resource.GLOBAL );
145         }
146
147         return bundle;
148     }
149
150 }