[MRM-1093] Log configuration and repository changes made.

Submitted by: Jevica Arianne B. Zurbano (applied with modifications and other refactoring)


git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@756563 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Porter 2009-03-20 16:12:10 +00:00
parent 9bd751e3d5
commit bf34387459
24 changed files with 320 additions and 206 deletions

View File

@ -24,8 +24,12 @@ import java.io.FilenameFilter;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.maven.archiva.model.ArchivaArtifact; import org.apache.maven.archiva.model.ArchivaArtifact;
import org.apache.maven.archiva.model.ArtifactReference; import org.apache.maven.archiva.model.ArtifactReference;
import org.apache.maven.archiva.repository.audit.AuditEvent;
import org.apache.maven.archiva.repository.ManagedRepositoryContent; import org.apache.maven.archiva.repository.ManagedRepositoryContent;
import org.apache.maven.archiva.repository.events.RepositoryListener; import org.apache.maven.archiva.repository.events.RepositoryListener;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -44,6 +48,10 @@ public abstract class AbstractRepositoryPurge
protected final List<RepositoryListener> listeners; protected final List<RepositoryListener> listeners;
private Logger logger = LoggerFactory.getLogger( "org.apache.archiva.AuditLog" );
private static final char DELIM = ' ';
public AbstractRepositoryPurge( ManagedRepositoryContent repository, List<RepositoryListener> listeners ) public AbstractRepositoryPurge( ManagedRepositoryContent repository, List<RepositoryListener> listeners )
{ {
this.repository = repository; this.repository = repository;
@ -101,6 +109,7 @@ public abstract class AbstractRepositoryPurge
// TODO: this needs to be logged // TODO: this needs to be logged
artifactFile.delete(); artifactFile.delete();
triggerAuditEvent( repository.getRepository().getId(), ArtifactReference.toKey( reference ), AuditEvent.PURGE_ARTIFACT );
purgeSupportFiles( artifactFile ); purgeSupportFiles( artifactFile );
} }
} }
@ -133,9 +142,19 @@ public abstract class AbstractRepositoryPurge
{ {
if ( file.exists() && file.isFile() ) if ( file.exists() && file.isFile() )
{ {
String fileName = file.getName();
file.delete(); file.delete();
// TODO: log that it was deleted // TODO: log that it was deleted
triggerAuditEvent( repository.getRepository().getId(), fileName, AuditEvent.PURGE_FILE );
} }
} }
} }
private void triggerAuditEvent( String repoId, String resource, String action )
{
String msg = repoId + DELIM + "<system-purge>" + DELIM + "<system>" + DELIM + '\"' + resource + '\"' +
DELIM + '\"' + action + '\"';
logger.info( msg );
}
} }

View File

@ -32,6 +32,10 @@ import org.apache.maven.archiva.model.RepositoryProblem;
import org.apache.maven.archiva.repository.ManagedRepositoryContent; import org.apache.maven.archiva.repository.ManagedRepositoryContent;
import org.apache.maven.archiva.repository.RepositoryContentFactory; import org.apache.maven.archiva.repository.RepositoryContentFactory;
import org.apache.maven.archiva.repository.RepositoryException; import org.apache.maven.archiva.repository.RepositoryException;
import org.apache.maven.archiva.repository.audit.AuditEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List; import java.util.List;
import java.io.File; import java.io.File;
@ -75,6 +79,10 @@ public class DatabaseCleanupRemoveArtifactConsumer
*/ */
private RepositoryContentFactory repositoryFactory; private RepositoryContentFactory repositoryFactory;
private Logger logger = LoggerFactory.getLogger( "org.apache.archiva.AuditLog" );
private static final char DELIM = ' ';
public void beginScan() public void beginScan()
{ {
// TODO Auto-generated method stub // TODO Auto-generated method stub
@ -105,6 +113,8 @@ public class DatabaseCleanupRemoveArtifactConsumer
{ {
artifactDAO.deleteArtifact( artifact ); artifactDAO.deleteArtifact( artifact );
triggerAuditEvent( repositoryContent.getRepository().getId(), artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getVersion(), AuditEvent.REMOVE_SCANNED );
// Remove all repository problems related to this artifact // Remove all repository problems related to this artifact
Constraint artifactConstraint = new RepositoryProblemByArtifactConstraint( artifact ); Constraint artifactConstraint = new RepositoryProblemByArtifactConstraint( artifact );
List<RepositoryProblem> repositoryProblems = List<RepositoryProblem> repositoryProblems =
@ -159,4 +169,12 @@ public class DatabaseCleanupRemoveArtifactConsumer
{ {
this.repositoryFactory = repositoryFactory; this.repositoryFactory = repositoryFactory;
} }
private void triggerAuditEvent( String repoId, String resource, String action )
{
String msg = repoId + DELIM + "<db-scan>" + DELIM + "<system>" + DELIM + '\"' + resource + '\"' +
DELIM + '\"' + action + '\"';
logger.info( msg );
}
} }

View File

@ -46,6 +46,52 @@ public class AuditEvent
public static final String UPLOAD_FILE = "Uploaded File"; public static final String UPLOAD_FILE = "Uploaded File";
public static final String ADD_LEGACY_PATH = "Added Legacy Artifact Path";
public static final String REMOVE_LEGACY_PATH = "Removed Legacy Artifact Path";
public static final String PURGE_ARTIFACT = "Purged Artifact";
public static final String PURGE_FILE = "Purged Support File";
public static final String REMOVE_SCANNED = "Removed in Filesystem";
// configuration events
public static final String ADD_MANAGED_REPO = "Added Managed Repository";
public static final String MODIFY_MANAGED_REPO = "Updated Managed Repository";
public static final String DELETE_MANAGED_REPO = "Deleted Managed Repository";
public static final String ADD_REMOTE_REPO = "Added Remote Repository";
public static final String MODIFY_REMOTE_REPO = "Updated Remote Repository";
public static final String DELETE_REMOTE_REPO = "Deleted Remote Repository";
public static final String ADD_REPO_GROUP = "Added Repository Group";
public static final String DELETE_REPO_GROUP = "Deleted Repository Group";
public static final String ADD_REPO_TO_GROUP = "Added Repository to Group";
public static final String DELETE_REPO_FROM_GROUP = "Deleted Repository from Group";
public static final String ENABLE_REPO_CONSUMER = "Enabled Content Consumer";
public static final String DISABLE_REPO_CONSUMER = "Disabled Content Consumer";
public static final String ENABLE_DB_CONSUMER = "Enabled Database Consumer";
public static final String DISABLE_DB_CONSUMER = "Disabled Database Consumer";
public static final String ADD_PATTERN = "Added File Type Pattern";
public static final String REMOVE_PATTERN = "Removed File Type Pattern";
public static final String DB_SCHEDULE = "Modified Scanning Schedule";
private String repositoryId; private String repositoryId;
private String userId; private String userId;
@ -69,6 +115,16 @@ public class AuditEvent
this.action = action; this.action = action;
} }
public AuditEvent( String user, String resource, String action )
{
this( null, user, resource, action );
}
public AuditEvent( String principal, String action2 )
{
this( null, principal, action2 );
}
public String getRepositoryId() public String getRepositoryId()
{ {
return repositoryId; return repositoryId;

View File

@ -26,31 +26,35 @@ import org.slf4j.LoggerFactory;
* AuditLog - Audit Log. * AuditLog - Audit Log.
* *
* @version $Id$ * @version $Id$
* * @plexus.component role="org.apache.maven.archiva.repository.audit.AuditListener" role-hint="logging"
* @plexus.component role="org.apache.maven.archiva.repository.audit.AuditListener"
* role-hint="logging"
*/ */
public class AuditLog public class AuditLog
implements AuditListener implements AuditListener
{ {
public static final Logger logger = LoggerFactory.getLogger( "org.apache.archiva.AuditLog" ); public static final Logger logger = LoggerFactory.getLogger( "org.apache.archiva.AuditLog" );
private static final String NONE = "-";
private static final char DELIM = ' '; private static final char DELIM = ' ';
/** /**
* Creates a log message in the following format ... * Creates a log message in the following format ...
*
* "{repository_id} {user_id} {remote_ip} \"{resource}\" \"{action}\"" * "{repository_id} {user_id} {remote_ip} \"{resource}\" \"{action}\""
*/ */
public void auditEvent( AuditEvent event ) public void auditEvent( AuditEvent event )
{ {
StringBuffer msg = new StringBuffer(); StringBuffer msg = new StringBuffer();
msg.append( event.getRepositoryId() ).append( DELIM ); msg.append( checkNull( event.getRepositoryId() ) ).append( DELIM );
msg.append( event.getUserId() ).append( DELIM ); msg.append( event.getUserId() ).append( DELIM );
msg.append( event.getRemoteIP() ).append( DELIM ); msg.append( event.getRemoteIP() ).append( DELIM );
msg.append( '\"' ).append( event.getResource() ).append( '\"' ).append( DELIM ); msg.append( '\"' ).append( checkNull( event.getResource() ) ).append( '\"' ).append( DELIM );
msg.append( '\"' ).append( event.getAction() ).append( '\"' ); msg.append( '\"' ).append( event.getAction() ).append( '\"' );
logger.info( msg.toString() ); logger.info( msg.toString() );
} }
private String checkNull( String s )
{
return s != null ? s : NONE;
}
} }

View File

@ -30,11 +30,15 @@ import org.codehaus.plexus.redback.users.UserManager;
* ArchivaXworkUser * ArchivaXworkUser
* *
* @version $Id$ * @version $Id$
* @plexus.component role="org.apache.maven.archiva.security.ArchivaXworkUser"
*/ */
public class ArchivaXworkUser public final class ArchivaXworkUser
{ {
public String getActivePrincipal( Map<String, ?> sessionMap ) private ArchivaXworkUser()
{
// no touchy
}
public static String getActivePrincipal( Map<String, ?> sessionMap )
{ {
SecuritySession securitySession = SecuritySession securitySession =
(SecuritySession) sessionMap.get( SecuritySystemConstants.SECURITY_SESSION_KEY ); (SecuritySession) sessionMap.get( SecuritySystemConstants.SECURITY_SESSION_KEY );

View File

@ -22,7 +22,6 @@ package org.apache.maven.archiva.web.action;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import com.opensymphony.xwork2.ActionContext;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.apache.maven.archiva.database.ArchivaDatabaseException; import org.apache.maven.archiva.database.ArchivaDatabaseException;
@ -53,11 +52,6 @@ public class BrowseAction
*/ */
private UserRepositories userRepositories; private UserRepositories userRepositories;
/**
* @plexus.requirement
*/
private ArchivaXworkUser archivaXworkUser;
private BrowsingResults results; private BrowsingResults results;
private String groupId; private String groupId;
@ -209,12 +203,6 @@ public class BrowseAction
} }
} }
@SuppressWarnings("unchecked")
private String getPrincipal()
{
return archivaXworkUser.getActivePrincipal( ActionContext.getContext().getSession() );
}
private List<String> getObservableRepos() private List<String> getObservableRepos()
{ {
try try

View File

@ -48,7 +48,6 @@ import org.apache.maven.archiva.repository.RepositoryContentFactory;
import org.apache.maven.archiva.repository.RepositoryException; import org.apache.maven.archiva.repository.RepositoryException;
import org.apache.maven.archiva.repository.RepositoryNotFoundException; import org.apache.maven.archiva.repository.RepositoryNotFoundException;
import org.apache.maven.archiva.repository.audit.AuditEvent; import org.apache.maven.archiva.repository.audit.AuditEvent;
import org.apache.maven.archiva.repository.audit.AuditListener;
import org.apache.maven.archiva.repository.audit.Auditable; import org.apache.maven.archiva.repository.audit.Auditable;
import org.apache.maven.archiva.repository.metadata.MetadataTools; import org.apache.maven.archiva.repository.metadata.MetadataTools;
import org.apache.maven.archiva.repository.metadata.RepositoryMetadataException; import org.apache.maven.archiva.repository.metadata.RepositoryMetadataException;
@ -56,12 +55,9 @@ import org.apache.maven.archiva.repository.metadata.RepositoryMetadataReader;
import org.apache.maven.archiva.repository.metadata.RepositoryMetadataWriter; import org.apache.maven.archiva.repository.metadata.RepositoryMetadataWriter;
import org.apache.maven.archiva.security.AccessDeniedException; import org.apache.maven.archiva.security.AccessDeniedException;
import org.apache.maven.archiva.security.ArchivaSecurityException; import org.apache.maven.archiva.security.ArchivaSecurityException;
import org.apache.maven.archiva.security.ArchivaXworkUser;
import org.apache.maven.archiva.security.PrincipalNotFoundException; import org.apache.maven.archiva.security.PrincipalNotFoundException;
import org.apache.maven.archiva.security.UserRepositories; import org.apache.maven.archiva.security.UserRepositories;
import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.Preparable; import com.opensymphony.xwork2.Preparable;
import com.opensymphony.xwork2.Validateable; import com.opensymphony.xwork2.Validateable;
@ -74,11 +70,6 @@ public class DeleteArtifactAction
extends PlexusActionSupport extends PlexusActionSupport
implements Validateable, Preparable, Auditable implements Validateable, Preparable, Auditable
{ {
/**
* @plexus.requirement
*/
private ArchivaXworkUser archivaXworkUser;
/** /**
* The groupId of the artifact to be deleted. * The groupId of the artifact to be deleted.
*/ */
@ -129,11 +120,6 @@ public class DeleteArtifactAction
*/ */
private DatabaseConsumers databaseConsumers; private DatabaseConsumers databaseConsumers;
/**
* @plexus.requirement role="org.apache.maven.archiva.repository.audit.AuditListener"
*/
private List<AuditListener> auditListeners = new ArrayList<AuditListener>();
private ChecksumAlgorithm[] algorithms = new ChecksumAlgorithm[] { ChecksumAlgorithm.SHA1, ChecksumAlgorithm.MD5 }; private ChecksumAlgorithm[] algorithms = new ChecksumAlgorithm[] { ChecksumAlgorithm.SHA1, ChecksumAlgorithm.MD5 };
public String getGroupId() public String getGroupId()
@ -271,7 +257,7 @@ public class DeleteArtifactAction
"Artifact \'" + groupId + ":" + artifactId + ":" + version + "Artifact \'" + groupId + ":" + artifactId + ":" + version +
"\' was successfully deleted from repository \'" + repositoryId + "\'"; "\' was successfully deleted from repository \'" + repositoryId + "\'";
triggerAuditEvent( getPrincipal(), repositoryId, groupId + ":" + artifactId + ":" + version, triggerAuditEvent( repositoryId, groupId + ":" + artifactId + ":" + version,
AuditEvent.REMOVE_FILE ); AuditEvent.REMOVE_FILE );
addActionMessage( msg ); addActionMessage( msg );
@ -296,12 +282,6 @@ public class DeleteArtifactAction
} }
} }
@SuppressWarnings("unchecked")
private String getPrincipal()
{
return archivaXworkUser.getActivePrincipal( ActionContext.getContext().getSession() );
}
private File getMetadata( String targetPath ) private File getMetadata( String targetPath )
{ {
String artifactPath = targetPath.substring( 0, targetPath.lastIndexOf( File.separatorChar ) ); String artifactPath = targetPath.substring( 0, targetPath.lastIndexOf( File.separatorChar ) );
@ -403,21 +383,6 @@ public class DeleteArtifactAction
} }
} }
public void addAuditListener( AuditListener listener )
{
this.auditListeners.add( listener );
}
public void clearAuditListeners()
{
this.auditListeners.clear();
}
public void removeAuditListener( AuditListener listener )
{
this.auditListeners.remove( listener );
}
private List<String> getManagableRepos() private List<String> getManagableRepos()
{ {
try try
@ -439,15 +404,4 @@ public class DeleteArtifactAction
} }
return Collections.emptyList(); return Collections.emptyList();
} }
private void triggerAuditEvent( String user, String repositoryId, String resource, String action )
{
AuditEvent event = new AuditEvent( repositoryId, user, resource, action );
event.setRemoteIP( ServletActionContext.getRequest().getRemoteAddr() );
for ( AuditListener listener : auditListeners )
{
listener.auditEvent( event );
}
}
} }

View File

@ -19,12 +19,20 @@ package org.apache.maven.archiva.web.action;
* under the License. * under the License.
*/ */
import java.util.ArrayList;
import java.util.List;
import java.util.Map; import java.util.Map;
import org.apache.maven.archiva.repository.audit.AuditEvent;
import org.apache.maven.archiva.repository.audit.AuditListener;
import org.apache.maven.archiva.repository.audit.Auditable;
import org.apache.maven.archiva.security.ArchivaXworkUser;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.interceptor.SessionAware; import org.apache.struts2.interceptor.SessionAware;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport; import com.opensymphony.xwork2.ActionSupport;
/** /**
@ -32,15 +40,74 @@ import com.opensymphony.xwork2.ActionSupport;
*/ */
public abstract class PlexusActionSupport public abstract class PlexusActionSupport
extends ActionSupport extends ActionSupport
implements SessionAware implements SessionAware, Auditable
{ {
protected Map<?, ?> session; protected Map<?, ?> session;
protected Logger log = LoggerFactory.getLogger( getClass() ); protected Logger log = LoggerFactory.getLogger( getClass() );
/**
* @plexus.requirement role="org.apache.maven.archiva.repository.audit.AuditListener"
*/
private List<AuditListener> auditListeners = new ArrayList<AuditListener>();
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void setSession( Map map ) public void setSession( Map map )
{ {
this.session = map; this.session = map;
} }
public void addAuditListener( AuditListener listener )
{
this.auditListeners.add( listener );
}
public void clearAuditListeners()
{
this.auditListeners.clear();
}
public void removeAuditListener( AuditListener listener )
{
this.auditListeners.remove( listener );
}
protected void triggerAuditEvent( String repositoryId, String resource, String action )
{
AuditEvent event = new AuditEvent( repositoryId, getPrincipal(), resource, action );
event.setRemoteIP( ServletActionContext.getRequest().getRemoteAddr() );
for ( AuditListener listener : auditListeners )
{
listener.auditEvent( event );
}
}
protected void triggerAuditEvent( String resource, String action )
{
AuditEvent event = new AuditEvent( getPrincipal(), resource, action );
event.setRemoteIP( ServletActionContext.getRequest().getRemoteAddr() );
for ( AuditListener listener : auditListeners )
{
listener.auditEvent( event );
}
}
protected void triggerAuditEvent( String action )
{
AuditEvent event = new AuditEvent( getPrincipal(), action );
event.setRemoteIP( ServletActionContext.getRequest().getRemoteAddr() );
for ( AuditListener listener : auditListeners )
{
listener.auditEvent( event );
}
}
@SuppressWarnings( "unchecked" )
protected String getPrincipal()
{
return ArchivaXworkUser.getActivePrincipal( ActionContext.getContext().getSession() );
}
} }

View File

@ -45,14 +45,12 @@ import org.apache.maven.archiva.database.constraints.UniqueVersionConstraint;
import org.apache.maven.archiva.model.ArchivaArtifact; import org.apache.maven.archiva.model.ArchivaArtifact;
import org.apache.maven.archiva.security.AccessDeniedException; import org.apache.maven.archiva.security.AccessDeniedException;
import org.apache.maven.archiva.security.ArchivaSecurityException; import org.apache.maven.archiva.security.ArchivaSecurityException;
import org.apache.maven.archiva.security.ArchivaXworkUser;
import org.apache.maven.archiva.security.PrincipalNotFoundException; import org.apache.maven.archiva.security.PrincipalNotFoundException;
import org.apache.maven.archiva.security.UserRepositories; import org.apache.maven.archiva.security.UserRepositories;
import org.apache.struts2.ServletActionContext; import org.apache.struts2.ServletActionContext;
import org.springframework.web.context.WebApplicationContext; import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils; import org.springframework.web.context.support.WebApplicationContextUtils;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.Preparable; import com.opensymphony.xwork2.Preparable;
/** /**
@ -87,11 +85,6 @@ public class SearchAction
*/ */
private UserRepositories userRepositories; private UserRepositories userRepositories;
/**
* @plexus.requirement
*/
private ArchivaXworkUser archivaXworkUser;
private static final String RESULTS = "results"; private static final String RESULTS = "results";
private static final String ARTIFACT = "artifact"; private static final String ARTIFACT = "artifact";
@ -400,12 +393,6 @@ public class SearchAction
return INPUT; return INPUT;
} }
@SuppressWarnings("unchecked")
private String getPrincipal()
{
return archivaXworkUser.getActivePrincipal( ActionContext.getContext().getSession() );
}
private List<String> getObservableRepos() private List<String> getObservableRepos()
{ {
try try
@ -663,16 +650,6 @@ public class SearchAction
this.userRepositories = userRepositories; this.userRepositories = userRepositories;
} }
public ArchivaXworkUser getArchivaXworkUser()
{
return archivaXworkUser;
}
public void setArchivaXworkUser( ArchivaXworkUser archivaXworkUser )
{
this.archivaXworkUser = archivaXworkUser;
}
public Map<String, String> getSearchFields() public Map<String, String> getSearchFields()
{ {
return searchFields; return searchFields;

View File

@ -34,9 +34,7 @@ import org.apache.maven.archiva.security.AccessDeniedException;
import org.apache.maven.archiva.security.ArchivaSecurityException; import org.apache.maven.archiva.security.ArchivaSecurityException;
import org.apache.maven.archiva.security.PrincipalNotFoundException; import org.apache.maven.archiva.security.PrincipalNotFoundException;
import org.apache.maven.archiva.security.UserRepositories; import org.apache.maven.archiva.security.UserRepositories;
import org.apache.maven.archiva.security.ArchivaXworkUser;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.Validateable; import com.opensymphony.xwork2.Validateable;
/** /**
@ -62,13 +60,6 @@ public class ShowArtifactAction
*/ */
private UserRepositories userRepositories; private UserRepositories userRepositories;
/**
* @plexus.requirement
*/
private ArchivaXworkUser archivaXworkUser;
/* .\ Input Parameters \.________________________________________ */
private String groupId; private String groupId;
private String artifactId; private String artifactId;
@ -195,12 +186,6 @@ public class ShowArtifactAction
return SUCCESS; return SUCCESS;
} }
@SuppressWarnings("unchecked")
private String getPrincipal()
{
return archivaXworkUser.getActivePrincipal( ActionContext.getContext().getSession() );
}
private List<String> getObservableRepos() private List<String> getObservableRepos()
{ {
try try

View File

@ -48,7 +48,6 @@ import org.apache.maven.archiva.repository.RepositoryException;
import org.apache.maven.archiva.repository.RepositoryNotFoundException; import org.apache.maven.archiva.repository.RepositoryNotFoundException;
import org.apache.maven.archiva.repository.scanner.RepositoryContentConsumers; import org.apache.maven.archiva.repository.scanner.RepositoryContentConsumers;
import org.apache.maven.archiva.repository.audit.AuditEvent; import org.apache.maven.archiva.repository.audit.AuditEvent;
import org.apache.maven.archiva.repository.audit.AuditListener;
import org.apache.maven.archiva.repository.audit.Auditable; import org.apache.maven.archiva.repository.audit.Auditable;
import org.apache.maven.archiva.repository.metadata.MetadataTools; import org.apache.maven.archiva.repository.metadata.MetadataTools;
import org.apache.maven.archiva.repository.metadata.RepositoryMetadataException; import org.apache.maven.archiva.repository.metadata.RepositoryMetadataException;
@ -61,10 +60,7 @@ import org.apache.maven.archiva.security.AccessDeniedException;
import org.apache.maven.archiva.security.ArchivaSecurityException; import org.apache.maven.archiva.security.ArchivaSecurityException;
import org.apache.maven.archiva.security.PrincipalNotFoundException; import org.apache.maven.archiva.security.PrincipalNotFoundException;
import org.apache.maven.archiva.security.UserRepositories; import org.apache.maven.archiva.security.UserRepositories;
import org.apache.maven.archiva.security.ArchivaXworkUser;
import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.Preparable; import com.opensymphony.xwork2.Preparable;
import com.opensymphony.xwork2.Validateable; import com.opensymphony.xwork2.Validateable;
import org.apache.commons.io.FilenameUtils; import org.apache.commons.io.FilenameUtils;
@ -85,11 +81,6 @@ public class UploadAction
*/ */
private RepositoryContentConsumers consumers; private RepositoryContentConsumers consumers;
/**
* @plexus.requirement
*/
private ArchivaXworkUser archivaXworkUser;
/** /**
* The groupId of the artifact to be deployed. * The groupId of the artifact to be deployed.
*/ */
@ -155,11 +146,6 @@ public class UploadAction
*/ */
private RepositoryContentFactory repositoryFactory; private RepositoryContentFactory repositoryFactory;
/**
* @plexus.requirement role="org.apache.maven.archiva.repository.audit.AuditListener"
*/
private List<AuditListener> auditListeners = new ArrayList<AuditListener>();
private ChecksumAlgorithm[] algorithms = new ChecksumAlgorithm[] { ChecksumAlgorithm.SHA1, ChecksumAlgorithm.MD5 }; private ChecksumAlgorithm[] algorithms = new ChecksumAlgorithm[] { ChecksumAlgorithm.SHA1, ChecksumAlgorithm.MD5 };
private ProjectModelWriter pomWriter = new ProjectModel400Writer(); private ProjectModelWriter pomWriter = new ProjectModel400Writer();
@ -413,7 +399,7 @@ public class UploadAction
String msg = "Artifact \'" + groupId + ":" + artifactId + ":" + version + String msg = "Artifact \'" + groupId + ":" + artifactId + ":" + version +
"\' was successfully deployed to repository \'" + repositoryId + "\'"; "\' was successfully deployed to repository \'" + repositoryId + "\'";
triggerAuditEvent( getPrincipal(), repositoryId, groupId + ":" + artifactId + ":" + version, AuditEvent.UPLOAD_FILE ); triggerAuditEvent( repositoryId, groupId + ":" + artifactId + ":" + version, AuditEvent.UPLOAD_FILE );
addActionMessage( msg ); addActionMessage( msg );
@ -432,12 +418,6 @@ public class UploadAction
} }
} }
@SuppressWarnings("unchecked")
private String getPrincipal()
{
return archivaXworkUser.getActivePrincipal( ActionContext.getContext().getSession() );
}
private void copyFile( File sourceFile, File targetPath, String targetFilename ) private void copyFile( File sourceFile, File targetPath, String targetFilename )
throws IOException throws IOException
{ {
@ -584,21 +564,6 @@ public class UploadAction
} }
} }
public void addAuditListener( AuditListener listener )
{
this.auditListeners.add( listener );
}
public void clearAuditListeners()
{
this.auditListeners.clear();
}
public void removeAuditListener( AuditListener listener )
{
this.auditListeners.remove( listener );
}
private List<String> getManagableRepos() private List<String> getManagableRepos()
{ {
try try
@ -620,15 +585,4 @@ public class UploadAction
} }
return Collections.emptyList(); return Collections.emptyList();
} }
private void triggerAuditEvent( String user, String repositoryId, String resource, String action )
{
AuditEvent event = new AuditEvent( repositoryId, user, resource, action );
event.setRemoteIP( ServletActionContext.getRequest().getRemoteAddr() );
for ( AuditListener listener : auditListeners )
{
listener.auditEvent( event );
}
}
} }

View File

@ -28,6 +28,8 @@ import org.apache.maven.archiva.configuration.Configuration;
import org.apache.maven.archiva.configuration.DatabaseScanningConfiguration; import org.apache.maven.archiva.configuration.DatabaseScanningConfiguration;
import org.apache.maven.archiva.configuration.IndeterminateConfigurationException; import org.apache.maven.archiva.configuration.IndeterminateConfigurationException;
import org.apache.maven.archiva.database.updater.DatabaseConsumers; import org.apache.maven.archiva.database.updater.DatabaseConsumers;
import org.apache.maven.archiva.repository.audit.AuditEvent;
import org.apache.maven.archiva.repository.audit.Auditable;
import org.apache.maven.archiva.security.ArchivaRoleConstants; import org.apache.maven.archiva.security.ArchivaRoleConstants;
import org.apache.maven.archiva.web.action.PlexusActionSupport; import org.apache.maven.archiva.web.action.PlexusActionSupport;
import org.codehaus.plexus.redback.rbac.Resource; import org.codehaus.plexus.redback.rbac.Resource;
@ -46,7 +48,7 @@ import com.opensymphony.xwork2.Preparable;
*/ */
public class DatabaseAction public class DatabaseAction
extends PlexusActionSupport extends PlexusActionSupport
implements Preparable, SecureAction implements Preparable, SecureAction, Auditable
{ {
/** /**
* @plexus.requirement * @plexus.requirement
@ -103,23 +105,40 @@ public class DatabaseAction
public String updateUnprocessedConsumers() public String updateUnprocessedConsumers()
{ {
List<String> oldConsumers = archivaConfiguration.getConfiguration().getDatabaseScanning().getUnprocessedConsumers();
archivaConfiguration.getConfiguration().getDatabaseScanning().setUnprocessedConsumers( archivaConfiguration.getConfiguration().getDatabaseScanning().setUnprocessedConsumers(
enabledUnprocessedConsumers ); enabledUnprocessedConsumers );
filterAddedConsumers( oldConsumers, enabledUnprocessedConsumers );
filterRemovedConsumers( oldConsumers, enabledUnprocessedConsumers );
return saveConfiguration(); return saveConfiguration();
} }
public String updateCleanupConsumers() public String updateCleanupConsumers()
{ {
List<String> oldConsumers = archivaConfiguration.getConfiguration().getDatabaseScanning().getCleanupConsumers();
archivaConfiguration.getConfiguration().getDatabaseScanning().setCleanupConsumers( enabledCleanupConsumers ); archivaConfiguration.getConfiguration().getDatabaseScanning().setCleanupConsumers( enabledCleanupConsumers );
filterAddedConsumers( oldConsumers, enabledCleanupConsumers );
filterRemovedConsumers( oldConsumers, enabledCleanupConsumers );
return saveConfiguration(); return saveConfiguration();
} }
public String updateSchedule() public String updateSchedule()
{ {
String oldCron = archivaConfiguration.getConfiguration().getDatabaseScanning().getCronExpression();
archivaConfiguration.getConfiguration().getDatabaseScanning().setCronExpression( cron ); archivaConfiguration.getConfiguration().getDatabaseScanning().setCronExpression( cron );
if ( !oldCron.equals( cron ) )
{
triggerAuditEvent( AuditEvent.DB_SCHEDULE + " " + cron );
}
return saveConfiguration(); return saveConfiguration();
} }
@ -195,4 +214,26 @@ public class DatabaseAction
{ {
this.enabledCleanupConsumers = enabledCleanupConsumers; this.enabledCleanupConsumers = enabledCleanupConsumers;
} }
private void filterAddedConsumers( List<String> oldList, List<String> newList )
{
for ( String consumer : newList )
{
if ( !oldList.contains( consumer ) )
{
triggerAuditEvent( consumer, AuditEvent.ENABLE_DB_CONSUMER );
}
}
}
private void filterRemovedConsumers( List<String> oldList, List<String> newList )
{
for ( String consumer : oldList )
{
if ( !newList.contains( consumer ) )
{
triggerAuditEvent( consumer, AuditEvent.DISABLE_DB_CONSUMER );
}
}
}
} }

View File

@ -19,20 +19,23 @@ package org.apache.maven.archiva.web.action.admin.repositories;
* under the License. * under the License.
*/ */
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.apache.maven.archiva.configuration.ArchivaConfiguration; import org.apache.maven.archiva.configuration.ArchivaConfiguration;
import org.apache.maven.archiva.configuration.Configuration; import org.apache.maven.archiva.configuration.Configuration;
import org.apache.maven.archiva.configuration.IndeterminateConfigurationException; import org.apache.maven.archiva.configuration.IndeterminateConfigurationException;
import org.apache.maven.archiva.configuration.InvalidConfigurationException;
import org.apache.maven.archiva.configuration.ProxyConnectorConfiguration; import org.apache.maven.archiva.configuration.ProxyConnectorConfiguration;
import org.apache.maven.archiva.repository.audit.Auditable;
import org.apache.maven.archiva.security.ArchivaRoleConstants; import org.apache.maven.archiva.security.ArchivaRoleConstants;
import org.apache.maven.archiva.web.action.PlexusActionSupport;
import org.codehaus.plexus.redback.rbac.Resource; import org.codehaus.plexus.redback.rbac.Resource;
import org.codehaus.plexus.registry.RegistryException;
import org.codehaus.redback.integration.interceptor.SecureAction; import org.codehaus.redback.integration.interceptor.SecureAction;
import org.codehaus.redback.integration.interceptor.SecureActionBundle; import org.codehaus.redback.integration.interceptor.SecureActionBundle;
import org.codehaus.redback.integration.interceptor.SecureActionException; import org.codehaus.redback.integration.interceptor.SecureActionException;
import org.codehaus.plexus.registry.RegistryException;
import java.util.ArrayList;
import java.util.List;
import org.apache.maven.archiva.web.action.PlexusActionSupport;
/** /**
* Abstract AdminRepositories Action base. * Abstract AdminRepositories Action base.
@ -44,7 +47,7 @@ import org.apache.maven.archiva.web.action.PlexusActionSupport;
*/ */
public abstract class AbstractRepositoriesAdminAction public abstract class AbstractRepositoriesAdminAction
extends PlexusActionSupport extends PlexusActionSupport
implements SecureAction implements SecureAction, Auditable
{ {
/** /**
* @plexus.requirement * @plexus.requirement

View File

@ -24,6 +24,7 @@ import com.opensymphony.xwork2.Validateable;
import org.apache.maven.archiva.configuration.Configuration; import org.apache.maven.archiva.configuration.Configuration;
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
import org.apache.maven.archiva.repository.audit.AuditEvent;
import org.codehaus.plexus.redback.role.RoleManagerException; import org.codehaus.plexus.redback.role.RoleManagerException;
import org.codehaus.plexus.scheduler.CronExpressionValidator; import org.codehaus.plexus.scheduler.CronExpressionValidator;
import java.io.File; import java.io.File;
@ -86,6 +87,7 @@ public class AddManagedRepositoryAction
try try
{ {
addRepository( repository, configuration ); addRepository( repository, configuration );
triggerAuditEvent( repository.getId(), null, AuditEvent.ADD_MANAGED_REPO );
addRepositoryRoles( repository ); addRepositoryRoles( repository );
result = saveConfiguration( configuration ); result = saveConfiguration( configuration );
} }

View File

@ -24,6 +24,7 @@ import com.opensymphony.xwork2.Validateable;
import org.apache.maven.archiva.configuration.Configuration; import org.apache.maven.archiva.configuration.Configuration;
import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration; import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration;
import org.apache.maven.archiva.repository.audit.AuditEvent;
import org.codehaus.plexus.redback.role.RoleManagerException; import org.codehaus.plexus.redback.role.RoleManagerException;
import java.io.IOException; import java.io.IOException;
@ -66,6 +67,7 @@ public class AddRemoteRepositoryAction
try try
{ {
addRepository( repository, configuration ); addRepository( repository, configuration );
triggerAuditEvent( repository.getId(), null, AuditEvent.ADD_REMOTE_REPO );
result = saveConfiguration( configuration ); result = saveConfiguration( configuration );
} }
catch ( IOException e ) catch ( IOException e )

View File

@ -34,6 +34,7 @@ import org.apache.maven.archiva.database.constraints.RepositoryContentStatistics
import org.apache.maven.archiva.model.ArchivaArtifact; import org.apache.maven.archiva.model.ArchivaArtifact;
import org.apache.maven.archiva.model.ArchivaProjectModel; import org.apache.maven.archiva.model.ArchivaProjectModel;
import org.apache.maven.archiva.model.RepositoryContentStatistics; import org.apache.maven.archiva.model.RepositoryContentStatistics;
import org.apache.maven.archiva.repository.audit.AuditEvent;
import org.apache.maven.archiva.configuration.ProxyConnectorConfiguration; import org.apache.maven.archiva.configuration.ProxyConnectorConfiguration;
@ -107,6 +108,7 @@ public class DeleteManagedRepositoryAction
Configuration configuration = archivaConfiguration.getConfiguration(); Configuration configuration = archivaConfiguration.getConfiguration();
cleanupRepositoryData( existingRepository ); cleanupRepositoryData( existingRepository );
removeRepository( repoid, configuration ); removeRepository( repoid, configuration );
triggerAuditEvent( repoid, null, AuditEvent.DELETE_MANAGED_REPO );
result = saveConfiguration( configuration ); result = saveConfiguration( configuration );
if ( result.equals( SUCCESS ) ) if ( result.equals( SUCCESS ) )

View File

@ -25,6 +25,7 @@ import org.apache.commons.lang.StringUtils;
import org.apache.maven.archiva.configuration.Configuration; import org.apache.maven.archiva.configuration.Configuration;
import org.apache.maven.archiva.configuration.ProxyConnectorConfiguration; import org.apache.maven.archiva.configuration.ProxyConnectorConfiguration;
import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration; import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration;
import org.apache.maven.archiva.repository.audit.AuditEvent;
import java.util.List; import java.util.List;
@ -74,6 +75,7 @@ public class DeleteRemoteRepositoryAction
Configuration configuration = archivaConfiguration.getConfiguration(); Configuration configuration = archivaConfiguration.getConfiguration();
removeRepository( repoid, configuration ); removeRepository( repoid, configuration );
triggerAuditEvent( repoid, null, AuditEvent.DELETE_REMOTE_REPO );
result = saveConfiguration( configuration ); result = saveConfiguration( configuration );
cleanupRepositoryData( existingRepository ); cleanupRepositoryData( existingRepository );

View File

@ -24,6 +24,7 @@ import com.opensymphony.xwork2.Preparable;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.apache.maven.archiva.configuration.Configuration; import org.apache.maven.archiva.configuration.Configuration;
import org.apache.maven.archiva.configuration.RepositoryGroupConfiguration; import org.apache.maven.archiva.configuration.RepositoryGroupConfiguration;
import org.apache.maven.archiva.repository.audit.AuditEvent;
/** /**
* DeleteRepositoryGroupAction * DeleteRepositoryGroupAction
@ -70,6 +71,7 @@ public class DeleteRepositoryGroupAction
} }
config.removeRepositoryGroup( group ); config.removeRepositoryGroup( group );
triggerAuditEvent( AuditEvent.DELETE_REPO_GROUP + " " + repoGroupId );
return saveConfiguration( config ); return saveConfiguration( config );
} }

View File

@ -25,6 +25,7 @@ import com.opensymphony.xwork2.Validateable;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.apache.maven.archiva.configuration.Configuration; import org.apache.maven.archiva.configuration.Configuration;
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
import org.apache.maven.archiva.repository.audit.AuditEvent;
import org.codehaus.plexus.redback.role.RoleManagerException; import org.codehaus.plexus.redback.role.RoleManagerException;
import org.codehaus.plexus.scheduler.CronExpressionValidator; import org.codehaus.plexus.scheduler.CronExpressionValidator;
@ -111,6 +112,7 @@ public class EditManagedRepositoryAction
try try
{ {
addRepository( repository, configuration ); addRepository( repository, configuration );
triggerAuditEvent( repository.getId(), null, AuditEvent.MODIFY_MANAGED_REPO );
addRepositoryRoles( repository ); addRepositoryRoles( repository );
result = saveConfiguration( configuration ); result = saveConfiguration( configuration );
} }

View File

@ -24,6 +24,7 @@ import com.opensymphony.xwork2.Preparable;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.apache.maven.archiva.configuration.Configuration; import org.apache.maven.archiva.configuration.Configuration;
import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration; import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration;
import org.apache.maven.archiva.repository.audit.AuditEvent;
import org.codehaus.plexus.redback.role.RoleManagerException; import org.codehaus.plexus.redback.role.RoleManagerException;
import java.io.IOException; import java.io.IOException;
@ -81,6 +82,7 @@ public class EditRemoteRepositoryAction
try try
{ {
addRepository( repository, configuration ); addRepository( repository, configuration );
triggerAuditEvent( repository.getId(), null, AuditEvent.MODIFY_REMOTE_REPO );
result = saveConfiguration( configuration ); result = saveConfiguration( configuration );
} }
catch ( IOException e ) catch ( IOException e )

View File

@ -33,6 +33,7 @@ import org.apache.commons.lang.StringUtils;
import org.apache.maven.archiva.configuration.Configuration; import org.apache.maven.archiva.configuration.Configuration;
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
import org.apache.maven.archiva.configuration.RepositoryGroupConfiguration; import org.apache.maven.archiva.configuration.RepositoryGroupConfiguration;
import org.apache.maven.archiva.repository.audit.AuditEvent;
import org.apache.maven.archiva.web.util.ContextUtils; import org.apache.maven.archiva.web.util.ContextUtils;
/** /**
@ -130,6 +131,7 @@ public class RepositoryGroupsAction
} }
configuration.addRepositoryGroup( repositoryGroup ); configuration.addRepositoryGroup( repositoryGroup );
triggerAuditEvent( AuditEvent.ADD_REPO_GROUP + " " + repoGroupId );
return saveConfiguration( configuration ); return saveConfiguration( configuration );
} }
@ -158,6 +160,8 @@ public class RepositoryGroupsAction
group.addRepository( repoId ); group.addRepository( repoId );
config.addRepositoryGroup( group ); config.addRepositoryGroup( group );
triggerAuditEvent( repoId, null, AuditEvent.ADD_REPO_TO_GROUP + " " + repoGroupId );
return saveConfiguration( config ); return saveConfiguration( config );
} }
@ -186,6 +190,8 @@ public class RepositoryGroupsAction
group.removeRepository( repoId ); group.removeRepository( repoId );
config.addRepositoryGroup( group ); config.addRepositoryGroup( group );
triggerAuditEvent( repoId, null, AuditEvent.DELETE_REPO_FROM_GROUP + " " + repoGroupId );
return saveConfiguration( config ); return saveConfiguration( config );
} }

View File

@ -19,8 +19,11 @@ package org.apache.maven.archiva.web.action.admin.scanning;
* under the License. * under the License.
*/ */
import com.opensymphony.xwork2.Preparable; import java.util.ArrayList;
import com.opensymphony.xwork2.Validateable; import java.util.Collections;
import java.util.List;
import java.util.Map;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.apache.maven.archiva.configuration.ArchivaConfiguration; import org.apache.maven.archiva.configuration.ArchivaConfiguration;
@ -30,20 +33,19 @@ import org.apache.maven.archiva.configuration.IndeterminateConfigurationExceptio
import org.apache.maven.archiva.configuration.RepositoryScanningConfiguration; import org.apache.maven.archiva.configuration.RepositoryScanningConfiguration;
import org.apache.maven.archiva.configuration.functors.FiletypeSelectionPredicate; import org.apache.maven.archiva.configuration.functors.FiletypeSelectionPredicate;
import org.apache.maven.archiva.configuration.functors.FiletypeToMapClosure; import org.apache.maven.archiva.configuration.functors.FiletypeToMapClosure;
import org.apache.maven.archiva.repository.audit.AuditEvent;
import org.apache.maven.archiva.repository.audit.Auditable;
import org.apache.maven.archiva.repository.scanner.RepositoryContentConsumers; import org.apache.maven.archiva.repository.scanner.RepositoryContentConsumers;
import org.apache.maven.archiva.security.ArchivaRoleConstants; import org.apache.maven.archiva.security.ArchivaRoleConstants;
import org.apache.maven.archiva.web.action.PlexusActionSupport; import org.apache.maven.archiva.web.action.PlexusActionSupport;
import org.codehaus.plexus.redback.rbac.Resource; import org.codehaus.plexus.redback.rbac.Resource;
import org.codehaus.plexus.registry.RegistryException;
import org.codehaus.redback.integration.interceptor.SecureAction; import org.codehaus.redback.integration.interceptor.SecureAction;
import org.codehaus.redback.integration.interceptor.SecureActionBundle; import org.codehaus.redback.integration.interceptor.SecureActionBundle;
import org.codehaus.redback.integration.interceptor.SecureActionException; import org.codehaus.redback.integration.interceptor.SecureActionException;
import org.codehaus.plexus.registry.RegistryException;
import java.util.ArrayList; import com.opensymphony.xwork2.Preparable;
import java.util.Collections; import com.opensymphony.xwork2.Validateable;
import java.util.List;
import java.util.Map;
/** /**
* RepositoryScanningAction * RepositoryScanningAction
@ -53,7 +55,7 @@ import java.util.Map;
*/ */
public class RepositoryScanningAction public class RepositoryScanningAction
extends PlexusActionSupport extends PlexusActionSupport
implements Preparable, Validateable, SecureAction implements Preparable, Validateable, SecureAction, Auditable
{ {
/** /**
* @plexus.requirement * @plexus.requirement
@ -133,6 +135,8 @@ public class RepositoryScanningAction
filetype.addPattern( pattern ); filetype.addPattern( pattern );
addActionMessage( "Added pattern \"" + pattern + "\" to filetype " + id ); addActionMessage( "Added pattern \"" + pattern + "\" to filetype " + id );
triggerAuditEvent( AuditEvent.ADD_PATTERN + " " + pattern );
return saveConfiguration(); return saveConfiguration();
} }
@ -223,6 +227,8 @@ public class RepositoryScanningAction
filetype.removePattern( getPattern() ); filetype.removePattern( getPattern() );
triggerAuditEvent( AuditEvent.REMOVE_PATTERN + " " + pattern );
return saveConfiguration(); return saveConfiguration();
} }
@ -240,9 +246,14 @@ public class RepositoryScanningAction
{ {
addActionMessage( "Update Invalid Consumers" ); addActionMessage( "Update Invalid Consumers" );
List<String> oldConsumers = archivaConfiguration.getConfiguration().getRepositoryScanning().getInvalidContentConsumers();
archivaConfiguration.getConfiguration().getRepositoryScanning().setInvalidContentConsumers( archivaConfiguration.getConfiguration().getRepositoryScanning().setInvalidContentConsumers(
enabledInvalidContentConsumers ); enabledInvalidContentConsumers );
filterAddedConsumers( oldConsumers, enabledInvalidContentConsumers );
filterRemovedConsumers( oldConsumers, enabledInvalidContentConsumers );
return saveConfiguration(); return saveConfiguration();
} }
@ -250,9 +261,14 @@ public class RepositoryScanningAction
{ {
addActionMessage( "Update Known Consumers" ); addActionMessage( "Update Known Consumers" );
List<String> oldConsumers = archivaConfiguration.getConfiguration().getRepositoryScanning().getKnownContentConsumers();
archivaConfiguration.getConfiguration().getRepositoryScanning().setKnownContentConsumers( archivaConfiguration.getConfiguration().getRepositoryScanning().setKnownContentConsumers(
enabledKnownContentConsumers ); enabledKnownContentConsumers );
filterAddedConsumers( oldConsumers, enabledKnownContentConsumers );
filterRemovedConsumers( oldConsumers, enabledKnownContentConsumers );
return saveConfiguration(); return saveConfiguration();
} }
@ -298,6 +314,28 @@ public class RepositoryScanningAction
return SUCCESS; return SUCCESS;
} }
private void filterAddedConsumers( List<String> oldList, List<String> newList )
{
for ( String consumer : newList )
{
if ( !oldList.contains( consumer ) )
{
triggerAuditEvent( AuditEvent.ENABLE_REPO_CONSUMER + " " + consumer );
}
}
}
private void filterRemovedConsumers( List<String> oldList, List<String> newList )
{
for ( String consumer : oldList )
{
if ( !newList.contains( consumer ) )
{
triggerAuditEvent( AuditEvent.DISABLE_REPO_CONSUMER + " " + consumer );
}
}
}
public List<String> getEnabledInvalidContentConsumers() public List<String> getEnabledInvalidContentConsumers()
{ {
return enabledInvalidContentConsumers; return enabledInvalidContentConsumers;

View File

@ -20,7 +20,6 @@ package org.apache.maven.archiva.web.action;
*/ */
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.List; import java.util.List;
import org.apache.archiva.indexer.search.RepositorySearch; import org.apache.archiva.indexer.search.RepositorySearch;
@ -35,11 +34,10 @@ import org.apache.maven.archiva.database.ArtifactDAO;
import org.apache.maven.archiva.database.constraints.ArtifactsByChecksumConstraint; import org.apache.maven.archiva.database.constraints.ArtifactsByChecksumConstraint;
import org.apache.maven.archiva.database.constraints.UniqueVersionConstraint; import org.apache.maven.archiva.database.constraints.UniqueVersionConstraint;
import org.apache.maven.archiva.model.ArchivaArtifact; import org.apache.maven.archiva.model.ArchivaArtifact;
import org.apache.maven.archiva.security.ArchivaXworkUser;
import org.apache.maven.archiva.security.UserRepositories; import org.apache.maven.archiva.security.UserRepositories;
import org.codehaus.plexus.redback.users.UserManager;
import org.codehaus.plexus.spring.PlexusInSpringTestCase; import org.codehaus.plexus.spring.PlexusInSpringTestCase;
import org.easymock.MockControl; import org.easymock.MockControl;
import org.easymock.classextension.MockClassControl;
import com.opensymphony.xwork2.Action; import com.opensymphony.xwork2.Action;
@ -65,8 +63,6 @@ public class SearchActionTest
private MockControl archivaXworkUserControl; private MockControl archivaXworkUserControl;
private ArchivaXworkUser archivaXworkUser;
private MockControl searchControl; private MockControl searchControl;
private RepositorySearch search; private RepositorySearch search;
@ -93,11 +89,6 @@ public class SearchActionTest
userReposControl = MockControl.createControl( UserRepositories.class ); userReposControl = MockControl.createControl( UserRepositories.class );
userRepos = ( UserRepositories ) userReposControl.getMock(); userRepos = ( UserRepositories ) userReposControl.getMock();
archivaXworkUserControl = MockClassControl.createControl( ArchivaXworkUser.class );
archivaXworkUserControl.setDefaultMatcher( MockControl.ALWAYS_MATCHER );
archivaXworkUser = ( ArchivaXworkUser ) archivaXworkUserControl.getMock();
searchControl = MockControl.createControl( RepositorySearch.class ); searchControl = MockControl.createControl( RepositorySearch.class );
searchControl.setDefaultMatcher( MockControl.ALWAYS_MATCHER ); searchControl.setDefaultMatcher( MockControl.ALWAYS_MATCHER );
search = ( RepositorySearch ) searchControl.getMock(); search = ( RepositorySearch ) searchControl.getMock();
@ -107,7 +98,6 @@ public class SearchActionTest
artifactDao = ( ArtifactDAO ) artifactDaoControl.getMock(); artifactDao = ( ArtifactDAO ) artifactDaoControl.getMock();
action.setArchivaConfiguration( archivaConfig ); action.setArchivaConfiguration( archivaConfig );
action.setArchivaXworkUser( archivaXworkUser );
action.setUserRepositories( userRepos ); action.setUserRepositories( userRepos );
action.setDao( dao ); action.setDao( dao );
action.setNexusSearch( search ); action.setNexusSearch( search );
@ -153,7 +143,7 @@ public class SearchActionTest
versions.add( "1.0" ); versions.add( "1.0" );
versions.add( "1.1" ); versions.add( "1.1" );
archivaXworkUserControl.expectAndReturn( getActivePrincipal(), "user", 3 ); archivaXworkUserControl.expectAndReturn( UserManager.GUEST_USERNAME, "user", 3 );
userReposControl.expectAndReturn( userRepos.getObservableRepositoryIds( "user" ), selectedRepos, 2 ); userReposControl.expectAndReturn( userRepos.getObservableRepositoryIds( "user" ), selectedRepos, 2 );
@ -178,11 +168,6 @@ public class SearchActionTest
daoControl.verify(); daoControl.verify();
} }
private String getActivePrincipal()
{
return archivaXworkUser.getActivePrincipal( Collections.<String,Object>emptyMap() );
}
public void testSearchWithinSearchResults() public void testSearchWithinSearchResults()
throws Exception throws Exception
{ {
@ -218,7 +203,7 @@ public class SearchActionTest
versions.add( "1.0" ); versions.add( "1.0" );
versions.add( "1.1" ); versions.add( "1.1" );
archivaXworkUserControl.expectAndReturn( getActivePrincipal(), "user", 3 ); archivaXworkUserControl.expectAndReturn( UserManager.GUEST_USERNAME, "user", 3 );
userReposControl.expectAndReturn( userRepos.getObservableRepositoryIds( "user" ), selectedRepos, 2 ); userReposControl.expectAndReturn( userRepos.getObservableRepositoryIds( "user" ), selectedRepos, 2 );
@ -252,7 +237,7 @@ public class SearchActionTest
List<String> selectedRepos = new ArrayList<String>(); List<String> selectedRepos = new ArrayList<String>();
archivaXworkUserControl.expectAndReturn( getActivePrincipal(), "user" ); archivaXworkUserControl.expectAndReturn( UserManager.GUEST_USERNAME, "user" );
userReposControl.expectAndReturn( userRepos.getObservableRepositoryIds( "user" ), selectedRepos ); userReposControl.expectAndReturn( userRepos.getObservableRepositoryIds( "user" ), selectedRepos );
@ -284,7 +269,7 @@ public class SearchActionTest
SearchResults results = new SearchResults(); SearchResults results = new SearchResults();
archivaXworkUserControl.expectAndReturn( getActivePrincipal(), "user", 2 ); archivaXworkUserControl.expectAndReturn( UserManager.GUEST_USERNAME, "user", 2 );
userReposControl.expectAndReturn( userRepos.getObservableRepositoryIds( "user" ), selectedRepos ); userReposControl.expectAndReturn( userRepos.getObservableRepositoryIds( "user" ), selectedRepos );
@ -339,7 +324,7 @@ public class SearchActionTest
SearchFields searchFields = new SearchFields( "org", null, null, null, null, selectedRepos ); SearchFields searchFields = new SearchFields( "org", null, null, null, null, selectedRepos );
archivaXworkUserControl.expectAndReturn( getActivePrincipal(), "user" ); archivaXworkUserControl.expectAndReturn( UserManager.GUEST_USERNAME, "user" );
searchControl.expectAndReturn( search.search( "user", searchFields, limits ), results ); searchControl.expectAndReturn( search.search( "user", searchFields, limits ), results );
@ -389,7 +374,7 @@ public class SearchActionTest
SearchFields searchFields = new SearchFields( "org", null, null, null, null, selectedRepos ); SearchFields searchFields = new SearchFields( "org", null, null, null, null, selectedRepos );
archivaXworkUserControl.expectAndReturn( getActivePrincipal(), "user", 2 ); archivaXworkUserControl.expectAndReturn( UserManager.GUEST_USERNAME, "user", 2 );
userReposControl.expectAndReturn( userRepos.getObservableRepositoryIds( "user" ), selectedRepos ); userReposControl.expectAndReturn( userRepos.getObservableRepositoryIds( "user" ), selectedRepos );
@ -434,7 +419,7 @@ public class SearchActionTest
SearchFields searchFields = new SearchFields( "org", null, null, null, null, selectedRepos ); SearchFields searchFields = new SearchFields( "org", null, null, null, null, selectedRepos );
archivaXworkUserControl.expectAndReturn( getActivePrincipal(), "user" ); archivaXworkUserControl.expectAndReturn( UserManager.GUEST_USERNAME, "user" );
searchControl.expectAndReturn( search.search( "user", searchFields, limits ), results ); searchControl.expectAndReturn( search.search( "user", searchFields, limits ), results );

View File

@ -21,15 +21,16 @@ package org.apache.maven.archiva.web.action.admin.repositories;
import java.util.Collections; import java.util.Collections;
import com.opensymphony.xwork2.Action;
import org.apache.maven.archiva.configuration.ArchivaConfiguration; import org.apache.maven.archiva.configuration.ArchivaConfiguration;
import org.apache.maven.archiva.configuration.Configuration; import org.apache.maven.archiva.configuration.Configuration;
import org.apache.maven.archiva.configuration.RepositoryGroupConfiguration; import org.apache.maven.archiva.configuration.RepositoryGroupConfiguration;
import org.codehaus.plexus.spring.PlexusInSpringTestCase;
import org.codehaus.redback.integration.interceptor.SecureActionBundle; import org.codehaus.redback.integration.interceptor.SecureActionBundle;
import org.codehaus.redback.integration.interceptor.SecureActionException; import org.codehaus.redback.integration.interceptor.SecureActionException;
import org.codehaus.plexus.spring.PlexusInSpringTestCase;
import org.easymock.MockControl; import org.easymock.MockControl;
import com.opensymphony.xwork2.Action;
/** /**
* DeleteRepositoryGroupActionTest * DeleteRepositoryGroupActionTest
* *