mirror of
https://github.com/apache/archiva.git
synced 2025-02-21 17:35:19 +00:00
MRM-1507 : api to configure ProxyConnector : oops missed to add some files
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1166131 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
281092c41a
commit
2a795aa6bf
@ -0,0 +1,401 @@
|
||||
package org.apache.archiva.admin.repository;
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Olivier Lamy
|
||||
* @since 1.4
|
||||
*/
|
||||
public abstract class AbstractRepositoryConnector
|
||||
implements Serializable
|
||||
{
|
||||
/**
|
||||
* The Repository Source for this connector.
|
||||
*/
|
||||
private String sourceRepoId;
|
||||
|
||||
/**
|
||||
* The Repository Target for this connector.
|
||||
*/
|
||||
private String targetRepoId;
|
||||
|
||||
/**
|
||||
* The network proxy ID to use for this connector.
|
||||
*/
|
||||
private String proxyId;
|
||||
|
||||
/**
|
||||
* Field blackListPatterns.
|
||||
*/
|
||||
private List<String> blackListPatterns;
|
||||
|
||||
/**
|
||||
* Field whiteListPatterns.
|
||||
*/
|
||||
private List<String> whiteListPatterns;
|
||||
|
||||
/**
|
||||
* Field policies.
|
||||
*/
|
||||
private Map<String, String> policies;
|
||||
|
||||
/**
|
||||
* Field properties.
|
||||
*/
|
||||
private Map<String, String> properties;
|
||||
|
||||
/**
|
||||
* If the the repository proxy connector is disabled or not
|
||||
*/
|
||||
private boolean disabled = false;
|
||||
|
||||
//-----------/
|
||||
//- Methods -/
|
||||
//-----------/
|
||||
|
||||
/**
|
||||
* Method addBlackListPattern.
|
||||
*
|
||||
* @param string
|
||||
*/
|
||||
public void addBlackListPattern( String string )
|
||||
{
|
||||
getBlackListPatterns().add( string );
|
||||
}
|
||||
|
||||
/**
|
||||
* Method addPolicy.
|
||||
*
|
||||
* @param key
|
||||
* @param value
|
||||
*/
|
||||
public void addPolicy( String key, String value )
|
||||
{
|
||||
getPolicies().put( key, value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Method addProperty.
|
||||
*
|
||||
* @param key
|
||||
* @param value
|
||||
*/
|
||||
public void addProperty( String key, String value )
|
||||
{
|
||||
getProperties().put( key, value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Method addWhiteListPattern.
|
||||
*
|
||||
* @param string
|
||||
*/
|
||||
public void addWhiteListPattern( String string )
|
||||
{
|
||||
getWhiteListPatterns().add( string );
|
||||
}
|
||||
|
||||
/**
|
||||
* Method getBlackListPatterns.
|
||||
*
|
||||
* @return List
|
||||
*/
|
||||
public List<String> getBlackListPatterns()
|
||||
{
|
||||
if ( this.blackListPatterns == null )
|
||||
{
|
||||
this.blackListPatterns = new ArrayList<String>();
|
||||
}
|
||||
|
||||
return this.blackListPatterns;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method getPolicies.
|
||||
*
|
||||
* @return Map
|
||||
*/
|
||||
public Map<String, String> getPolicies()
|
||||
{
|
||||
if ( this.policies == null )
|
||||
{
|
||||
this.policies = new HashMap<String, String>();
|
||||
}
|
||||
|
||||
return this.policies;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method getProperties.
|
||||
*
|
||||
* @return Map
|
||||
*/
|
||||
public Map<String, String> getProperties()
|
||||
{
|
||||
if ( this.properties == null )
|
||||
{
|
||||
this.properties = new HashMap<String, String>();
|
||||
}
|
||||
|
||||
return this.properties;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the network proxy ID to use for this connector.
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public String getProxyId()
|
||||
{
|
||||
return this.proxyId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Repository Source for this connector.
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public String getSourceRepoId()
|
||||
{
|
||||
return this.sourceRepoId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Repository Target for this connector.
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public String getTargetRepoId()
|
||||
{
|
||||
return this.targetRepoId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method getWhiteListPatterns.
|
||||
*
|
||||
* @return List
|
||||
*/
|
||||
public List<String> getWhiteListPatterns()
|
||||
{
|
||||
if ( this.whiteListPatterns == null )
|
||||
{
|
||||
this.whiteListPatterns = new ArrayList<String>();
|
||||
}
|
||||
|
||||
return this.whiteListPatterns;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get if the the repository proxy connector is disabled or not
|
||||
* .
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public boolean isDisabled()
|
||||
{
|
||||
return this.disabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method removeBlackListPattern.
|
||||
*
|
||||
* @param string
|
||||
*/
|
||||
public void removeBlackListPattern( String string )
|
||||
{
|
||||
getBlackListPatterns().remove( string );
|
||||
}
|
||||
|
||||
/**
|
||||
* Method removeWhiteListPattern.
|
||||
*
|
||||
* @param string
|
||||
*/
|
||||
public void removeWhiteListPattern( String string )
|
||||
{
|
||||
getWhiteListPatterns().remove( string );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the list of blacklisted patterns for this connector.
|
||||
*
|
||||
* @param blackListPatterns
|
||||
*/
|
||||
public void setBlackListPatterns( List<String> blackListPatterns )
|
||||
{
|
||||
this.blackListPatterns = blackListPatterns;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set if the the repository proxy connector is
|
||||
* disabled or not
|
||||
* .
|
||||
*
|
||||
* @param disabled
|
||||
*/
|
||||
public void setDisabled( boolean disabled )
|
||||
{
|
||||
this.disabled = disabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set policy configuration for the connector.
|
||||
*
|
||||
* @param policies
|
||||
*/
|
||||
public void setPolicies( Map<String, String> policies )
|
||||
{
|
||||
this.policies = policies;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set configuration for the connector.
|
||||
*
|
||||
* @param properties
|
||||
*/
|
||||
public void setProperties( Map<String, String> properties )
|
||||
{
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the network proxy ID to use for this connector.
|
||||
*
|
||||
* @param proxyId
|
||||
*/
|
||||
public void setProxyId( String proxyId )
|
||||
{
|
||||
this.proxyId = proxyId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Repository Source for this connector.
|
||||
*
|
||||
* @param sourceRepoId
|
||||
*/
|
||||
public void setSourceRepoId( String sourceRepoId )
|
||||
{
|
||||
this.sourceRepoId = sourceRepoId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Repository Target for this connector.
|
||||
*
|
||||
* @param targetRepoId
|
||||
*/
|
||||
public void setTargetRepoId( String targetRepoId )
|
||||
{
|
||||
this.targetRepoId = targetRepoId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set
|
||||
* The list of whitelisted patterns for this
|
||||
* connector.
|
||||
*
|
||||
* @param whiteListPatterns
|
||||
*/
|
||||
public void setWhiteListPatterns( List<String> whiteListPatterns )
|
||||
{
|
||||
this.whiteListPatterns = whiteListPatterns;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Obtain a specific policy from the underlying connector.
|
||||
*
|
||||
* @param policyId the policy id to fetch.
|
||||
* @param defaultValue the default value for the policy id.
|
||||
* @return the configured policy value (or default value if not found).
|
||||
*/
|
||||
public String getPolicy( String policyId, String defaultValue )
|
||||
{
|
||||
if ( this.getPolicies() == null )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
String value = this.getPolicies().get( policyId );
|
||||
|
||||
if ( value == null )
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals( Object o )
|
||||
{
|
||||
if ( this == o )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if ( o == null || getClass() != o.getClass() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
AbstractRepositoryConnector that = (AbstractRepositoryConnector) o;
|
||||
|
||||
if ( sourceRepoId != null ? !sourceRepoId.equals( that.sourceRepoId ) : that.sourceRepoId != null )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if ( targetRepoId != null ? !targetRepoId.equals( that.targetRepoId ) : that.targetRepoId != null )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
int result = sourceRepoId != null ? sourceRepoId.hashCode() : 0;
|
||||
result = 31 * result + ( targetRepoId != null ? targetRepoId.hashCode() : 0 );
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
sb.append( "AbstractRepositoryConnector" );
|
||||
sb.append( "{sourceRepoId='" ).append( sourceRepoId ).append( '\'' );
|
||||
sb.append( ", targetRepoId='" ).append( targetRepoId ).append( '\'' );
|
||||
sb.append( ", proxyId='" ).append( proxyId ).append( '\'' );
|
||||
sb.append( ", blackListPatterns=" ).append( blackListPatterns );
|
||||
sb.append( ", whiteListPatterns=" ).append( whiteListPatterns );
|
||||
sb.append( ", policies=" ).append( policies );
|
||||
sb.append( ", properties=" ).append( properties );
|
||||
sb.append( ", disabled=" ).append( disabled );
|
||||
sb.append( '}' );
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,206 @@
|
||||
package org.apache.archiva.admin.repository.proxyconnector;
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
import org.apache.archiva.admin.AuditInformation;
|
||||
import org.apache.archiva.admin.repository.AbstractRepositoryAdmin;
|
||||
import org.apache.archiva.admin.repository.RepositoryAdminException;
|
||||
import org.apache.archiva.admin.repository.managed.ManagedRepositoryAdmin;
|
||||
import org.apache.archiva.admin.repository.remote.RemoteRepositoryAdmin;
|
||||
import org.apache.archiva.audit.AuditEvent;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.maven.archiva.configuration.Configuration;
|
||||
import org.apache.maven.archiva.configuration.ProxyConnectorConfiguration;
|
||||
import org.apache.maven.archiva.configuration.functors.ProxyConnectorSelectionPredicate;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Olivier Lamy
|
||||
* @since 1.4
|
||||
*/
|
||||
@Service( "proxyConnectorAdmin#default" )
|
||||
public class DefaultProxyConnectorAdmin
|
||||
extends AbstractRepositoryAdmin
|
||||
implements ProxyConnectorAdmin
|
||||
{
|
||||
|
||||
@Inject
|
||||
private ManagedRepositoryAdmin managedRepositoryAdmin;
|
||||
|
||||
@Inject
|
||||
private RemoteRepositoryAdmin remoteRepositoryAdmin;
|
||||
|
||||
public List<ProxyConnector> getProxyConnectors()
|
||||
throws RepositoryAdminException
|
||||
{
|
||||
List<ProxyConnectorConfiguration> proxyConnectorConfigurations =
|
||||
getArchivaConfiguration().getConfiguration().getProxyConnectors();
|
||||
List<ProxyConnector> proxyConnectors = new ArrayList<ProxyConnector>( proxyConnectorConfigurations.size() );
|
||||
for ( ProxyConnectorConfiguration configuration : proxyConnectorConfigurations )
|
||||
{
|
||||
ProxyConnector proxyConnector = new ProxyConnector();
|
||||
proxyConnectors.add( proxyConnector );
|
||||
proxyConnector.setOrder( configuration.getOrder() );
|
||||
proxyConnector.setBlackListPatterns( new ArrayList<String>( configuration.getBlackListPatterns() ) );
|
||||
proxyConnector.setWhiteListPatterns( new ArrayList<String>( configuration.getWhiteListPatterns() ) );
|
||||
proxyConnector.setDisabled( configuration.isDisabled() );
|
||||
proxyConnector.setPolicies( new HashMap<String, String>( configuration.getPolicies() ) );
|
||||
proxyConnector.setProperties( new HashMap<String, String>( configuration.getProperties() ) );
|
||||
proxyConnector.setProxyId( configuration.getProxyId() );
|
||||
proxyConnector.setSourceRepoId( configuration.getSourceRepoId() );
|
||||
proxyConnector.setTargetRepoId( configuration.getTargetRepoId() );
|
||||
}
|
||||
|
||||
return proxyConnectors;
|
||||
}
|
||||
|
||||
public ProxyConnector getProxyConnector( String sourceRepoId, String targetRepoId )
|
||||
throws RepositoryAdminException
|
||||
{
|
||||
for ( ProxyConnector proxyConnector : getProxyConnectors() )
|
||||
{
|
||||
if ( StringUtils.equals( sourceRepoId, proxyConnector.getSourceRepoId() ) && StringUtils.equals(
|
||||
targetRepoId, proxyConnector.getTargetRepoId() ) )
|
||||
{
|
||||
return proxyConnector;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Boolean addProxyConnector( ProxyConnector proxyConnector, AuditInformation auditInformation )
|
||||
throws RepositoryAdminException
|
||||
{
|
||||
if ( getProxyConnector( proxyConnector.getSourceRepoId(), proxyConnector.getTargetRepoId() ) != null )
|
||||
{
|
||||
throw new RepositoryAdminException(
|
||||
"Unable to add proxy connector, as one already exists with source repository id ["
|
||||
+ proxyConnector.getSourceRepoId() + "] and target repository id ["
|
||||
+ proxyConnector.getTargetRepoId() + "]." );
|
||||
}
|
||||
|
||||
validateProxyConnector( proxyConnector );
|
||||
|
||||
proxyConnector.setBlackListPatterns( unescapePatterns( proxyConnector.getBlackListPatterns() ) );
|
||||
proxyConnector.setWhiteListPatterns( unescapePatterns( proxyConnector.getWhiteListPatterns() ) );
|
||||
|
||||
Configuration configuration = getArchivaConfiguration().getConfiguration();
|
||||
|
||||
ProxyConnectorConfiguration proxyConnectorConfiguration = getProxyConnectorConfiguration( proxyConnector );
|
||||
configuration.addProxyConnector( proxyConnectorConfiguration );
|
||||
saveConfiguration( configuration );
|
||||
triggerAuditEvent( proxyConnector.getSourceRepoId() + "-" + proxyConnector.getTargetRepoId(), null,
|
||||
AuditEvent.ADD_PROXY_CONNECTOR, auditInformation );
|
||||
return Boolean.TRUE;
|
||||
|
||||
}
|
||||
|
||||
public Boolean deleteProxyConnector( ProxyConnector proxyConnector, AuditInformation auditInformation )
|
||||
throws RepositoryAdminException
|
||||
{
|
||||
Configuration configuration = getArchivaConfiguration().getConfiguration();
|
||||
ProxyConnectorConfiguration proxyConnectorConfiguration =
|
||||
findProxyConnector( proxyConnector.getSourceRepoId(), proxyConnector.getTargetRepoId(), configuration );
|
||||
if ( proxyConnectorConfiguration == null )
|
||||
{
|
||||
throw new RepositoryAdminException(
|
||||
"unable to find ProxyConnector with source " + proxyConnector.getSourceRepoId() + " and target "
|
||||
+ proxyConnector.getTargetRepoId() );
|
||||
}
|
||||
configuration.removeProxyConnector( proxyConnectorConfiguration );
|
||||
saveConfiguration( configuration );
|
||||
triggerAuditEvent( proxyConnector.getSourceRepoId() + "-" + proxyConnector.getTargetRepoId(), null,
|
||||
AuditEvent.DELETE_PROXY_CONNECTOR, auditInformation );
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
|
||||
protected List<String> unescapePatterns( List<String> patterns )
|
||||
{
|
||||
List<String> rawPatterns = new ArrayList<String>();
|
||||
if ( patterns != null )
|
||||
{
|
||||
for ( String pattern : patterns )
|
||||
{
|
||||
rawPatterns.add( StringUtils.replace( pattern, "\\\\", "\\" ) );
|
||||
}
|
||||
}
|
||||
|
||||
return rawPatterns;
|
||||
}
|
||||
|
||||
protected ProxyConnectorConfiguration findProxyConnector( String sourceId, String targetId,
|
||||
Configuration configuration )
|
||||
{
|
||||
if ( StringUtils.isBlank( sourceId ) )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if ( StringUtils.isBlank( targetId ) )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
ProxyConnectorSelectionPredicate selectedProxy = new ProxyConnectorSelectionPredicate( sourceId, targetId );
|
||||
return (ProxyConnectorConfiguration) CollectionUtils.find( configuration.getProxyConnectors(), selectedProxy );
|
||||
}
|
||||
|
||||
protected ProxyConnectorConfiguration getProxyConnectorConfiguration( ProxyConnector proxyConnector )
|
||||
{
|
||||
ProxyConnectorConfiguration proxyConnectorConfiguration = new ProxyConnectorConfiguration();
|
||||
proxyConnectorConfiguration.setOrder( proxyConnector.getOrder() );
|
||||
proxyConnectorConfiguration.setBlackListPatterns(
|
||||
new ArrayList<String>( proxyConnector.getBlackListPatterns() ) );
|
||||
proxyConnectorConfiguration.setWhiteListPatterns(
|
||||
new ArrayList<String>( proxyConnector.getWhiteListPatterns() ) );
|
||||
proxyConnectorConfiguration.setDisabled( proxyConnector.isDisabled() );
|
||||
proxyConnectorConfiguration.setPolicies( new HashMap( proxyConnector.getPolicies() ) );
|
||||
proxyConnectorConfiguration.setProperties( new HashMap( proxyConnector.getProperties() ) );
|
||||
proxyConnectorConfiguration.setProxyId( proxyConnector.getProxyId() );
|
||||
proxyConnectorConfiguration.setSourceRepoId( proxyConnector.getSourceRepoId() );
|
||||
proxyConnectorConfiguration.setTargetRepoId( proxyConnector.getTargetRepoId() );
|
||||
return proxyConnectorConfiguration;
|
||||
}
|
||||
|
||||
protected void validateProxyConnector( ProxyConnector proxyConnector )
|
||||
throws RepositoryAdminException
|
||||
{
|
||||
// validate source a Managed target a Remote
|
||||
if ( managedRepositoryAdmin.getManagedRepository( proxyConnector.getSourceRepoId() ) == null )
|
||||
{
|
||||
throw new RepositoryAdminException(
|
||||
"non valid ProxyConnector sourceRepo with id " + proxyConnector.getSourceRepoId()
|
||||
+ " is not a ManagedRepository" );
|
||||
}
|
||||
if ( remoteRepositoryAdmin.getRemoteRepository( proxyConnector.getTargetRepoId() ) == null )
|
||||
{
|
||||
throw new RepositoryAdminException(
|
||||
"non valid ProxyConnector sourceRepo with id " + proxyConnector.getTargetRepoId()
|
||||
+ " is not a RemoteRepository" );
|
||||
}
|
||||
|
||||
// FIXME validate NetworkProxyConfiguration too
|
||||
}
|
||||
}
|
@ -0,0 +1,116 @@
|
||||
package org.apache.archiva.admin.repository.proxyconnector;
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
import org.apache.archiva.admin.repository.AbstractRepositoryConnector;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author Olivier Lamy
|
||||
* @since 1.4
|
||||
*/
|
||||
public class ProxyConnector
|
||||
extends AbstractRepositoryConnector
|
||||
implements Serializable
|
||||
{
|
||||
/**
|
||||
* The order id for UNORDERED
|
||||
*/
|
||||
public static final int UNORDERED = 0;
|
||||
|
||||
/**
|
||||
* The policy key {@link #getPolicies()} for error handling.
|
||||
* See {@link org.apache.maven.archiva.policies.DownloadErrorPolicy}
|
||||
* for details on potential values to this policy key.
|
||||
*/
|
||||
public static final String POLICY_PROPAGATE_ERRORS = "propagate-errors";
|
||||
|
||||
/**
|
||||
* The policy key {@link #getPolicies()} for error handling when an artifact is present.
|
||||
* See {@link org.apache.maven.archiva.policies.DownloadErrorPolicy}
|
||||
* for details on potential values to this policy key.
|
||||
*/
|
||||
public static final String POLICY_PROPAGATE_ERRORS_ON_UPDATE = "propagate-errors-on-update";
|
||||
|
||||
/**
|
||||
* The policy key {@link #getPolicies()} for snapshot handling.
|
||||
* See {@link org.apache.maven.archiva.policies.SnapshotsPolicy}
|
||||
* for details on potential values to this policy key.
|
||||
*/
|
||||
public static final String POLICY_SNAPSHOTS = "snapshots";
|
||||
|
||||
/**
|
||||
* The policy key {@link #getPolicies()} for releases handling.
|
||||
* See {@link org.apache.maven.archiva.policies.ReleasesPolicy}
|
||||
* for details on potential values to this policy key.
|
||||
*/
|
||||
public static final String POLICY_RELEASES = "releases";
|
||||
|
||||
/**
|
||||
* The policy key {@link #getPolicies()} for checksum handling.
|
||||
* See {@link org.apache.maven.archiva.policies.ChecksumPolicy}
|
||||
* for details on potential values to this policy key.
|
||||
*/
|
||||
public static final String POLICY_CHECKSUM = "checksum";
|
||||
|
||||
/**
|
||||
* The policy key {@link #getPolicies()} for cache-failures handling.
|
||||
* See {@link org.apache.maven.archiva.policies.CachedFailuresPolicy}
|
||||
* for details on potential values to this policy key.
|
||||
*/
|
||||
public static final String POLICY_CACHE_FAILURES = "cache-failures";
|
||||
|
||||
/**
|
||||
*
|
||||
* The order of the proxy connectors. (0 means no order specified)
|
||||
* .
|
||||
*/
|
||||
private int order = 0;
|
||||
|
||||
/**
|
||||
* Get the order of the proxy connectors. (0 means no order specified)
|
||||
* @return int
|
||||
*/
|
||||
public int getOrder()
|
||||
{
|
||||
return this.order;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the order of the proxy connectors. (0 means no order specified)
|
||||
* @param order
|
||||
*/
|
||||
public void setOrder( int order )
|
||||
{
|
||||
this.order = order;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
sb.append( "ProxyConnector" );
|
||||
sb.append( "{order=" ).append( order );
|
||||
sb.append( '}' );
|
||||
sb.append( super.toString() );
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
package org.apache.archiva.admin.repository.proxyconnector;
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
import org.apache.archiva.admin.AuditInformation;
|
||||
import org.apache.archiva.admin.repository.RepositoryAdminException;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* No update method here as id is : sourceRepoId and targetRepoId, use delete then add.
|
||||
*
|
||||
* @author Olivier Lamy
|
||||
* @since 1.4
|
||||
*/
|
||||
public interface ProxyConnectorAdmin
|
||||
{
|
||||
List<ProxyConnector> getProxyConnectors()
|
||||
throws RepositoryAdminException;
|
||||
|
||||
ProxyConnector getProxyConnector( String sourceRepoId, String targetRepoId )
|
||||
throws RepositoryAdminException;
|
||||
|
||||
Boolean addProxyConnector( ProxyConnector proxyConnector, AuditInformation auditInformation )
|
||||
throws RepositoryAdminException;
|
||||
|
||||
Boolean deleteProxyConnector( ProxyConnector proxyConnector, AuditInformation auditInformation )
|
||||
throws RepositoryAdminException;
|
||||
|
||||
}
|
@ -0,0 +1,126 @@
|
||||
package org.apache.archiva.admin.repository.proxyconnector;
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
import org.apache.archiva.admin.repository.AbstractRepositoryAdminTest;
|
||||
import org.apache.archiva.admin.repository.remote.RemoteRepository;
|
||||
import org.apache.archiva.audit.AuditEvent;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author Olivier Lamy
|
||||
*/
|
||||
public class ProxyConnectorAdminTest
|
||||
extends AbstractRepositoryAdminTest
|
||||
{
|
||||
|
||||
@Test
|
||||
public void addAndDelete()
|
||||
throws Exception
|
||||
{
|
||||
assertEquals( "not proxyConnectors 2 " + proxyConnectorAdmin.getProxyConnectors(), 2,
|
||||
proxyConnectorAdmin.getProxyConnectors().size() );
|
||||
assertFalse( proxyConnectorAdmin.getProxyConnectors().isEmpty() );
|
||||
ProxyConnector proxyConnector = new ProxyConnector();
|
||||
proxyConnector.setSourceRepoId( "snapshots" );
|
||||
proxyConnector.setTargetRepoId( "central" );
|
||||
proxyConnectorAdmin.addProxyConnector( proxyConnector, getFakeAuditInformation() );
|
||||
|
||||
assertFalse( proxyConnectorAdmin.getProxyConnectors().isEmpty() );
|
||||
assertEquals( 3, proxyConnectorAdmin.getProxyConnectors().size() );
|
||||
|
||||
assertNotNull( proxyConnectorAdmin.getProxyConnector( "snapshots", "central" ) );
|
||||
|
||||
proxyConnectorAdmin.deleteProxyConnector( proxyConnector, getFakeAuditInformation() );
|
||||
|
||||
assertEquals( 2, proxyConnectorAdmin.getProxyConnectors().size() );
|
||||
assertFalse( proxyConnectorAdmin.getProxyConnectors().isEmpty() );
|
||||
|
||||
assertEquals( 2, mockAuditListener.getAuditEvents().size() );
|
||||
|
||||
assertEquals( AuditEvent.ADD_PROXY_CONNECTOR, mockAuditListener.getAuditEvents().get( 0 ).getAction() );
|
||||
assertEquals( "root", mockAuditListener.getAuditEvents().get( 0 ).getUserId() );
|
||||
assertEquals( "archiva-localhost", mockAuditListener.getAuditEvents().get( 0 ).getRemoteIP() );
|
||||
|
||||
assertEquals( AuditEvent.DELETE_PROXY_CONNECTOR, mockAuditListener.getAuditEvents().get( 1 ).getAction() );
|
||||
assertEquals( "root", mockAuditListener.getAuditEvents().get( 1 ).getUserId() );
|
||||
|
||||
assertNull( proxyConnectorAdmin.getProxyConnector( "snapshots", "central" ) );
|
||||
|
||||
mockAuditListener.clearEvents();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addAndUpdateAndDelete()
|
||||
throws Exception
|
||||
{
|
||||
|
||||
RemoteRepository remoteRepository = getRemoteRepository( "test-new-one" );
|
||||
|
||||
remoteRepositoryAdmin.addRemoteRepository( remoteRepository, getFakeAuditInformation() );
|
||||
|
||||
assertEquals( "not proxyConnectors 2 " + proxyConnectorAdmin.getProxyConnectors(), 2,
|
||||
proxyConnectorAdmin.getProxyConnectors().size() );
|
||||
assertFalse( proxyConnectorAdmin.getProxyConnectors().isEmpty() );
|
||||
ProxyConnector proxyConnector = new ProxyConnector();
|
||||
proxyConnector.setSourceRepoId( "snapshots" );
|
||||
proxyConnector.setTargetRepoId( "central" );
|
||||
proxyConnectorAdmin.addProxyConnector( proxyConnector, getFakeAuditInformation() );
|
||||
|
||||
assertFalse( proxyConnectorAdmin.getProxyConnectors().isEmpty() );
|
||||
assertEquals( 3, proxyConnectorAdmin.getProxyConnectors().size() );
|
||||
|
||||
assertNotNull( proxyConnectorAdmin.getProxyConnector( "snapshots", "central" ) );
|
||||
|
||||
proxyConnectorAdmin.deleteProxyConnector( proxyConnector, getFakeAuditInformation() );
|
||||
|
||||
proxyConnector.setTargetRepoId( remoteRepository.getId() );
|
||||
proxyConnectorAdmin.addProxyConnector( proxyConnector, getFakeAuditInformation() );
|
||||
|
||||
assertNull( proxyConnectorAdmin.getProxyConnector( "snapshots", "central" ) );
|
||||
assertNotNull( remoteRepository.getId(),
|
||||
proxyConnectorAdmin.getProxyConnector( "snapshots", remoteRepository.getId() ) );
|
||||
|
||||
proxyConnectorAdmin.deleteProxyConnector( proxyConnector, getFakeAuditInformation() );
|
||||
|
||||
assertNull( proxyConnectorAdmin.getProxyConnector( "snapshots", "central" ) );
|
||||
|
||||
assertEquals( 2, proxyConnectorAdmin.getProxyConnectors().size() );
|
||||
assertFalse( proxyConnectorAdmin.getProxyConnectors().isEmpty() );
|
||||
|
||||
assertEquals( 5, mockAuditListener.getAuditEvents().size() );
|
||||
|
||||
assertEquals( AuditEvent.ADD_REMOTE_REPO, mockAuditListener.getAuditEvents().get( 0 ).getAction() );
|
||||
|
||||
assertEquals( AuditEvent.ADD_PROXY_CONNECTOR, mockAuditListener.getAuditEvents().get( 1 ).getAction() );
|
||||
assertEquals( "root", mockAuditListener.getAuditEvents().get( 2 ).getUserId() );
|
||||
assertEquals( "archiva-localhost", mockAuditListener.getAuditEvents().get( 2 ).getRemoteIP() );
|
||||
|
||||
assertEquals( AuditEvent.DELETE_PROXY_CONNECTOR, mockAuditListener.getAuditEvents().get( 2 ).getAction() );
|
||||
|
||||
assertEquals( AuditEvent.ADD_PROXY_CONNECTOR, mockAuditListener.getAuditEvents().get( 3 ).getAction() );
|
||||
|
||||
assertEquals( AuditEvent.DELETE_PROXY_CONNECTOR, mockAuditListener.getAuditEvents().get( 4 ).getAction() );
|
||||
assertEquals( "root", mockAuditListener.getAuditEvents().get( 4 ).getUserId() );
|
||||
|
||||
remoteRepositoryAdmin.deleteRemoteRepository( remoteRepository.getId(), getFakeAuditInformation() );
|
||||
mockAuditListener.clearEvents();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,81 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!--
|
||||
~ Licensed to the Apache Software Foundation (ASF) under one
|
||||
~ or more contributor license agreements. See the NOTICE file
|
||||
~ distributed with this work for additional information
|
||||
~ regarding copyright ownership. The ASF licenses this file
|
||||
~ to you under the Apache License, Version 2.0 (the
|
||||
~ "License"); you may not use this file except in compliance
|
||||
~ with the License. You may obtain a copy of the License at
|
||||
~
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~
|
||||
~ Unless required by applicable law or agreed to in writing,
|
||||
~ software distributed under the License is distributed on an
|
||||
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
~ KIND, either express or implied. See the License for the
|
||||
~ specific language governing permissions and limitations
|
||||
~ under the License.
|
||||
-->
|
||||
|
||||
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
|
||||
|
||||
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
|
||||
|
||||
<appender name="console" class="org.apache.log4j.ConsoleAppender">
|
||||
<layout class="org.apache.log4j.PatternLayout">
|
||||
<param name="ConversionPattern" value="%d [%t] %-5p %c %x - %m%n"/>
|
||||
</layout>
|
||||
</appender>
|
||||
<logger name="org.apache.maven.archiva.web.action.SearchAction">
|
||||
<level value="debug"/>
|
||||
</logger>
|
||||
<logger name="org.apache.archiva.indexer.search.NexusRepositorySearch">
|
||||
<level value="debug"/>
|
||||
</logger>
|
||||
<logger name="org.apache.archiva.common.plexusbridge.MavenIndexerUtils">
|
||||
<level value="debug"/>
|
||||
</logger>
|
||||
<logger name="JPOX">
|
||||
<level value="error"/>
|
||||
</logger>
|
||||
|
||||
<logger name="org.apache.commons.configuration.DefaultConfigurationBuilder">
|
||||
<level value="error"/>
|
||||
</logger>
|
||||
|
||||
<logger name="org.apache.archiva.admin.repository.managed">
|
||||
<level value="debug"/>
|
||||
</logger>
|
||||
|
||||
<logger name="com.opensymphony.xwork2.ognl.OgnlValueStack">
|
||||
<level value="error"/>
|
||||
</logger>
|
||||
|
||||
|
||||
<logger name="org.springframework">
|
||||
<level value="info"/>
|
||||
</logger>
|
||||
|
||||
<logger name="org.codehaus.plexus">
|
||||
<level value="info"/>
|
||||
</logger>
|
||||
|
||||
<logger name="org.codehaus.redback">
|
||||
<level value="info"/>
|
||||
</logger>
|
||||
|
||||
<logger name="org.apache.cxf">
|
||||
<level value="info"/>
|
||||
</logger>
|
||||
|
||||
<logger name="org.quartz">
|
||||
<level value="info"/>
|
||||
</logger>
|
||||
|
||||
<root>
|
||||
<priority value ="info" />
|
||||
<appender-ref ref="console" />
|
||||
</root>
|
||||
|
||||
</log4j:configuration>
|
Loading…
x
Reference in New Issue
Block a user