diff options
author | Brett Porter <brett@apache.org> | 2009-03-20 16:12:10 +0000 |
---|---|---|
committer | Brett Porter <brett@apache.org> | 2009-03-20 16:12:10 +0000 |
commit | bf34387459021c5c677c6c90c4b48f52821f06da (patch) | |
tree | e9772970f62cfc2d920093b6525712d023b0a72b /archiva-modules/archiva-web/archiva-webapp | |
parent | 9bd751e3d523d5be4fc2691958715c0f34c6e413 (diff) | |
download | archiva-bf34387459021c5c677c6c90c4b48f52821f06da.tar.gz archiva-bf34387459021c5c677c6c90c4b48f52821f06da.zip |
[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
Diffstat (limited to 'archiva-modules/archiva-web/archiva-webapp')
19 files changed, 201 insertions, 188 deletions
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<String> 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; @@ -75,11 +71,6 @@ public class DeleteArtifactAction implements Validateable, Preparable, Auditable { /** - * @plexus.requirement - */ - private ArchivaXworkUser archivaXworkUser; - - /** * The groupId of the artifact to be deleted. */ private String groupId; @@ -129,11 +120,6 @@ public class DeleteArtifactAction */ 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 }; 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<String> 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<AuditListener> auditListeners = new ArrayList<AuditListener>();
+
@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<String> 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<String, String> 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<String> 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<AuditListener> auditListeners = new ArrayList<AuditListener>(); - 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<String> 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<String> oldConsumers = archivaConfiguration.getConfiguration().getDatabaseScanning().getUnprocessedConsumers(); + archivaConfiguration.getConfiguration().getDatabaseScanning().setUnprocessedConsumers( enabledUnprocessedConsumers ); + + filterAddedConsumers( oldConsumers, enabledUnprocessedConsumers ); + filterRemovedConsumers( oldConsumers, enabledUnprocessedConsumers ); return saveConfiguration(); } public String updateCleanupConsumers() { + List<String> 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<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 ); + } + } + } } 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<String> 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<String> 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<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() { 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.<String,Object>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<String> selectedRepos = new ArrayList<String>(); - 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 * |