mirror of https://github.com/apache/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
This commit is contained in:
parent
d40d925272
commit
bc267adc07
|
@ -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 );
|
||||
|
|
|
@ -800,6 +800,11 @@ public class ArchivaDavResourceFactory
|
|||
return archivaLocator;
|
||||
}
|
||||
|
||||
public ArchivaAuditLogsDao getAuditLogsDao()
|
||||
{
|
||||
return auditLogsDao;
|
||||
}
|
||||
|
||||
private static class LogicalResource
|
||||
{
|
||||
private String path;
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue