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.commons.collections.CollectionUtils;
23 import org.apache.commons.collections.functors.NotPredicate;
24 import org.apache.commons.lang.StringUtils;
25 import org.apache.maven.archiva.configuration.ArchivaConfiguration;
26 import org.apache.maven.archiva.configuration.Configuration;
27 import org.apache.maven.archiva.configuration.IndeterminateConfigurationException;
28 import org.apache.maven.archiva.configuration.ProxyConnectorConfiguration;
29 import org.apache.maven.archiva.configuration.functors.ProxyConnectorSelectionPredicate;
30 import org.apache.archiva.security.ArchivaRoleConstants;
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)";
58 protected ArchivaConfiguration archivaConfiguration;
60 public SecureActionBundle getSecureActionBundle()
61 throws SecureActionException
63 SecureActionBundle bundle = new SecureActionBundle();
65 bundle.setRequiresAuthentication( true );
66 bundle.addRequiredAuthorization( ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION, Resource.GLOBAL );
71 public void setArchivaConfiguration( ArchivaConfiguration archivaConfiguration )
73 this.archivaConfiguration = archivaConfiguration;
76 protected void addProxyConnector( ProxyConnectorConfiguration proxyConnector )
78 getConfig().addProxyConnector( proxyConnector );
81 protected ProxyConnectorConfiguration findProxyConnector( String sourceId, String targetId )
83 if ( StringUtils.isBlank( sourceId ) )
88 if ( StringUtils.isBlank( targetId ) )
93 ProxyConnectorSelectionPredicate selectedProxy = new ProxyConnectorSelectionPredicate( sourceId, targetId );
94 return (ProxyConnectorConfiguration) CollectionUtils.find( getConfig().getProxyConnectors(), selectedProxy );
97 protected Configuration getConfig()
99 return this.archivaConfiguration.getConfiguration();
102 protected Map<String, List<ProxyConnectorConfiguration>> createProxyConnectorMap()
104 return getConfig().getProxyConnectorAsMap();
107 protected void removeConnector( String sourceId, String targetId )
109 ProxyConnectorSelectionPredicate selectedProxy = new ProxyConnectorSelectionPredicate( sourceId, targetId );
110 NotPredicate notSelectedProxy = new NotPredicate( selectedProxy );
111 CollectionUtils.filter( getConfig().getProxyConnectors(), notSelectedProxy );
114 protected void removeProxyConnector( ProxyConnectorConfiguration connector )
116 getConfig().removeProxyConnector( connector );
119 protected String saveConfiguration()
123 archivaConfiguration.save( getConfig() );
124 addActionMessage( "Successfully saved configuration" );
126 catch ( RegistryException e )
128 addActionError( "Unable to save configuration: " + e.getMessage() );
131 catch ( IndeterminateConfigurationException e )
133 addActionError( e.getMessage() );