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.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
59 protected ArchivaConfiguration archivaConfiguration;
62 private ManagedRepositoryAdmin managedRepositoryAdmin;
65 private RepositoryCommonValidator repositoryCommonValidator;
67 public ArchivaConfiguration getArchivaConfiguration()
69 return archivaConfiguration;
72 public SecureActionBundle getSecureActionBundle()
73 throws SecureActionException
75 SecureActionBundle bundle = new SecureActionBundle();
77 bundle.setRequiresAuthentication( true );
78 bundle.addRequiredAuthorization( ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION, Resource.GLOBAL );
83 public void setArchivaConfiguration( ArchivaConfiguration archivaConfiguration )
85 this.archivaConfiguration = archivaConfiguration;
89 * Save the configuration.
91 * @param configuration the configuration to save.
92 * @return the webwork result code to issue.
93 * @throws IOException thrown if unable to save file to disk.
94 * @throws InvalidConfigurationException thrown if configuration is invalid.
95 * @throws RegistryException thrown if configuration subsystem has a problem saving the configuration to disk.
97 protected String saveConfiguration( Configuration configuration )
101 archivaConfiguration.save( configuration );
102 addActionMessage( "Successfully saved configuration" );
104 catch ( IndeterminateConfigurationException e )
106 addActionError( e.getMessage() );
109 catch ( RegistryException e )
111 addActionError( "Configuration Registry Exception: " + e.getMessage() );
119 * Get the list of ProxyConnectors that are present in the configuration.
121 * @return a new list of ProxyConnectors present in the configuration.
123 protected List<ProxyConnectorConfiguration> getProxyConnectors()
125 return new ArrayList<ProxyConnectorConfiguration>(
126 archivaConfiguration.getConfiguration().getProxyConnectors() );
130 public ManagedRepositoryAdmin getManagedRepositoryAdmin()
132 return managedRepositoryAdmin;
135 public void setManagedRepositoryAdmin( ManagedRepositoryAdmin managedRepositoryAdmin )
137 this.managedRepositoryAdmin = managedRepositoryAdmin;
140 public RepositoryCommonValidator getRepositoryCommonValidator()
142 return repositoryCommonValidator;
145 public void setRepositoryCommonValidator( RepositoryCommonValidator repositoryCommonValidator )
147 this.repositoryCommonValidator = repositoryCommonValidator;