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;
protected final ManagedRepositoryContent repository;
protected final List<RepositoryListener> listeners;
+
+ private Logger logger = LoggerFactory.getLogger( "org.apache.archiva.AuditLog" );
+
+ private static final char DELIM = ' ';
public AbstractRepositoryPurge( ManagedRepositoryContent repository, List<RepositoryListener> listeners )
{
// TODO: this needs to be logged
artifactFile.delete();
+ triggerAuditEvent( repository.getRepository().getId(), ArtifactReference.toKey( reference ), AuditEvent.PURGE_ARTIFACT );
purgeSupportFiles( artifactFile );
}
}
{
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 + "<system-purge>" + DELIM + "<system>" + DELIM + '\"' + resource + '\"' +
+ DELIM + '\"' + action + '\"';
+
+ logger.info( msg );
+ }
}
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;
* @plexus.requirement
*/
private RepositoryContentFactory repositoryFactory;
+
+ private Logger logger = LoggerFactory.getLogger( "org.apache.archiva.AuditLog" );
+
+ private static final char DELIM = ' ';
public void beginScan()
{
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 );
{
this.repositoryFactory = repositoryFactory;
}
+
+ private void triggerAuditEvent( String repoId, String resource, String action )
+ {
+ String msg = repoId + DELIM + "<db-scan>" + DELIM + "<system>" + DELIM + '\"' + resource + '\"' +
+ DELIM + '\"' + action + '\"';
+
+ logger.info( msg );
+ }
}
*/
/**
- * AuditEvent
- *
+ * AuditEvent
+ *
* @version $Id$
*/
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;
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;
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;
+ }
}
* ArchivaXworkUser
*
* @version $Id$
- * @plexus.component role="org.apache.maven.archiva.security.ArchivaXworkUser"
*/
-public class ArchivaXworkUser
+public final class ArchivaXworkUser
{
- public String getActivePrincipal( Map<String, ?> sessionMap )
+ private ArchivaXworkUser()
+ {
+ // no touchy
+ }
+
+ public static String getActivePrincipal( Map<String, ?> sessionMap )
{
SecuritySession securitySession =
(SecuritySession) sessionMap.get( SecuritySystemConstants.SECURITY_SESSION_KEY );
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;
*/
private UserRepositories userRepositories;
- /**
- * @plexus.requirement
- */
- private ArchivaXworkUser archivaXworkUser;
-
private BrowsingResults results;
private String groupId;
}
}
- @SuppressWarnings("unchecked")
- private String getPrincipal()
- {
- return archivaXworkUser.getActivePrincipal( ActionContext.getContext().getSession() );
- }
-
private List<String> getObservableRepos()
{
try
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;
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;
extends PlexusActionSupport
implements Validateable, Preparable, Auditable
{
- /**
- * @plexus.requirement
- */
- private ArchivaXworkUser archivaXworkUser;
-
/**
* The groupId of the artifact to be deleted.
*/
*/
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()
"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 );
}
}
- @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 ) );
}
}
- 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
}
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 );
- }
- }
}
* under the License.\r
*/\r
\r
+import java.util.ArrayList;\r
+import java.util.List;\r
import java.util.Map;\r
\r
+import org.apache.maven.archiva.repository.audit.AuditEvent;\r
+import org.apache.maven.archiva.repository.audit.AuditListener;\r
+import org.apache.maven.archiva.repository.audit.Auditable;\r
+import org.apache.maven.archiva.security.ArchivaXworkUser;\r
+import org.apache.struts2.ServletActionContext;\r
import org.apache.struts2.interceptor.SessionAware;\r
import org.slf4j.Logger;\r
import org.slf4j.LoggerFactory;\r
\r
+import com.opensymphony.xwork2.ActionContext;\r
import com.opensymphony.xwork2.ActionSupport;\r
\r
/**\r
*/\r
public abstract class PlexusActionSupport\r
extends ActionSupport\r
- implements SessionAware\r
+ implements SessionAware, Auditable\r
{\r
protected Map<?, ?> session;\r
\r
protected Logger log = LoggerFactory.getLogger( getClass() );\r
- \r
+\r
+ /**\r
+ * @plexus.requirement role="org.apache.maven.archiva.repository.audit.AuditListener"\r
+ */\r
+ private List<AuditListener> auditListeners = new ArrayList<AuditListener>();\r
+\r
@SuppressWarnings("unchecked")\r
public void setSession( Map map )\r
{\r
this.session = map;\r
}\r
+\r
+ public void addAuditListener( AuditListener listener )\r
+ {\r
+ this.auditListeners.add( listener );\r
+ }\r
+\r
+ public void clearAuditListeners()\r
+ {\r
+ this.auditListeners.clear();\r
+ }\r
+\r
+ public void removeAuditListener( AuditListener listener )\r
+ {\r
+ this.auditListeners.remove( listener );\r
+ }\r
+\r
+ protected void triggerAuditEvent( String repositoryId, String resource, String action )\r
+ {\r
+ AuditEvent event = new AuditEvent( repositoryId, getPrincipal(), resource, action );\r
+ event.setRemoteIP( ServletActionContext.getRequest().getRemoteAddr() );\r
+ \r
+ for ( AuditListener listener : auditListeners )\r
+ {\r
+ listener.auditEvent( event );\r
+ }\r
+ }\r
+\r
+ protected void triggerAuditEvent( String resource, String action )\r
+ {\r
+ AuditEvent event = new AuditEvent( getPrincipal(), resource, action );\r
+ event.setRemoteIP( ServletActionContext.getRequest().getRemoteAddr() );\r
+ \r
+ for ( AuditListener listener : auditListeners )\r
+ {\r
+ listener.auditEvent( event );\r
+ }\r
+ }\r
+\r
+ protected void triggerAuditEvent( String action )\r
+ {\r
+ AuditEvent event = new AuditEvent( getPrincipal(), action );\r
+ event.setRemoteIP( ServletActionContext.getRequest().getRemoteAddr() );\r
+ \r
+ for ( AuditListener listener : auditListeners )\r
+ {\r
+ listener.auditEvent( event );\r
+ }\r
+ }\r
+\r
+ @SuppressWarnings( "unchecked" )\r
+ protected String getPrincipal()\r
+ {\r
+ return ArchivaXworkUser.getActivePrincipal( ActionContext.getContext().getSession() );\r
+ }\r
}\r
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;
/**
*/
private UserRepositories userRepositories;
- /**
- * @plexus.requirement
- */
- private ArchivaXworkUser archivaXworkUser;
-
private static final String RESULTS = "results";
private static final String ARTIFACT = "artifact";
return INPUT;
}
- @SuppressWarnings("unchecked")
- private String getPrincipal()
- {
- return archivaXworkUser.getActivePrincipal( ActionContext.getContext().getSession() );
- }
-
private List<String> getObservableRepos()
{
try
this.userRepositories = userRepositories;
}
- public ArchivaXworkUser getArchivaXworkUser()
- {
- return archivaXworkUser;
- }
-
- public void setArchivaXworkUser( ArchivaXworkUser archivaXworkUser )
- {
- this.archivaXworkUser = archivaXworkUser;
- }
-
public Map<String, String> getSearchFields()
{
return searchFields;
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;
/**
*/
private UserRepositories userRepositories;
- /**
- * @plexus.requirement
- */
- private ArchivaXworkUser archivaXworkUser;
-
- /* .\ Input Parameters \.________________________________________ */
-
private String groupId;
private String artifactId;
return SUCCESS;
}
- @SuppressWarnings("unchecked")
- private String getPrincipal()
- {
- return archivaXworkUser.getActivePrincipal( ActionContext.getContext().getSession() );
- }
-
private List<String> getObservableRepos()
{
try
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;
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;
private RepositoryContentConsumers consumers;
/**
- * @plexus.requirement
- */
- private ArchivaXworkUser archivaXworkUser;
-
- /**
* The groupId of the artifact to be deployed.
*/
private String groupId;
*/
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();
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 );
}
}
- @SuppressWarnings("unchecked")
- private String getPrincipal()
- {
- return archivaXworkUser.getActivePrincipal( ActionContext.getContext().getSession() );
- }
-
private void copyFile( File sourceFile, File targetPath, String targetFilename )
throws IOException
{
}
}
- 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
}
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 );
- }
- }
}
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;
*/
public class DatabaseAction
extends PlexusActionSupport
- implements Preparable, SecureAction
+ implements Preparable, SecureAction, Auditable
{
/**
* @plexus.requirement
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();
}
{
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 );
+ }
+ }
+ }
}
* 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.
*/
public abstract class AbstractRepositoriesAdminAction
extends PlexusActionSupport
- implements SecureAction
+ implements SecureAction, Auditable
{
/**
* @plexus.requirement
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;
try
{
addRepository( repository, configuration );
+ triggerAuditEvent( repository.getId(), null, AuditEvent.ADD_MANAGED_REPO );
addRepositoryRoles( repository );
result = saveConfiguration( configuration );
}
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;
try
{
addRepository( repository, configuration );
+ triggerAuditEvent( repository.getId(), null, AuditEvent.ADD_REMOTE_REPO );
result = saveConfiguration( configuration );
}
catch ( IOException e )
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;
Configuration configuration = archivaConfiguration.getConfiguration();
cleanupRepositoryData( existingRepository );
removeRepository( repoid, configuration );
+ triggerAuditEvent( repoid, null, AuditEvent.DELETE_MANAGED_REPO );
result = saveConfiguration( configuration );
if ( result.equals( SUCCESS ) )
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;
Configuration configuration = archivaConfiguration.getConfiguration();
removeRepository( repoid, configuration );
+ triggerAuditEvent( repoid, null, AuditEvent.DELETE_REMOTE_REPO );
result = saveConfiguration( configuration );
cleanupRepositoryData( existingRepository );
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
}
config.removeRepositoryGroup( group );
+ triggerAuditEvent( AuditEvent.DELETE_REPO_GROUP + " " + repoGroupId );
return saveConfiguration( config );
}
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;
try
{
addRepository( repository, configuration );
+ triggerAuditEvent( repository.getId(), null, AuditEvent.MODIFY_MANAGED_REPO );
addRepositoryRoles( repository );
result = saveConfiguration( configuration );
}
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;
try
{
addRepository( repository, configuration );
+ triggerAuditEvent( repository.getId(), null, AuditEvent.MODIFY_REMOTE_REPO );
result = saveConfiguration( configuration );
}
catch ( IOException e )
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;
/**
}
configuration.addRepositoryGroup( repositoryGroup );
+ triggerAuditEvent( AuditEvent.ADD_REPO_GROUP + " " + repoGroupId );
return saveConfiguration( configuration );
}
// save repository group configuration
group.addRepository( repoId );
config.addRepositoryGroup( group );
+
+ triggerAuditEvent( repoId, null, AuditEvent.ADD_REPO_TO_GROUP + " " + repoGroupId );
return saveConfiguration( config );
}
// save repository group configuration
group.removeRepository( repoId );
config.addRepositoryGroup( group );
+
+ triggerAuditEvent( repoId, null, AuditEvent.DELETE_REPO_FROM_GROUP + " " + repoGroupId );
return saveConfiguration( config );
}
* 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;
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
*/
public class RepositoryScanningAction
extends PlexusActionSupport
- implements Preparable, Validateable, SecureAction
+ implements Preparable, Validateable, SecureAction, Auditable
{
/**
* @plexus.requirement
private String pattern;
private String fileTypeId;
-
+
public void addActionError( String anErrorMessage )
{
super.addActionError( anErrorMessage );
filetype.addPattern( pattern );
addActionMessage( "Added pattern \"" + pattern + "\" to filetype " + id );
+
+ triggerAuditEvent( AuditEvent.ADD_PATTERN + " " + pattern );
return saveConfiguration();
}
}
filetype.removePattern( getPattern() );
+
+ triggerAuditEvent( AuditEvent.REMOVE_PATTERN + " " + pattern );
return saveConfiguration();
}
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();
}
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();
}
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;
*/
import java.util.ArrayList;
-import java.util.Collections;
import java.util.List;
import org.apache.archiva.indexer.search.RepositorySearch;
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;
private MockControl archivaXworkUserControl;
- private ArchivaXworkUser archivaXworkUser;
-
private MockControl searchControl;
private RepositorySearch search;
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();
artifactDao = ( ArtifactDAO ) artifactDaoControl.getMock();
action.setArchivaConfiguration( archivaConfig );
- action.setArchivaXworkUser( archivaXworkUser );
action.setUserRepositories( userRepos );
action.setDao( dao );
action.setNexusSearch( search );
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 );
daoControl.verify();
}
- private String getActivePrincipal()
- {
- return archivaXworkUser.getActivePrincipal( Collections.<String,Object>emptyMap() );
- }
-
public void testSearchWithinSearchResults()
throws Exception
{
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 );
List<String> selectedRepos = new ArrayList<String>();
- archivaXworkUserControl.expectAndReturn( getActivePrincipal(), "user" );
+ archivaXworkUserControl.expectAndReturn( UserManager.GUEST_USERNAME, "user" );
userReposControl.expectAndReturn( userRepos.getObservableRepositoryIds( "user" ), selectedRepos );
SearchResults results = new SearchResults();
- archivaXworkUserControl.expectAndReturn( getActivePrincipal(), "user", 2 );
+ archivaXworkUserControl.expectAndReturn( UserManager.GUEST_USERNAME, "user", 2 );
userReposControl.expectAndReturn( userRepos.getObservableRepositoryIds( "user" ), selectedRepos );
SearchFields searchFields = new SearchFields( "org", null, null, null, null, selectedRepos );
- archivaXworkUserControl.expectAndReturn( getActivePrincipal(), "user" );
+ archivaXworkUserControl.expectAndReturn( UserManager.GUEST_USERNAME, "user" );
searchControl.expectAndReturn( search.search( "user", searchFields, limits ), results );
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 );
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 );
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
*