1 package org.apache.maven.archiva.web.action.admin.repositories;
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 org.apache.archiva.admin.repository.RepositoryCommonValidator;
23 import org.apache.archiva.admin.repository.managed.ManagedRepositoryAdmin;
24 import org.apache.archiva.audit.Auditable;
25 import org.apache.archiva.security.common.ArchivaRoleConstants;
26 import org.apache.maven.archiva.configuration.ArchivaConfiguration;
27 import org.apache.maven.archiva.configuration.Configuration;
28 import org.apache.maven.archiva.configuration.IndeterminateConfigurationException;
29 import org.apache.maven.archiva.configuration.InvalidConfigurationException;
30 import org.apache.maven.archiva.configuration.ProxyConnectorConfiguration;
31 import org.apache.maven.archiva.web.action.AbstractActionSupport;
32 import org.codehaus.plexus.redback.rbac.Resource;
33 import org.codehaus.plexus.registry.RegistryException;
34 import org.codehaus.redback.integration.interceptor.SecureAction;
35 import org.codehaus.redback.integration.interceptor.SecureActionBundle;
36 import org.codehaus.redback.integration.interceptor.SecureActionException;
38 import javax.inject.Inject;
39 import java.io.IOException;
40 import java.util.ArrayList;
41 import java.util.List;
44 * Abstract AdminRepositories Action base.
46 * Base class for all repository administrative functions.
47 * This should be neutral to the type of action (add/edit/delete) and type of repo (managed/remote)
51 public abstract class AbstractRepositoriesAdminAction
52 extends AbstractActionSupport
53 implements SecureAction, Auditable
57 protected ArchivaConfiguration archivaConfiguration;
60 private ManagedRepositoryAdmin managedRepositoryAdmin;
63 private RepositoryCommonValidator repositoryCommonValidator;
65 public ArchivaConfiguration getArchivaConfiguration()
67 return archivaConfiguration;
70 public SecureActionBundle getSecureActionBundle()
71 throws SecureActionException
73 SecureActionBundle bundle = new SecureActionBundle();
75 bundle.setRequiresAuthentication( true );
76 bundle.addRequiredAuthorization( ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION, Resource.GLOBAL );
81 public void setArchivaConfiguration( ArchivaConfiguration archivaConfiguration )
83 this.archivaConfiguration = archivaConfiguration;
87 * Save the configuration.
89 * @param configuration the configuration to save.
90 * @return the webwork result code to issue.
91 * @throws IOException thrown if unable to save file to disk.
92 * @throws InvalidConfigurationException thrown if configuration is invalid.
93 * @throws RegistryException thrown if configuration subsystem has a problem saving the configuration to disk.
95 protected String saveConfiguration( Configuration configuration )
99 archivaConfiguration.save( configuration );
100 addActionMessage( "Successfully saved configuration" );
102 catch ( IndeterminateConfigurationException e )
104 addActionError( e.getMessage() );
107 catch ( RegistryException e )
109 addActionError( "Configuration Registry Exception: " + e.getMessage() );
117 * Get the list of ProxyConnectors that are present in the configuration.
119 * @return a new list of ProxyConnectors present in the configuration.
121 protected List<ProxyConnectorConfiguration> getProxyConnectors()
123 return new ArrayList<ProxyConnectorConfiguration>(
124 archivaConfiguration.getConfiguration().getProxyConnectors() );
128 public ManagedRepositoryAdmin getManagedRepositoryAdmin()
130 return managedRepositoryAdmin;
133 public void setManagedRepositoryAdmin( ManagedRepositoryAdmin managedRepositoryAdmin )
135 this.managedRepositoryAdmin = managedRepositoryAdmin;
138 public RepositoryCommonValidator getRepositoryCommonValidator()
140 return repositoryCommonValidator;
143 public void setRepositoryCommonValidator( RepositoryCommonValidator repositoryCommonValidator )
145 this.repositoryCommonValidator = repositoryCommonValidator;