From: Brett Porter Date: Fri, 20 Mar 2009 16:12:10 +0000 (+0000) Subject: [MRM-1093] Log configuration and repository changes made. X-Git-Tag: archiva-1.2~14 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=bf34387459021c5c677c6c90c4b48f52821f06da;p=archiva.git [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 --- diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/AbstractRepositoryPurge.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/AbstractRepositoryPurge.java index 46b0e9b12..467c56af4 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/AbstractRepositoryPurge.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/AbstractRepositoryPurge.java @@ -24,8 +24,12 @@ import java.io.FilenameFilter; import java.util.List; 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.ArtifactReference; +import org.apache.maven.archiva.repository.audit.AuditEvent; import org.apache.maven.archiva.repository.ManagedRepositoryContent; import org.apache.maven.archiva.repository.events.RepositoryListener; import org.slf4j.Logger; @@ -43,6 +47,10 @@ public abstract class AbstractRepositoryPurge protected final ManagedRepositoryContent repository; protected final List listeners; + + private Logger logger = LoggerFactory.getLogger( "org.apache.archiva.AuditLog" ); + + private static final char DELIM = ' '; public AbstractRepositoryPurge( ManagedRepositoryContent repository, List listeners ) { @@ -101,6 +109,7 @@ public abstract class AbstractRepositoryPurge // TODO: this needs to be logged artifactFile.delete(); + triggerAuditEvent( repository.getRepository().getId(), ArtifactReference.toKey( reference ), AuditEvent.PURGE_ARTIFACT ); purgeSupportFiles( artifactFile ); } } @@ -133,9 +142,19 @@ public abstract class AbstractRepositoryPurge { if ( file.exists() && file.isFile() ) { + String fileName = file.getName(); file.delete(); // 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 + "" + DELIM + "" + DELIM + '\"' + resource + '\"' + + DELIM + '\"' + action + '\"'; + + logger.info( msg ); + } } diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-database-consumers/src/main/java/org/apache/maven/archiva/consumers/database/DatabaseCleanupRemoveArtifactConsumer.java b/archiva-modules/archiva-base/archiva-consumers/archiva-database-consumers/src/main/java/org/apache/maven/archiva/consumers/database/DatabaseCleanupRemoveArtifactConsumer.java index c849cc88e..c4539c6f3 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-database-consumers/src/main/java/org/apache/maven/archiva/consumers/database/DatabaseCleanupRemoveArtifactConsumer.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-database-consumers/src/main/java/org/apache/maven/archiva/consumers/database/DatabaseCleanupRemoveArtifactConsumer.java @@ -32,6 +32,10 @@ import org.apache.maven.archiva.model.RepositoryProblem; import org.apache.maven.archiva.repository.ManagedRepositoryContent; import org.apache.maven.archiva.repository.RepositoryContentFactory; 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.io.File; @@ -74,6 +78,10 @@ public class DatabaseCleanupRemoveArtifactConsumer * @plexus.requirement */ private RepositoryContentFactory repositoryFactory; + + private Logger logger = LoggerFactory.getLogger( "org.apache.archiva.AuditLog" ); + + private static final char DELIM = ' '; public void beginScan() { @@ -104,6 +112,8 @@ public class DatabaseCleanupRemoveArtifactConsumer if( !file.exists() ) { artifactDAO.deleteArtifact( artifact ); + + triggerAuditEvent( repositoryContent.getRepository().getId(), artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getVersion(), AuditEvent.REMOVE_SCANNED ); // Remove all repository problems related to this artifact Constraint artifactConstraint = new RepositoryProblemByArtifactConstraint( artifact ); @@ -159,4 +169,12 @@ public class DatabaseCleanupRemoveArtifactConsumer { this.repositoryFactory = repositoryFactory; } + + private void triggerAuditEvent( String repoId, String resource, String action ) + { + String msg = repoId + DELIM + "" + DELIM + "" + DELIM + '\"' + resource + '\"' + + DELIM + '\"' + action + '\"'; + + logger.info( msg ); + } } diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/audit/AuditEvent.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/audit/AuditEvent.java index 643d5c0e9..ead95b502 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/audit/AuditEvent.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/audit/AuditEvent.java @@ -20,8 +20,8 @@ package org.apache.maven.archiva.repository.audit; */ /** - * AuditEvent - * + * AuditEvent + * * @version $Id$ */ public class AuditEvent @@ -43,13 +43,59 @@ public class AuditEvent public static final String COPY_DIRECTORY = "Copied Directory"; public static final String COPY_FILE = "Copied 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 userId; - + private String remoteIP; private String resource; @@ -69,6 +115,16 @@ public class AuditEvent 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() { return repositoryId; diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/audit/AuditLog.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/audit/AuditLog.java index f6ae7f906..d99c9d7bc 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/audit/AuditLog.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/audit/AuditLog.java @@ -23,34 +23,38 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * AuditLog - Audit Log. - * - * @version $Id$ + * AuditLog - Audit Log. * - * @plexus.component role="org.apache.maven.archiva.repository.audit.AuditListener" - * role-hint="logging" + * @version $Id$ + * @plexus.component role="org.apache.maven.archiva.repository.audit.AuditListener" role-hint="logging" */ public class AuditLog implements AuditListener { public static final Logger logger = LoggerFactory.getLogger( "org.apache.archiva.AuditLog" ); - - private static final char DELIM = ' '; + + private static final String NONE = "-"; + + private static final char DELIM = ' '; /** * Creates a log message in the following format ... - * * "{repository_id} {user_id} {remote_ip} \"{resource}\" \"{action}\"" */ public void auditEvent( AuditEvent event ) { 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.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( '\"' ); logger.info( msg.toString() ); } + + private String checkNull( String s ) + { + return s != null ? s : NONE; + } } diff --git a/archiva-modules/archiva-web/archiva-security/src/main/java/org/apache/maven/archiva/security/ArchivaXworkUser.java b/archiva-modules/archiva-web/archiva-security/src/main/java/org/apache/maven/archiva/security/ArchivaXworkUser.java index 2cdb7f7f9..a12f4d72c 100644 --- a/archiva-modules/archiva-web/archiva-security/src/main/java/org/apache/maven/archiva/security/ArchivaXworkUser.java +++ b/archiva-modules/archiva-web/archiva-security/src/main/java/org/apache/maven/archiva/security/ArchivaXworkUser.java @@ -30,11 +30,15 @@ import org.codehaus.plexus.redback.users.UserManager; * ArchivaXworkUser * * @version $Id$ - * @plexus.component role="org.apache.maven.archiva.security.ArchivaXworkUser" */ -public class ArchivaXworkUser +public final class ArchivaXworkUser { - public String getActivePrincipal( Map sessionMap ) + private ArchivaXworkUser() + { + // no touchy + } + + public static String getActivePrincipal( Map sessionMap ) { SecuritySession securitySession = (SecuritySession) sessionMap.get( SecuritySystemConstants.SECURITY_SESSION_KEY ); diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/BrowseAction.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/BrowseAction.java index 8d986cd78..64c967cc5 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/BrowseAction.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/BrowseAction.java @@ -22,7 +22,6 @@ package org.apache.maven.archiva.web.action; import java.util.Collections; import java.util.List; -import com.opensymphony.xwork2.ActionContext; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang.StringUtils; import org.apache.maven.archiva.database.ArchivaDatabaseException; @@ -53,11 +52,6 @@ public class BrowseAction */ private UserRepositories userRepositories; - /** - * @plexus.requirement - */ - private ArchivaXworkUser archivaXworkUser; - private BrowsingResults results; private String groupId; @@ -209,12 +203,6 @@ public class BrowseAction } } - @SuppressWarnings("unchecked") - private String getPrincipal() - { - return archivaXworkUser.getActivePrincipal( ActionContext.getContext().getSession() ); - } - private List getObservableRepos() { try diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/DeleteArtifactAction.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/DeleteArtifactAction.java index da2f1ebb7..7d2d62b25 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/DeleteArtifactAction.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/DeleteArtifactAction.java @@ -48,7 +48,6 @@ import org.apache.maven.archiva.repository.RepositoryContentFactory; import org.apache.maven.archiva.repository.RepositoryException; import org.apache.maven.archiva.repository.RepositoryNotFoundException; 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.metadata.MetadataTools; 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.security.AccessDeniedException; 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.UserRepositories; -import org.apache.struts2.ServletActionContext; -import com.opensymphony.xwork2.ActionContext; import com.opensymphony.xwork2.Preparable; import com.opensymphony.xwork2.Validateable; @@ -74,11 +70,6 @@ public class DeleteArtifactAction extends PlexusActionSupport implements Validateable, Preparable, Auditable { - /** - * @plexus.requirement - */ - private ArchivaXworkUser archivaXworkUser; - /** * The groupId of the artifact to be deleted. */ @@ -129,11 +120,6 @@ public class DeleteArtifactAction */ private DatabaseConsumers databaseConsumers; - /** - * @plexus.requirement role="org.apache.maven.archiva.repository.audit.AuditListener" - */ - private List auditListeners = new ArrayList(); - private ChecksumAlgorithm[] algorithms = new ChecksumAlgorithm[] { ChecksumAlgorithm.SHA1, ChecksumAlgorithm.MD5 }; public String getGroupId() @@ -271,7 +257,7 @@ public class DeleteArtifactAction "Artifact \'" + groupId + ":" + artifactId + ":" + version + "\' was successfully deleted from repository \'" + repositoryId + "\'"; - triggerAuditEvent( getPrincipal(), repositoryId, groupId + ":" + artifactId + ":" + version, + triggerAuditEvent( repositoryId, groupId + ":" + artifactId + ":" + version, AuditEvent.REMOVE_FILE ); 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 ) { 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 getManagableRepos() { try @@ -439,15 +404,4 @@ public class DeleteArtifactAction } 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 ); - } - } } diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/PlexusActionSupport.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/PlexusActionSupport.java index 025e4f51a..8780aba44 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/PlexusActionSupport.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/PlexusActionSupport.java @@ -19,12 +19,20 @@ package org.apache.maven.archiva.web.action; * under the License. */ +import java.util.ArrayList; +import java.util.List; 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.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.opensymphony.xwork2.ActionContext; import com.opensymphony.xwork2.ActionSupport; /** @@ -32,15 +40,74 @@ import com.opensymphony.xwork2.ActionSupport; */ public abstract class PlexusActionSupport extends ActionSupport - implements SessionAware + implements SessionAware, Auditable { protected Map session; protected Logger log = LoggerFactory.getLogger( getClass() ); - + + /** + * @plexus.requirement role="org.apache.maven.archiva.repository.audit.AuditListener" + */ + private List auditListeners = new ArrayList(); + @SuppressWarnings("unchecked") public void setSession( Map 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() ); + } } diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/SearchAction.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/SearchAction.java index 493121c90..4060df730 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/SearchAction.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/SearchAction.java @@ -45,14 +45,12 @@ import org.apache.maven.archiva.database.constraints.UniqueVersionConstraint; import org.apache.maven.archiva.model.ArchivaArtifact; import org.apache.maven.archiva.security.AccessDeniedException; 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.UserRepositories; import org.apache.struts2.ServletActionContext; import org.springframework.web.context.WebApplicationContext; import org.springframework.web.context.support.WebApplicationContextUtils; -import com.opensymphony.xwork2.ActionContext; import com.opensymphony.xwork2.Preparable; /** @@ -87,11 +85,6 @@ public class SearchAction */ private UserRepositories userRepositories; - /** - * @plexus.requirement - */ - private ArchivaXworkUser archivaXworkUser; - private static final String RESULTS = "results"; private static final String ARTIFACT = "artifact"; @@ -400,12 +393,6 @@ public class SearchAction return INPUT; } - @SuppressWarnings("unchecked") - private String getPrincipal() - { - return archivaXworkUser.getActivePrincipal( ActionContext.getContext().getSession() ); - } - private List getObservableRepos() { try @@ -663,16 +650,6 @@ public class SearchAction this.userRepositories = userRepositories; } - public ArchivaXworkUser getArchivaXworkUser() - { - return archivaXworkUser; - } - - public void setArchivaXworkUser( ArchivaXworkUser archivaXworkUser ) - { - this.archivaXworkUser = archivaXworkUser; - } - public Map getSearchFields() { return searchFields; diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/ShowArtifactAction.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/ShowArtifactAction.java index 869abd5f7..be7ba5d3a 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/ShowArtifactAction.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/ShowArtifactAction.java @@ -34,9 +34,7 @@ import org.apache.maven.archiva.security.AccessDeniedException; import org.apache.maven.archiva.security.ArchivaSecurityException; import org.apache.maven.archiva.security.PrincipalNotFoundException; import org.apache.maven.archiva.security.UserRepositories; -import org.apache.maven.archiva.security.ArchivaXworkUser; -import com.opensymphony.xwork2.ActionContext; import com.opensymphony.xwork2.Validateable; /** @@ -62,13 +60,6 @@ public class ShowArtifactAction */ private UserRepositories userRepositories; - /** - * @plexus.requirement - */ - private ArchivaXworkUser archivaXworkUser; - - /* .\ Input Parameters \.________________________________________ */ - private String groupId; private String artifactId; @@ -195,12 +186,6 @@ public class ShowArtifactAction return SUCCESS; } - @SuppressWarnings("unchecked") - private String getPrincipal() - { - return archivaXworkUser.getActivePrincipal( ActionContext.getContext().getSession() ); - } - private List getObservableRepos() { try diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/UploadAction.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/UploadAction.java index c39850c1a..ac9282224 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/UploadAction.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/UploadAction.java @@ -48,7 +48,6 @@ import org.apache.maven.archiva.repository.RepositoryException; import org.apache.maven.archiva.repository.RepositoryNotFoundException; import org.apache.maven.archiva.repository.scanner.RepositoryContentConsumers; 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.metadata.MetadataTools; 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.PrincipalNotFoundException; 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.Validateable; import org.apache.commons.io.FilenameUtils; @@ -86,11 +82,6 @@ public class UploadAction private RepositoryContentConsumers consumers; /** - * @plexus.requirement - */ - private ArchivaXworkUser archivaXworkUser; - - /** * The groupId of the artifact to be deployed. */ private String groupId; @@ -155,11 +146,6 @@ public class UploadAction */ private RepositoryContentFactory repositoryFactory; - /** - * @plexus.requirement role="org.apache.maven.archiva.repository.audit.AuditListener" - */ - private List auditListeners = new ArrayList(); - private ChecksumAlgorithm[] algorithms = new ChecksumAlgorithm[] { ChecksumAlgorithm.SHA1, ChecksumAlgorithm.MD5 }; private ProjectModelWriter pomWriter = new ProjectModel400Writer(); @@ -413,7 +399,7 @@ public class UploadAction String msg = "Artifact \'" + groupId + ":" + artifactId + ":" + version + "\' 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 ); @@ -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 ) 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 getManagableRepos() { try @@ -620,15 +585,4 @@ public class UploadAction } 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 ); - } - } } diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/database/DatabaseAction.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/database/DatabaseAction.java index d040980ef..9c7d1b518 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/database/DatabaseAction.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/database/DatabaseAction.java @@ -28,6 +28,8 @@ import org.apache.maven.archiva.configuration.Configuration; import org.apache.maven.archiva.configuration.DatabaseScanningConfiguration; import org.apache.maven.archiva.configuration.IndeterminateConfigurationException; 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.web.action.PlexusActionSupport; import org.codehaus.plexus.redback.rbac.Resource; @@ -46,7 +48,7 @@ import com.opensymphony.xwork2.Preparable; */ public class DatabaseAction extends PlexusActionSupport - implements Preparable, SecureAction + implements Preparable, SecureAction, Auditable { /** * @plexus.requirement @@ -103,22 +105,39 @@ public class DatabaseAction public String updateUnprocessedConsumers() { + List oldConsumers = archivaConfiguration.getConfiguration().getDatabaseScanning().getUnprocessedConsumers(); + archivaConfiguration.getConfiguration().getDatabaseScanning().setUnprocessedConsumers( enabledUnprocessedConsumers ); + + filterAddedConsumers( oldConsumers, enabledUnprocessedConsumers ); + filterRemovedConsumers( oldConsumers, enabledUnprocessedConsumers ); return saveConfiguration(); } public String updateCleanupConsumers() { + List oldConsumers = archivaConfiguration.getConfiguration().getDatabaseScanning().getCleanupConsumers(); + archivaConfiguration.getConfiguration().getDatabaseScanning().setCleanupConsumers( enabledCleanupConsumers ); + + filterAddedConsumers( oldConsumers, enabledCleanupConsumers ); + filterRemovedConsumers( oldConsumers, enabledCleanupConsumers ); return saveConfiguration(); } public String updateSchedule() { + String oldCron = archivaConfiguration.getConfiguration().getDatabaseScanning().getCronExpression(); + archivaConfiguration.getConfiguration().getDatabaseScanning().setCronExpression( cron ); + + if ( !oldCron.equals( cron ) ) + { + triggerAuditEvent( AuditEvent.DB_SCHEDULE + " " + cron ); + } return saveConfiguration(); } @@ -195,4 +214,26 @@ public class DatabaseAction { this.enabledCleanupConsumers = enabledCleanupConsumers; } + + private void filterAddedConsumers( List oldList, List newList ) + { + for ( String consumer : newList ) + { + if ( !oldList.contains( consumer ) ) + { + triggerAuditEvent( consumer, AuditEvent.ENABLE_DB_CONSUMER ); + } + } + } + + private void filterRemovedConsumers( List oldList, List newList ) + { + for ( String consumer : oldList ) + { + if ( !newList.contains( consumer ) ) + { + triggerAuditEvent( consumer, AuditEvent.DISABLE_DB_CONSUMER ); + } + } + } } diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/AbstractRepositoriesAdminAction.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/AbstractRepositoriesAdminAction.java index 5b1324dd8..144bbaa00 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/AbstractRepositoriesAdminAction.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/AbstractRepositoriesAdminAction.java @@ -19,20 +19,23 @@ package org.apache.maven.archiva.web.action.admin.repositories; * 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.Configuration; 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.repository.audit.Auditable; 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.registry.RegistryException; import org.codehaus.redback.integration.interceptor.SecureAction; import org.codehaus.redback.integration.interceptor.SecureActionBundle; 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. @@ -44,7 +47,7 @@ import org.apache.maven.archiva.web.action.PlexusActionSupport; */ public abstract class AbstractRepositoriesAdminAction extends PlexusActionSupport - implements SecureAction + implements SecureAction, Auditable { /** * @plexus.requirement diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/AddManagedRepositoryAction.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/AddManagedRepositoryAction.java index 4d3341521..b51bc7f94 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/AddManagedRepositoryAction.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/AddManagedRepositoryAction.java @@ -24,6 +24,7 @@ import com.opensymphony.xwork2.Validateable; import org.apache.maven.archiva.configuration.Configuration; 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.scheduler.CronExpressionValidator; import java.io.File; @@ -86,6 +87,7 @@ public class AddManagedRepositoryAction try { addRepository( repository, configuration ); + triggerAuditEvent( repository.getId(), null, AuditEvent.ADD_MANAGED_REPO ); addRepositoryRoles( repository ); result = saveConfiguration( configuration ); } diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/AddRemoteRepositoryAction.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/AddRemoteRepositoryAction.java index d624220f6..3b3d7b1d6 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/AddRemoteRepositoryAction.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/AddRemoteRepositoryAction.java @@ -24,6 +24,7 @@ import com.opensymphony.xwork2.Validateable; import org.apache.maven.archiva.configuration.Configuration; import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration; +import org.apache.maven.archiva.repository.audit.AuditEvent; import org.codehaus.plexus.redback.role.RoleManagerException; import java.io.IOException; @@ -66,6 +67,7 @@ public class AddRemoteRepositoryAction try { addRepository( repository, configuration ); + triggerAuditEvent( repository.getId(), null, AuditEvent.ADD_REMOTE_REPO ); result = saveConfiguration( configuration ); } catch ( IOException e ) diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryAction.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryAction.java index 2ef89df70..a2793ce09 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryAction.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryAction.java @@ -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.ArchivaProjectModel; import org.apache.maven.archiva.model.RepositoryContentStatistics; +import org.apache.maven.archiva.repository.audit.AuditEvent; import org.apache.maven.archiva.configuration.ProxyConnectorConfiguration; @@ -107,6 +108,7 @@ public class DeleteManagedRepositoryAction Configuration configuration = archivaConfiguration.getConfiguration(); cleanupRepositoryData( existingRepository ); removeRepository( repoid, configuration ); + triggerAuditEvent( repoid, null, AuditEvent.DELETE_MANAGED_REPO ); result = saveConfiguration( configuration ); if ( result.equals( SUCCESS ) ) diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteRemoteRepositoryAction.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteRemoteRepositoryAction.java index 13e6536cd..9d9fef04b 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteRemoteRepositoryAction.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteRemoteRepositoryAction.java @@ -25,6 +25,7 @@ import org.apache.commons.lang.StringUtils; import org.apache.maven.archiva.configuration.Configuration; import org.apache.maven.archiva.configuration.ProxyConnectorConfiguration; import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration; +import org.apache.maven.archiva.repository.audit.AuditEvent; import java.util.List; @@ -74,6 +75,7 @@ public class DeleteRemoteRepositoryAction Configuration configuration = archivaConfiguration.getConfiguration(); removeRepository( repoid, configuration ); + triggerAuditEvent( repoid, null, AuditEvent.DELETE_REMOTE_REPO ); result = saveConfiguration( configuration ); cleanupRepositoryData( existingRepository ); diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteRepositoryGroupAction.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteRepositoryGroupAction.java index 5e99c9c81..0c3aad84a 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteRepositoryGroupAction.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteRepositoryGroupAction.java @@ -24,6 +24,7 @@ import com.opensymphony.xwork2.Preparable; import org.apache.commons.lang.StringUtils; import org.apache.maven.archiva.configuration.Configuration; import org.apache.maven.archiva.configuration.RepositoryGroupConfiguration; +import org.apache.maven.archiva.repository.audit.AuditEvent; /** * DeleteRepositoryGroupAction @@ -70,6 +71,7 @@ public class DeleteRepositoryGroupAction } config.removeRepositoryGroup( group ); + triggerAuditEvent( AuditEvent.DELETE_REPO_GROUP + " " + repoGroupId ); return saveConfiguration( config ); } diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/EditManagedRepositoryAction.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/EditManagedRepositoryAction.java index 90bea2e73..de0cdd242 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/EditManagedRepositoryAction.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/EditManagedRepositoryAction.java @@ -25,6 +25,7 @@ import com.opensymphony.xwork2.Validateable; import org.apache.commons.lang.StringUtils; import org.apache.maven.archiva.configuration.Configuration; 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.scheduler.CronExpressionValidator; @@ -111,6 +112,7 @@ public class EditManagedRepositoryAction try { addRepository( repository, configuration ); + triggerAuditEvent( repository.getId(), null, AuditEvent.MODIFY_MANAGED_REPO ); addRepositoryRoles( repository ); result = saveConfiguration( configuration ); } diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/EditRemoteRepositoryAction.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/EditRemoteRepositoryAction.java index ce32241ef..61dd3f6a4 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/EditRemoteRepositoryAction.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/EditRemoteRepositoryAction.java @@ -24,6 +24,7 @@ import com.opensymphony.xwork2.Preparable; import org.apache.commons.lang.StringUtils; import org.apache.maven.archiva.configuration.Configuration; import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration; +import org.apache.maven.archiva.repository.audit.AuditEvent; import org.codehaus.plexus.redback.role.RoleManagerException; import java.io.IOException; @@ -81,6 +82,7 @@ public class EditRemoteRepositoryAction try { addRepository( repository, configuration ); + triggerAuditEvent( repository.getId(), null, AuditEvent.MODIFY_REMOTE_REPO ); result = saveConfiguration( configuration ); } catch ( IOException e ) diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/RepositoryGroupsAction.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/RepositoryGroupsAction.java index 2e8ab406c..fd5acb8b0 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/RepositoryGroupsAction.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/RepositoryGroupsAction.java @@ -33,6 +33,7 @@ import org.apache.commons.lang.StringUtils; import org.apache.maven.archiva.configuration.Configuration; import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; import org.apache.maven.archiva.configuration.RepositoryGroupConfiguration; +import org.apache.maven.archiva.repository.audit.AuditEvent; import org.apache.maven.archiva.web.util.ContextUtils; /** @@ -130,6 +131,7 @@ public class RepositoryGroupsAction } configuration.addRepositoryGroup( repositoryGroup ); + triggerAuditEvent( AuditEvent.ADD_REPO_GROUP + " " + repoGroupId ); return saveConfiguration( configuration ); } @@ -157,6 +159,8 @@ public class RepositoryGroupsAction // save repository group configuration group.addRepository( repoId ); config.addRepositoryGroup( group ); + + triggerAuditEvent( repoId, null, AuditEvent.ADD_REPO_TO_GROUP + " " + repoGroupId ); return saveConfiguration( config ); } @@ -185,6 +189,8 @@ public class RepositoryGroupsAction // save repository group configuration group.removeRepository( repoId ); config.addRepositoryGroup( group ); + + triggerAuditEvent( repoId, null, AuditEvent.DELETE_REPO_FROM_GROUP + " " + repoGroupId ); return saveConfiguration( config ); } diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/scanning/RepositoryScanningAction.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/scanning/RepositoryScanningAction.java index 599a23d0a..ca68e7c69 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/scanning/RepositoryScanningAction.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/scanning/RepositoryScanningAction.java @@ -19,8 +19,11 @@ package org.apache.maven.archiva.web.action.admin.scanning; * under the License. */ -import com.opensymphony.xwork2.Preparable; -import com.opensymphony.xwork2.Validateable; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; + import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang.StringUtils; 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.functors.FiletypeSelectionPredicate; 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.security.ArchivaRoleConstants; import org.apache.maven.archiva.web.action.PlexusActionSupport; - 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.SecureActionBundle; import org.codehaus.redback.integration.interceptor.SecureActionException; -import org.codehaus.plexus.registry.RegistryException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Map; +import com.opensymphony.xwork2.Preparable; +import com.opensymphony.xwork2.Validateable; /** * RepositoryScanningAction @@ -53,7 +55,7 @@ import java.util.Map; */ public class RepositoryScanningAction extends PlexusActionSupport - implements Preparable, Validateable, SecureAction + implements Preparable, Validateable, SecureAction, Auditable { /** * @plexus.requirement @@ -92,7 +94,7 @@ public class RepositoryScanningAction private String pattern; private String fileTypeId; - + public void addActionError( String anErrorMessage ) { super.addActionError( anErrorMessage ); @@ -132,6 +134,8 @@ public class RepositoryScanningAction filetype.addPattern( pattern ); addActionMessage( "Added pattern \"" + pattern + "\" to filetype " + id ); + + triggerAuditEvent( AuditEvent.ADD_PATTERN + " " + pattern ); return saveConfiguration(); } @@ -222,6 +226,8 @@ public class RepositoryScanningAction } filetype.removePattern( getPattern() ); + + triggerAuditEvent( AuditEvent.REMOVE_PATTERN + " " + pattern ); return saveConfiguration(); } @@ -239,9 +245,14 @@ public class RepositoryScanningAction public String updateInvalidConsumers() { addActionMessage( "Update Invalid Consumers" ); + + List oldConsumers = archivaConfiguration.getConfiguration().getRepositoryScanning().getInvalidContentConsumers(); archivaConfiguration.getConfiguration().getRepositoryScanning().setInvalidContentConsumers( enabledInvalidContentConsumers ); + + filterAddedConsumers( oldConsumers, enabledInvalidContentConsumers ); + filterRemovedConsumers( oldConsumers, enabledInvalidContentConsumers ); return saveConfiguration(); } @@ -249,9 +260,14 @@ public class RepositoryScanningAction public String updateKnownConsumers() { addActionMessage( "Update Known Consumers" ); + + List oldConsumers = archivaConfiguration.getConfiguration().getRepositoryScanning().getKnownContentConsumers(); archivaConfiguration.getConfiguration().getRepositoryScanning().setKnownContentConsumers( enabledKnownContentConsumers ); + + filterAddedConsumers( oldConsumers, enabledKnownContentConsumers ); + filterRemovedConsumers( oldConsumers, enabledKnownContentConsumers ); return saveConfiguration(); } @@ -298,6 +314,28 @@ public class RepositoryScanningAction return SUCCESS; } + private void filterAddedConsumers( List oldList, List newList ) + { + for ( String consumer : newList ) + { + if ( !oldList.contains( consumer ) ) + { + triggerAuditEvent( AuditEvent.ENABLE_REPO_CONSUMER + " " + consumer ); + } + } + } + + private void filterRemovedConsumers( List oldList, List newList ) + { + for ( String consumer : oldList ) + { + if ( !newList.contains( consumer ) ) + { + triggerAuditEvent( AuditEvent.DISABLE_REPO_CONSUMER + " " + consumer ); + } + } + } + public List getEnabledInvalidContentConsumers() { return enabledInvalidContentConsumers; diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/SearchActionTest.java b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/SearchActionTest.java index 68296ed97..a0c26efe1 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/SearchActionTest.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/SearchActionTest.java @@ -20,7 +20,6 @@ package org.apache.maven.archiva.web.action; */ import java.util.ArrayList; -import java.util.Collections; import java.util.List; 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.UniqueVersionConstraint; import org.apache.maven.archiva.model.ArchivaArtifact; -import org.apache.maven.archiva.security.ArchivaXworkUser; import org.apache.maven.archiva.security.UserRepositories; +import org.codehaus.plexus.redback.users.UserManager; import org.codehaus.plexus.spring.PlexusInSpringTestCase; import org.easymock.MockControl; -import org.easymock.classextension.MockClassControl; import com.opensymphony.xwork2.Action; @@ -65,8 +63,6 @@ public class SearchActionTest private MockControl archivaXworkUserControl; - private ArchivaXworkUser archivaXworkUser; - private MockControl searchControl; private RepositorySearch search; @@ -93,11 +89,6 @@ public class SearchActionTest userReposControl = MockControl.createControl( UserRepositories.class ); userRepos = ( UserRepositories ) userReposControl.getMock(); - archivaXworkUserControl = MockClassControl.createControl( ArchivaXworkUser.class ); - archivaXworkUserControl.setDefaultMatcher( MockControl.ALWAYS_MATCHER ); - - archivaXworkUser = ( ArchivaXworkUser ) archivaXworkUserControl.getMock(); - searchControl = MockControl.createControl( RepositorySearch.class ); searchControl.setDefaultMatcher( MockControl.ALWAYS_MATCHER ); search = ( RepositorySearch ) searchControl.getMock(); @@ -107,7 +98,6 @@ public class SearchActionTest artifactDao = ( ArtifactDAO ) artifactDaoControl.getMock(); action.setArchivaConfiguration( archivaConfig ); - action.setArchivaXworkUser( archivaXworkUser ); action.setUserRepositories( userRepos ); action.setDao( dao ); action.setNexusSearch( search ); @@ -153,7 +143,7 @@ public class SearchActionTest versions.add( "1.0" ); versions.add( "1.1" ); - archivaXworkUserControl.expectAndReturn( getActivePrincipal(), "user", 3 ); + archivaXworkUserControl.expectAndReturn( UserManager.GUEST_USERNAME, "user", 3 ); userReposControl.expectAndReturn( userRepos.getObservableRepositoryIds( "user" ), selectedRepos, 2 ); @@ -178,11 +168,6 @@ public class SearchActionTest daoControl.verify(); } - private String getActivePrincipal() - { - return archivaXworkUser.getActivePrincipal( Collections.emptyMap() ); - } - public void testSearchWithinSearchResults() throws Exception { @@ -218,7 +203,7 @@ public class SearchActionTest versions.add( "1.0" ); versions.add( "1.1" ); - archivaXworkUserControl.expectAndReturn( getActivePrincipal(), "user", 3 ); + archivaXworkUserControl.expectAndReturn( UserManager.GUEST_USERNAME, "user", 3 ); userReposControl.expectAndReturn( userRepos.getObservableRepositoryIds( "user" ), selectedRepos, 2 ); @@ -252,7 +237,7 @@ public class SearchActionTest List selectedRepos = new ArrayList(); - archivaXworkUserControl.expectAndReturn( getActivePrincipal(), "user" ); + archivaXworkUserControl.expectAndReturn( UserManager.GUEST_USERNAME, "user" ); userReposControl.expectAndReturn( userRepos.getObservableRepositoryIds( "user" ), selectedRepos ); @@ -284,7 +269,7 @@ public class SearchActionTest SearchResults results = new SearchResults(); - archivaXworkUserControl.expectAndReturn( getActivePrincipal(), "user", 2 ); + archivaXworkUserControl.expectAndReturn( UserManager.GUEST_USERNAME, "user", 2 ); userReposControl.expectAndReturn( userRepos.getObservableRepositoryIds( "user" ), selectedRepos ); @@ -339,7 +324,7 @@ public class SearchActionTest 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 ); @@ -389,7 +374,7 @@ public class SearchActionTest 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 ); @@ -434,7 +419,7 @@ public class SearchActionTest 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 ); diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteRepositoryGroupActionTest.java b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteRepositoryGroupActionTest.java index 49b6f5983..8d4a8ae0c 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteRepositoryGroupActionTest.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteRepositoryGroupActionTest.java @@ -21,15 +21,16 @@ package org.apache.maven.archiva.web.action.admin.repositories; import java.util.Collections; -import com.opensymphony.xwork2.Action; import org.apache.maven.archiva.configuration.ArchivaConfiguration; import org.apache.maven.archiva.configuration.Configuration; 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.SecureActionException; -import org.codehaus.plexus.spring.PlexusInSpringTestCase; import org.easymock.MockControl; +import com.opensymphony.xwork2.Action; + /** * DeleteRepositoryGroupActionTest *