From: Brett Porter Date: Thu, 4 Mar 2010 05:18:44 +0000 (+0000) Subject: [MRM-1355] fix username for audit log X-Git-Tag: archiva-1.3.1~19 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=bc267adc0731b50d2e6264f6024f0f1dbbcb87ca;p=archiva.git [MRM-1355] fix username for audit log git-svn-id: https://svn.apache.org/repos/asf/archiva/branches/archiva-1.3.x@918857 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/ArchivaDavResource.java b/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/ArchivaDavResource.java index 846c7d6d5..0b0401009 100644 --- a/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/ArchivaDavResource.java +++ b/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/ArchivaDavResource.java @@ -71,14 +71,6 @@ import org.joda.time.format.ISODateTimeFormat; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import javax.servlet.http.HttpServletResponse; - /** */ public class ArchivaDavResource @@ -427,8 +419,9 @@ public class ArchivaDavResource throws DavException { String path = logicalResource + "/" + member.getDisplayName(); - - triggerAuditEvent( checkDavResourceIsArchivaDavResource( member ).remoteAddr, locator.getRepositoryId(), path, + + ArchivaDavResource resource = checkDavResourceIsArchivaDavResource( member ); + triggerAuditEvent( resource.remoteAddr, resource.principal, locator.getRepositoryId(), path, event ); } @@ -447,13 +440,13 @@ public class ArchivaDavResource { FileUtils.moveDirectory( getLocalResource(), resource.getLocalResource() ); - triggerAuditEvent( remoteAddr, locator.getRepositoryId(), logicalResource, AuditEvent.MOVE_DIRECTORY ); + triggerAuditEvent( remoteAddr, principal, locator.getRepositoryId(), logicalResource, AuditEvent.MOVE_DIRECTORY ); } else { FileUtils.moveFile( getLocalResource(), resource.getLocalResource() ); - triggerAuditEvent( remoteAddr, locator.getRepositoryId(), logicalResource, AuditEvent.MOVE_FILE ); + triggerAuditEvent( remoteAddr, principal, locator.getRepositoryId(), logicalResource, AuditEvent.MOVE_FILE ); } log.debug( ( isCollection() ? "Directory '" : "File '" ) + getLocalResource().getName() + "' moved to '" + @@ -485,13 +478,13 @@ public class ArchivaDavResource { FileUtils.copyDirectory( getLocalResource(), resource.getLocalResource() ); - triggerAuditEvent( remoteAddr, locator.getRepositoryId(), logicalResource, AuditEvent.COPY_DIRECTORY ); + triggerAuditEvent( remoteAddr, principal, locator.getRepositoryId(), logicalResource, AuditEvent.COPY_DIRECTORY ); } else { FileUtils.copyFile( getLocalResource(), resource.getLocalResource() ); - triggerAuditEvent( remoteAddr, locator.getRepositoryId(), logicalResource, AuditEvent.COPY_FILE ); + triggerAuditEvent( remoteAddr, principal, locator.getRepositoryId(), logicalResource, AuditEvent.COPY_FILE ); } log.debug( ( isCollection() ? "Directory '" : "File '" ) + getLocalResource().getName() + "' copied to '" + destination + "' (current user '" + this.principal + "')" ); @@ -658,7 +651,8 @@ public class ArchivaDavResource return (ArchivaDavResource) resource; } - private void triggerAuditEvent( String remoteIP, String repositoryId, String resource, String action ) + private void triggerAuditEvent( String remoteIP, String principal, String repositoryId, String resource, + String action ) { AuditEvent event = new AuditEvent( repositoryId, principal, resource, action ); event.setRemoteIP( remoteIP ); diff --git a/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/ArchivaDavResourceFactory.java b/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/ArchivaDavResourceFactory.java index 44260be75..5863483f4 100644 --- a/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/ArchivaDavResourceFactory.java +++ b/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/ArchivaDavResourceFactory.java @@ -800,6 +800,11 @@ public class ArchivaDavResourceFactory return archivaLocator; } + public ArchivaAuditLogsDao getAuditLogsDao() + { + return auditLogsDao; + } + private static class LogicalResource { private String path; diff --git a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/RepositoryServletSecurityTest.java b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/RepositoryServletSecurityTest.java index f4119959f..5658037d2 100644 --- a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/RepositoryServletSecurityTest.java +++ b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/RepositoryServletSecurityTest.java @@ -22,6 +22,7 @@ package org.apache.maven.archiva.webdav; import java.io.File; import java.io.IOException; import java.io.InputStream; +import java.util.List; import javax.servlet.http.HttpServletResponse; @@ -32,6 +33,10 @@ import org.apache.jackrabbit.webdav.DavSessionProvider; import org.apache.maven.archiva.configuration.ArchivaConfiguration; import org.apache.maven.archiva.configuration.Configuration; import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; +import org.apache.maven.archiva.database.ArchivaAuditLogsDao; +import org.apache.maven.archiva.database.constraints.MostRecentArchivaAuditLogsConstraint; +import org.apache.maven.archiva.model.ArchivaAuditLogs; +import org.apache.maven.archiva.repository.audit.AuditLog; import org.apache.maven.archiva.security.ArchivaRoleConstants; import org.apache.maven.archiva.security.ServletAuthenticator; import org.codehaus.plexus.redback.authentication.AuthenticationException; @@ -376,6 +381,10 @@ public class RepositoryServletSecurityTest servletAuthControl.verify(); // assertEquals(HttpServletResponse.SC_CREATED, response.getResponseCode()); + + ArchivaAuditLogsDao auditLogsDao = archivaDavResourceFactory.getAuditLogsDao(); + List auditLogs = auditLogsDao.queryAuditLogs( new MostRecentArchivaAuditLogsConstraint() ); + assertEquals( "admin", auditLogs.get( 0 ).getUsername() ); } // test get with invalid user, and guest has read access to repo