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