]> source.dussan.org Git - archiva.git/commitdiff
[MRM-1355] fix username for audit log
authorBrett Porter <brett@apache.org>
Thu, 4 Mar 2010 05:18:44 +0000 (05:18 +0000)
committerBrett Porter <brett@apache.org>
Thu, 4 Mar 2010 05:18:44 +0000 (05:18 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/branches/archiva-1.3.x@918857 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/ArchivaDavResource.java
archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/ArchivaDavResourceFactory.java
archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/RepositoryServletSecurityTest.java

index 846c7d6d50bd327f9b6fdb17f5b5d722361a570a..0b04010094d9b895444ca3b41a98b66a0b201f16 100644 (file)
@@ -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 );
index 44260be7501869751c708378c45ba4033ba3664b..5863483f49c9704d7e501813e6b350fec588d599 100644 (file)
@@ -800,6 +800,11 @@ public class ArchivaDavResourceFactory
         return archivaLocator;
     }
 
+    public ArchivaAuditLogsDao getAuditLogsDao()
+    {
+        return auditLogsDao;
+    }
+
     private static class LogicalResource
     {
         private String path;
index f4119959fe52d67054af9e537918c0db3ca6b04a..5658037d220ba4f66ab0c54212ebbad9cc01e49f 100644 (file)
@@ -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<ArchivaAuditLogs> auditLogs = auditLogsDao.queryAuditLogs( new MostRecentArchivaAuditLogsConstraint() );
+        assertEquals( "admin", auditLogs.get( 0 ).getUsername() );
     }
 
     // test get with invalid user, and guest has read access to repo