diff options
author | Jonathan Sharp <forjsharp@gmail.com> | 2014-10-17 15:23:47 -0700 |
---|---|---|
committer | Jonathan Sharp <forjsharp@gmail.com> | 2014-10-17 15:23:47 -0700 |
commit | 7c9267111a4eb6b8a47b8b4891af98c487dd0c9b (patch) | |
tree | 28731e9883086797a8f854170a86b06b8b91584d /archiva-modules | |
parent | d3687d86b46a9638a8bc74c1e24aeb829947cf8c (diff) | |
download | archiva-7c9267111a4eb6b8a47b8b4891af98c487dd0c9b.tar.gz archiva-7c9267111a4eb6b8a47b8b4891af98c487dd0c9b.zip |
MRM-813 tweak APC interface and ADRF AuditEvents
Diffstat (limited to 'archiva-modules')
7 files changed, 75 insertions, 24 deletions
diff --git a/archiva-modules/archiva-base/archiva-proxy-api/src/main/java/org/apache/archiva/proxy/model/ProxyFetchResult.java b/archiva-modules/archiva-base/archiva-proxy-api/src/main/java/org/apache/archiva/proxy/model/ProxyFetchResult.java new file mode 100644 index 000000000..28c2af074 --- /dev/null +++ b/archiva-modules/archiva-base/archiva-proxy-api/src/main/java/org/apache/archiva/proxy/model/ProxyFetchResult.java @@ -0,0 +1,48 @@ +package org.apache.archiva.proxy.model; + +/* + * 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.File; + +/** + * A result from a proxy fetch operation. + */ +public class ProxyFetchResult +{ + + //The file returned + File file; + + //Was the local file modified by the fetch? + boolean modified; + + public ProxyFetchResult( File file, boolean modified) { + this.file = file; + this.modified = modified; + } + + public File getFile() { + return file; + } + + public boolean isModified() { + return modified; + } +} diff --git a/archiva-modules/archiva-base/archiva-proxy-api/src/main/java/org/apache/archiva/proxy/model/RepositoryProxyConnectors.java b/archiva-modules/archiva-base/archiva-proxy-api/src/main/java/org/apache/archiva/proxy/model/RepositoryProxyConnectors.java index 37b373219..e63f62393 100644 --- a/archiva-modules/archiva-base/archiva-proxy-api/src/main/java/org/apache/archiva/proxy/model/RepositoryProxyConnectors.java +++ b/archiva-modules/archiva-base/archiva-proxy-api/src/main/java/org/apache/archiva/proxy/model/RepositoryProxyConnectors.java @@ -59,7 +59,7 @@ public interface RepositoryProxyConnectors * @param logicalPath the metadata to fetch. * @return the file that was obtained, or null if no content was obtained */ - File fetchMetatadaFromProxies( ManagedRepositoryContent repository, String logicalPath ); + ProxyFetchResult fetchMetadataFromProxies( ManagedRepositoryContent repository, String logicalPath ); /** * Performs the fetch operation against the target repositories diff --git a/archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/archiva/proxy/DefaultRepositoryProxyConnectors.java b/archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/archiva/proxy/DefaultRepositoryProxyConnectors.java index 151dd61ea..0daa2d201 100644 --- a/archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/archiva/proxy/DefaultRepositoryProxyConnectors.java +++ b/archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/archiva/proxy/DefaultRepositoryProxyConnectors.java @@ -48,6 +48,7 @@ import org.apache.archiva.policies.urlcache.UrlFailureCache; import org.apache.archiva.proxy.common.WagonFactory; import org.apache.archiva.proxy.common.WagonFactoryException; import org.apache.archiva.proxy.common.WagonFactoryRequest; +import org.apache.archiva.proxy.model.ProxyFetchResult; import org.apache.archiva.proxy.model.ProxyConnector; import org.apache.archiva.proxy.model.RepositoryProxyConnectors; import org.apache.archiva.redback.components.registry.Registry; @@ -447,7 +448,7 @@ public class DefaultRepositoryProxyConnectors } @Override - public File fetchMetatadaFromProxies( ManagedRepositoryContent repository, String logicalPath ) + public ProxyFetchResult fetchMetadataFromProxies( ManagedRepositoryContent repository, String logicalPath ) { File localFile = new File( repository.getRepoRoot(), logicalPath ); @@ -517,14 +518,15 @@ public class DefaultRepositoryProxyConnectors { log.warn( "Unable to update metadata {}:{}", localFile.getAbsolutePath(), e.getMessage(), e ); } + } if ( fileExists( localFile ) ) { - return localFile; + return new ProxyFetchResult( localFile, metadataNeedsUpdating ); } - return null; + return new ProxyFetchResult( null, false ); } /** diff --git a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/MetadataTransferTest.java b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/MetadataTransferTest.java index ed7f04b48..8ed576788 100644 --- a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/MetadataTransferTest.java +++ b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/MetadataTransferTest.java @@ -31,6 +31,7 @@ import org.apache.archiva.policies.CachedFailuresPolicy; import org.apache.archiva.policies.ChecksumPolicy; import org.apache.archiva.policies.ReleasesPolicy; import org.apache.archiva.policies.SnapshotsPolicy; +import org.apache.archiva.proxy.model.ProxyFetchResult; import org.apache.archiva.repository.metadata.MetadataTools; import org.apache.archiva.repository.metadata.RepositoryMetadataException; import org.apache.archiva.repository.metadata.RepositoryMetadataWriter; @@ -124,9 +125,9 @@ public class MetadataTransferTest ProjectReference metadata = createProjectReference( requestedResource ); - File downloadedFile = proxyHandler.fetchMetatadaFromProxies( managedDefaultRepository, + File downloadedFile = proxyHandler.fetchMetadataFromProxies( managedDefaultRepository, managedDefaultRepository.toMetadataPath( - metadata ) ); + metadata ) ).getFile(); assertNull( "Should not have downloaded a file.", downloadedFile ); assertNoTempFiles( expectedFile ); @@ -987,9 +988,9 @@ public class MetadataTransferTest ProjectReference metadata = createProjectReference( requestedResource ); - File downloadedFile = proxyHandler.fetchMetatadaFromProxies( managedDefaultRepository, + File downloadedFile = proxyHandler.fetchMetadataFromProxies( managedDefaultRepository, managedDefaultRepository.toMetadataPath( - metadata ) ); + metadata ) ).getFile(); assertNotNull( "Should have downloaded a file.", downloadedFile ); assertNoTempFiles( expectedFile ); @@ -1013,9 +1014,9 @@ public class MetadataTransferTest File expectedFile = new File( managedDefaultDir, requestedResource ); ProjectReference metadata = createProjectReference( requestedResource ); - File downloadedFile = proxyHandler.fetchMetatadaFromProxies( managedDefaultRepository, + File downloadedFile = proxyHandler.fetchMetadataFromProxies( managedDefaultRepository, managedDefaultRepository.toMetadataPath( - metadata ) ); + metadata ) ).getFile(); assertNull( downloadedFile ); assertNoTempFiles( expectedFile ); @@ -1034,9 +1035,9 @@ public class MetadataTransferTest VersionedReference metadata = createVersionedReference( requestedResource ); - File downloadedFile = proxyHandler.fetchMetatadaFromProxies( managedDefaultRepository, + File downloadedFile = proxyHandler.fetchMetadataFromProxies( managedDefaultRepository, managedDefaultRepository.toMetadataPath( - metadata ) ); + metadata ) ).getFile(); assertNotNull( "Should have downloaded a file.", downloadedFile ); assertNoTempFiles( expectedFile ); @@ -1060,9 +1061,9 @@ public class MetadataTransferTest File expectedFile = new File( managedDefaultDir, requestedResource ); VersionedReference metadata = createVersionedReference( requestedResource ); - File downloadedFile = proxyHandler.fetchMetatadaFromProxies( managedDefaultRepository, + File downloadedFile = proxyHandler.fetchMetadataFromProxies( managedDefaultRepository, managedDefaultRepository.toMetadataPath( - metadata ) ); + metadata ) ).getFile(); assertNull( downloadedFile ); assertNoTempFiles( expectedFile ); diff --git a/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/ArchivaDavResource.java b/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/ArchivaDavResource.java index f9a4d9e51..074d13bda 100644 --- a/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/ArchivaDavResource.java +++ b/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/ArchivaDavResource.java @@ -442,13 +442,13 @@ public class ArchivaDavResource } } - private void triggerAuditEvent( DavResource member, String event ) + private void triggerAuditEvent( DavResource member, String action ) throws DavException { String path = logicalResource + "/" + member.getDisplayName(); ArchivaDavResource resource = checkDavResourceIsArchivaDavResource( member ); - AuditEvent auditEvent = new AuditEvent( locator.getRepositoryId(), resource.principal, path, event ); + AuditEvent auditEvent = new AuditEvent( locator.getRepositoryId(), resource.principal, path, action ); auditEvent.setRemoteIP( resource.remoteAddr ); for ( AuditListener listener : auditListeners ) diff --git a/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/ArchivaDavResourceFactory.java b/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/ArchivaDavResourceFactory.java index 1e225a60a..31e2b881f 100644 --- a/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/ArchivaDavResourceFactory.java +++ b/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/ArchivaDavResourceFactory.java @@ -47,6 +47,7 @@ import org.apache.archiva.model.ArchivaRepositoryMetadata; import org.apache.archiva.model.ArtifactReference; import org.apache.archiva.policies.ProxyDownloadException; import org.apache.archiva.proxy.model.RepositoryProxyConnectors; +import org.apache.archiva.proxy.model.ProxyFetchResult; import org.apache.archiva.redback.authentication.AuthenticationException; import org.apache.archiva.redback.authentication.AuthenticationResult; import org.apache.archiva.redback.authorization.AuthorizationException; @@ -626,9 +627,7 @@ public class ArchivaDavResourceFactory { boolean previouslyExisted = resourceFile.exists(); - // Attempt to fetch the resource from any defined proxy. - boolean fromProxy = - fetchContentFromProxies( managedRepositoryContent, request, logicalResource ); + boolean fromProxy = fetchContentFromProxies( managedRepositoryContent, request, logicalResource ); // At this point the incoming request can either be in default or // legacy layout format. @@ -656,14 +655,14 @@ public class ArchivaDavResourceFactory if ( fromProxy ) { - String event = ( previouslyExisted ? AuditEvent.MODIFY_FILE : AuditEvent.CREATE_FILE ) + String action = ( previouslyExisted ? AuditEvent.MODIFY_FILE : AuditEvent.CREATE_FILE ) + PROXIED_SUFFIX; log.debug( "Proxied artifact '{}' in repository '{}' (current user '{}')", resourceFile.getName(), managedRepositoryContent.getId(), activePrincipal ); triggerAuditEvent( request.getRemoteAddr(), archivaLocator.getRepositoryId(), - logicalResource.getPath(), event, activePrincipal ); + logicalResource.getPath(), action, activePrincipal ); } if ( !resourceFile.exists() ) @@ -793,7 +792,7 @@ public class ArchivaDavResourceFactory // Is it a Metadata resource? if ( repositoryRequest.isDefault( path ) && repositoryRequest.isMetadata( path ) ) { - return connectors.fetchMetatadaFromProxies( managedRepository, path ) != null; + return connectors.fetchMetadataFromProxies( managedRepository, path ).isModified(); } // Is it an Archetype Catalog? diff --git a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/ArchivaDavResourceFactoryTest.java b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/ArchivaDavResourceFactoryTest.java index b8e460e26..edb8ab3d4 100644 --- a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/ArchivaDavResourceFactoryTest.java +++ b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/ArchivaDavResourceFactoryTest.java @@ -33,6 +33,7 @@ import org.apache.archiva.configuration.ArchivaConfiguration; import org.apache.archiva.configuration.Configuration; import org.apache.archiva.configuration.RepositoryGroupConfiguration; import org.apache.archiva.proxy.DefaultRepositoryProxyConnectors; +import org.apache.archiva.proxy.model.ProxyFetchResult; import org.apache.archiva.repository.ManagedRepositoryContent; import org.apache.archiva.repository.RepositoryContentFactory; import org.apache.archiva.repository.content.legacy.LegacyPathParser; @@ -645,7 +646,7 @@ public class ArchivaDavResourceFactoryTest extends DefaultRepositoryProxyConnectors { @Override - public File fetchMetatadaFromProxies( ManagedRepositoryContent repository, String logicalPath ) + public ProxyFetchResult fetchMetadataFromProxies( ManagedRepositoryContent repository, String logicalPath ) { File target = new File( repository.getRepoRoot(), logicalPath ); try @@ -657,7 +658,7 @@ public class ArchivaDavResourceFactoryTest } - return target; + return new ProxyFetchResult( target, true ); } } } |