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 com.opensymphony.xwork.ModelDriven;
23 import com.opensymphony.xwork.Preparable;
24 import org.apache.maven.archiva.configuration.AbstractRepositoryConfiguration;
25 import org.apache.maven.archiva.configuration.ArchivaConfiguration;
26 import org.apache.maven.archiva.configuration.Configuration;
27 import org.apache.maven.archiva.configuration.InvalidConfigurationException;
28 import org.apache.maven.archiva.security.ArchivaRoleConstants;
29 import org.codehaus.plexus.rbac.profile.RoleProfileException;
30 import org.codehaus.plexus.rbac.profile.RoleProfileManager;
31 import org.codehaus.plexus.registry.RegistryException;
32 import org.codehaus.plexus.security.rbac.RbacManagerException;
33 import org.codehaus.plexus.security.rbac.Resource;
34 import org.codehaus.plexus.security.ui.web.interceptor.SecureAction;
35 import org.codehaus.plexus.security.ui.web.interceptor.SecureActionBundle;
36 import org.codehaus.plexus.security.ui.web.interceptor.SecureActionException;
37 import org.codehaus.plexus.xwork.action.PlexusActionSupport;
39 import java.io.IOException;
42 * Base action for repository configuration actions.
44 * @author <a href="mailto:brett@apache.org">Brett Porter</a>
46 public abstract class AbstractConfigureRepositoryAction
47 extends PlexusActionSupport
48 implements ModelDriven, Preparable, SecureAction
53 private ArchivaConfiguration archivaConfiguration;
56 * @plexus.requirement role-hint="archiva"
58 protected RoleProfileManager roleProfileManager;
63 private AbstractRepositoryConfiguration repository;
66 * The repository ID to lookup when editing a repository.
68 private String repoId;
71 * The previously read configuration.
73 protected Configuration configuration;
76 throws IOException, InvalidConfigurationException, RbacManagerException, RoleProfileException, RegistryException
78 // TODO: if this didn't come from the form, go to configure.action instead of going through with re-saving what was just loaded
80 AbstractRepositoryConfiguration existingRepository = getRepository( repository.getId() );
81 if ( existingRepository != null )
83 addFieldError( "id", "A repository with that id already exists" );
87 return saveConfiguration();
91 throws IOException, InvalidConfigurationException, RbacManagerException, RoleProfileException, RegistryException
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, InvalidConfigurationException, RbacManagerException, RoleProfileException, RegistryException
110 archivaConfiguration.save( configuration );
112 // TODO: do we need to check if indexing is needed?
114 addActionMessage( "Successfully saved configuration" );
119 protected abstract void addRepository()
120 throws IOException, RoleProfileException;
122 public String input()
127 public Object getModel()
132 protected abstract AbstractRepositoryConfiguration createRepository();
134 public void prepare()
136 configuration = archivaConfiguration.getConfiguration();
138 if ( repository == null )
140 repository = getRepository( repoId );
142 if ( repository == null )
144 repository = createRepository();
148 public String getRepoId()
153 public void setRepoId( String repoId )
155 this.repoId = repoId;
158 protected AbstractRepositoryConfiguration getRepository()
163 public Configuration getConfiguration()
165 return configuration;
168 public SecureActionBundle getSecureActionBundle()
169 throws SecureActionException
171 SecureActionBundle bundle = new SecureActionBundle();
173 bundle.setRequiresAuthentication( true );
175 if ( getRepoId() != null )
177 // TODO: this is not right. It needs to change based on method. But is this really the right way to restrict this area?
178 // TODO: not right. We only care about this permission on managed repositories. Otherwise, it's configuration
179 bundle.addRequiredAuthorization( ArchivaRoleConstants.OPERATION_EDIT_REPOSITORY, getRepoId() );
183 bundle.addRequiredAuthorization( ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION, Resource.GLOBAL );