1 package org.apache.maven.archiva.web.action.admin.connectors.proxy;
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.security.common.ArchivaRoleConstants;
23 import org.apache.commons.collections.CollectionUtils;
24 import org.apache.commons.collections.functors.NotPredicate;
25 import org.apache.commons.lang.StringUtils;
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.ProxyConnectorConfiguration;
30 import org.apache.maven.archiva.configuration.functors.ProxyConnectorSelectionPredicate;
31 import org.apache.maven.archiva.web.action.AbstractActionSupport;
32 import org.codehaus.plexus.redback.rbac.Resource;
33 import org.codehaus.plexus.registry.RegistryException;
35 import java.util.List;
37 import org.codehaus.redback.integration.interceptor.SecureAction;
38 import org.codehaus.redback.integration.interceptor.SecureActionBundle;
39 import org.codehaus.redback.integration.interceptor.SecureActionException;
41 import javax.inject.Inject;
44 * AbstractProxyConnectorAction
48 public abstract class AbstractProxyConnectorAction
49 extends AbstractActionSupport
50 implements SecureAction
52 public static final String DIRECT_CONNECTION = "(direct connection)";
55 protected ArchivaConfiguration archivaConfiguration;
57 public SecureActionBundle getSecureActionBundle()
58 throws SecureActionException
60 SecureActionBundle bundle = new SecureActionBundle();
62 bundle.setRequiresAuthentication( true );
63 bundle.addRequiredAuthorization( ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION, Resource.GLOBAL );
68 public void setArchivaConfiguration( ArchivaConfiguration archivaConfiguration )
70 this.archivaConfiguration = archivaConfiguration;
73 protected void addProxyConnector( ProxyConnectorConfiguration proxyConnector )
75 getConfig().addProxyConnector( proxyConnector );
78 protected ProxyConnectorConfiguration findProxyConnector( String sourceId, String targetId )
80 if ( StringUtils.isBlank( sourceId ) )
85 if ( StringUtils.isBlank( targetId ) )
90 ProxyConnectorSelectionPredicate selectedProxy = new ProxyConnectorSelectionPredicate( sourceId, targetId );
91 return (ProxyConnectorConfiguration) CollectionUtils.find( getConfig().getProxyConnectors(), selectedProxy );
94 protected Configuration getConfig()
96 return this.archivaConfiguration.getConfiguration();
99 protected Map<String, List<ProxyConnectorConfiguration>> createProxyConnectorMap()
101 return getConfig().getProxyConnectorAsMap();
104 protected void removeConnector( String sourceId, String targetId )
106 ProxyConnectorSelectionPredicate selectedProxy = new ProxyConnectorSelectionPredicate( sourceId, targetId );
107 NotPredicate notSelectedProxy = new NotPredicate( selectedProxy );
108 CollectionUtils.filter( getConfig().getProxyConnectors(), notSelectedProxy );
111 protected void removeProxyConnector( ProxyConnectorConfiguration connector )
113 getConfig().removeProxyConnector( connector );
116 protected String saveConfiguration()
120 archivaConfiguration.save( getConfig() );
121 addActionMessage( "Successfully saved configuration" );
123 catch ( RegistryException e )
125 addActionError( "Unable to save configuration: " + e.getMessage() );
128 catch ( IndeterminateConfigurationException e )
130 addActionError( e.getMessage() );