]> source.dussan.org Git - archiva.git/commitdiff
[MRM-1093] Log configuration and repository changes made.
authorBrett Porter <brett@apache.org>
Fri, 20 Mar 2009 16:12:10 +0000 (16:12 +0000)
committerBrett Porter <brett@apache.org>
Fri, 20 Mar 2009 16:12:10 +0000 (16:12 +0000)
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

24 files changed:
archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/maven/archiva/consumers/core/repository/AbstractRepositoryPurge.java
archiva-modules/archiva-base/archiva-consumers/archiva-database-consumers/src/main/java/org/apache/maven/archiva/consumers/database/DatabaseCleanupRemoveArtifactConsumer.java
archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/audit/AuditEvent.java
archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/audit/AuditLog.java
archiva-modules/archiva-web/archiva-security/src/main/java/org/apache/maven/archiva/security/ArchivaXworkUser.java
archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/BrowseAction.java
archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/DeleteArtifactAction.java
archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/PlexusActionSupport.java
archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/SearchAction.java
archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/ShowArtifactAction.java
archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/UploadAction.java
archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/database/DatabaseAction.java
archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/AbstractRepositoriesAdminAction.java
archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/AddManagedRepositoryAction.java
archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/AddRemoteRepositoryAction.java
archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryAction.java
archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteRemoteRepositoryAction.java
archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteRepositoryGroupAction.java
archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/EditManagedRepositoryAction.java
archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/EditRemoteRepositoryAction.java
archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/RepositoryGroupsAction.java
archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/scanning/RepositoryScanningAction.java
archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/SearchActionTest.java
archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteRepositoryGroupActionTest.java

index 46b0e9b121cfacc57f589a1335ca7fb92491fde5..467c56af46aaa56e9db99b0f8401e6bb7529fb97 100644 (file)
@@ -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<RepositoryListener> listeners;
+         
+         private Logger logger = LoggerFactory.getLogger( "org.apache.archiva.AuditLog" );
+       
+         private static final char DELIM = ' ';
 
     public AbstractRepositoryPurge( ManagedRepositoryContent repository, List<RepositoryListener> 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 + "<system-purge>" + DELIM + "<system>" + DELIM + '\"' + resource + '\"' +
+            DELIM + '\"' + action + '\"';
+        
+        logger.info( msg );
+    }
 }
index c849cc88e92fb7fda0783d03bfa07e6f27621824..c4539c6f3383a4f7568d96df78b3c56fac2e1146 100644 (file)
@@ -32,6 +32,10 @@ import org.apache.maven.archiva.model.RepositoryProblem;
 import org.apache.maven.archiva.repository.ManagedRepositoryContent;
 import org.apache.maven.archiva.repository.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 + "<db-scan>" + DELIM + "<system>" + DELIM + '\"' + resource + '\"' +
+            DELIM + '\"' + action + '\"';
+        
+        logger.info( msg );
+    }
 }
index 643d5c0e97f64101f2e718d45072ada5663297a0..ead95b502c6a19c4f23d51be41a31453a626b5bf 100644 (file)
@@ -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;
index f6ae7f906c1027237df71d40f040d9c5b20a2358..d99c9d7bccbae4a8fee2bdb016eca8b36d8cc54a 100644 (file)
@@ -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;
+    }
 }
index 2cdb7f7f943360acdbc8efc67ba908d653ae383a..a12f4d72ca76eb9e824874fd43a9d9b2ad107d14 100644 (file)
@@ -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<String, ?> sessionMap )
+    private ArchivaXworkUser()
+    {
+        // no touchy
+    }
+    
+    public static String getActivePrincipal( Map<String, ?> sessionMap )
     {
         SecuritySession securitySession =
             (SecuritySession) sessionMap.get( SecuritySystemConstants.SECURITY_SESSION_KEY );
index 8d986cd7864a9bb23c29d243647ab2970006d69f..64c967cc5587d46d4f373db24f655d56dc755c6b 100644 (file)
@@ -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
index da2f1ebb7e1a2bba98fe19eb8dee6fcbb8713ccf..7d2d62b2569e794a5fb84d10d1d8ac7e02e31220 100644 (file)
@@ -48,7 +48,6 @@ import org.apache.maven.archiva.repository.RepositoryContentFactory;
 import org.apache.maven.archiva.repository.RepositoryException;
 import org.apache.maven.archiva.repository.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<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 );
-        }
-    }
 }
index 025e4f51a9352de34fcf1db51f600bb7d1e85a6c..8780aba449132fd13c50f86d2a68b1ffcdf25f4d 100644 (file)
@@ -19,12 +19,20 @@ package org.apache.maven.archiva.web.action;
  * 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
@@ -32,15 +40,74 @@ import com.opensymphony.xwork2.ActionSupport;
  */\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
index 493121c908da333cb32510d30910073b4641304f..4060df7301fda8a14d68fa087a6854872d52e8c2 100644 (file)
@@ -45,14 +45,12 @@ import org.apache.maven.archiva.database.constraints.UniqueVersionConstraint;
 import org.apache.maven.archiva.model.ArchivaArtifact;
 import org.apache.maven.archiva.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;
index 869abd5f7e4b8e324a64ea466efbe6250c803f74..be7ba5d3a9a81b5bda7d81ef4cf31cde178b4fb2 100644 (file)
@@ -34,9 +34,7 @@ import org.apache.maven.archiva.security.AccessDeniedException;
 import org.apache.maven.archiva.security.ArchivaSecurityException;
 import org.apache.maven.archiva.security.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
index c39850c1a66de45dc62bdd008821544d89f9d76d..ac92822244635fdcd58b9bdbd49a50a3552d95d5 100644 (file)
@@ -48,7 +48,6 @@ import org.apache.maven.archiva.repository.RepositoryException;
 import org.apache.maven.archiva.repository.RepositoryNotFoundException;
 import org.apache.maven.archiva.repository.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 );
-        }
-    }
 }
index d040980efe350ade04a4ef2fba62e6bacd236111..9c7d1b518745cc1e6ec8d669dc211c8560733e9c 100644 (file)
@@ -28,6 +28,8 @@ import org.apache.maven.archiva.configuration.Configuration;
 import org.apache.maven.archiva.configuration.DatabaseScanningConfiguration;
 import org.apache.maven.archiva.configuration.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 );
+            }
+        }
+    }
 }
index 5b1324dd8761ff1129c49957f595d6f02db94a63..144bbaa00d63c6b9d4e3828ba4a8fd9eab5618d4 100644 (file)
@@ -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
index 4d3341521dfd8bac5d97b0046014d28c10c926a7..b51bc7f9489a531e27a9b3fa15867c6e8a476854 100644 (file)
@@ -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 );
         }
index d624220f627a2f54a34b8c69bab8859561759980..3b3d7b1d68c2e87fbdd84e3c1ab5c8850e36c0e6 100644 (file)
@@ -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 )
index 2ef89df702251913ae99284ac5da216103f90d26..a2793ce0964b267df9c2ca651847562a154446a1 100644 (file)
@@ -34,6 +34,7 @@ import org.apache.maven.archiva.database.constraints.RepositoryContentStatistics
 import org.apache.maven.archiva.model.ArchivaArtifact;
 import org.apache.maven.archiva.model.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 ) )
index 13e6536cd9f1415d52635bde7630c6199cd0de6c..9d9fef04be346957e317ea3ed960187048575530 100644 (file)
@@ -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 );
index 5e99c9c810796f55dee0d32be114c264c69a5b12..0c3aad84a1bbc6d7198d160fecaef6bb9fcf2cb7 100644 (file)
@@ -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 );
     }
        
index 90bea2e73b7bb8b3d0f3a4f5e7b48d0d49518648..de0cdd242320dddcd7e554b4f8f053a61b6d0de2 100644 (file)
@@ -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 );
         }
index ce32241ef6e52040fa7474f534c4a345f67379b1..61dd3f6a4b4455334f9a31d854ce613aaec88faf 100644 (file)
@@ -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 )
index 2e8ab406cedf1a89635e62e168e87dd86d3da173..fd5acb8b028452ab00f5669dad5fbea310d7bad0 100644 (file)
@@ -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 );
     }
index 599a23d0a845bfe05995490cf323b1ebb5cdaba3..ca68e7c693eea32573de258e2a368ed9d42c2864 100644 (file)
@@ -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;
index 68296ed97103347b82298f7e358d7d2655966169..a0c26efe10076d05541368b4876b9a4e0df69951 100644 (file)
@@ -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 );
         
index 49b6f59830961d95d2d6159526c4f342b0252227..8d4a8ae0c6cf7b7c74a0d31aa853f8408b3fc250 100644 (file)
@@ -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
  *