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 com.opensymphony.xwork.ModelDriven;
20 import com.opensymphony.xwork.Preparable;
21 import org.apache.maven.archiva.configuration.AbstractRepositoryConfiguration;
22 import org.apache.maven.archiva.configuration.Configuration;
23 import org.apache.maven.archiva.configuration.ConfigurationChangeException;
24 import org.apache.maven.archiva.configuration.ConfigurationStore;
25 import org.apache.maven.archiva.configuration.ConfigurationStoreException;
26 import org.apache.maven.archiva.configuration.InvalidConfigurationException;
27 import org.apache.maven.archiva.security.ArchivaRoleConstants;
28 import org.codehaus.plexus.rbac.profile.RoleProfileException;
29 import org.codehaus.plexus.rbac.profile.RoleProfileManager;
30 import org.codehaus.plexus.security.rbac.RbacManagerException;
31 import org.codehaus.plexus.security.rbac.Resource;
32 import org.codehaus.plexus.security.ui.web.interceptor.SecureAction;
33 import org.codehaus.plexus.security.ui.web.interceptor.SecureActionBundle;
34 import org.codehaus.plexus.security.ui.web.interceptor.SecureActionException;
35 import org.codehaus.plexus.xwork.action.PlexusActionSupport;
37 import java.io.IOException;
40 * Base action for repository configuration actions.
42 * @author <a href="mailto:brett@apache.org">Brett Porter</a>
44 public abstract class AbstractConfigureRepositoryAction
45 extends PlexusActionSupport
46 implements ModelDriven, Preparable, SecureAction
51 private ConfigurationStore configurationStore;
54 * @plexus.requirement role-hint="archiva"
56 protected RoleProfileManager roleProfileManager;
61 private AbstractRepositoryConfiguration repository;
64 * The repository ID to lookup when editing a repository.
66 private String repoId;
69 * The previously read configuration.
71 protected Configuration configuration;
74 throws IOException, ConfigurationStoreException, InvalidConfigurationException, ConfigurationChangeException,
75 RbacManagerException, RoleProfileException
77 // TODO: if this didn't come from the form, go to configure.action instead of going through with re-saving what was just loaded
79 AbstractRepositoryConfiguration existingRepository = getRepository( repository.getId() );
80 if ( existingRepository != null )
82 addFieldError( "id", "A repository with that id already exists" );
86 return saveConfiguration();
90 throws IOException, ConfigurationStoreException, InvalidConfigurationException, ConfigurationChangeException,
91 RbacManagerException, RoleProfileException
93 // TODO: if this didn't come from the form, go to configure.action instead of going through with re-saving what was just loaded
95 AbstractRepositoryConfiguration existingRepository = getRepository( repository.getId() );
96 removeRepository( existingRepository );
98 return saveConfiguration();
101 protected abstract void removeRepository( AbstractRepositoryConfiguration existingRepository );
103 protected abstract AbstractRepositoryConfiguration getRepository( String id );
105 private String saveConfiguration()
106 throws IOException, ConfigurationStoreException, InvalidConfigurationException, ConfigurationChangeException,
107 RbacManagerException, RoleProfileException
111 configurationStore.storeConfiguration( configuration );
113 // TODO: do we need to check if indexing is needed?
115 addActionMessage( "Successfully saved configuration" );
120 protected abstract void addRepository()
121 throws IOException, RoleProfileException;
123 public String input()
128 public Object getModel()
133 protected abstract AbstractRepositoryConfiguration createRepository();
135 public void prepare()
136 throws ConfigurationStoreException
138 configuration = configurationStore.getConfigurationFromStore();
140 if ( repository == null )
142 repository = getRepository( repoId );
144 if ( repository == null )
146 repository = createRepository();
150 public String getRepoId()
155 public void setRepoId( String repoId )
157 this.repoId = repoId;
160 protected AbstractRepositoryConfiguration getRepository()
165 public Configuration getConfiguration()
167 return configuration;
170 public SecureActionBundle getSecureActionBundle()
171 throws SecureActionException
173 SecureActionBundle bundle = new SecureActionBundle();
175 bundle.setRequiresAuthentication( true );
177 if ( getRepoId() != null )
179 // TODO: this is not right. It needs to change based on method. But is this really the right way to restrict this area?
180 // TODO: not right. We only care about this permission on managed repositories. Otherwise, it's configuration
181 bundle.addRequiredAuthorization( ArchivaRoleConstants.OPERATION_EDIT_REPOSITORY, getRepoId() );
185 bundle.addRequiredAuthorization( ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION, Resource.GLOBAL );