]> source.dussan.org Git - archiva.git/commitdiff
[MRM-1296] Audit Log Report
authorMaria Odea B. Ching <oching@apache.org>
Mon, 14 Dec 2009 02:06:05 +0000 (02:06 +0000)
committerMaria Odea B. Ching <oching@apache.org>
Mon, 14 Dec 2009 02:06:05 +0000 (02:06 +0000)
o created data model, dao and query constraint object for audit logs
o save events in database

git-svn-id: https://svn.apache.org/repos/asf/archiva/branches/MRM-1296@890155 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-base/archiva-model/pom.xml
archiva-modules/archiva-base/archiva-model/src/main/mdo/archiva-base.xml
archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/ArchivaAuditLogsDao.java [new file with mode: 0644]
archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/MostRecentArchivaAuditLogsConstraint.java [new file with mode: 0644]
archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoArchivaAuditLogsDao.java [new file with mode: 0644]
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/UploadAction.java
archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/reports/ViewAuditLogReportAction.java
archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/reports/auditLogReport.jsp

index f686016c916f6c97c09fde76c1951c87da23bdc0..413dc92ea8c7e26f80eb20f39aa3bf90897a866f 100755 (executable)
@@ -70,7 +70,7 @@
         <groupId>org.codehaus.modello</groupId>
         <artifactId>modello-maven-plugin</artifactId>
         <configuration>
-          <version>1.2.1</version>
+          <version>1.2.3</version>
           <packageWithVersion>false</packageWithVersion>
           <models>
             <model>src/main/mdo/archiva-base.xml</model>
index de08a8d7b8512323cb27cb8cd22822f183399585..676e49ccdebbdc15bab64d4cf4cfd19a4f945f2a 100644 (file)
@@ -5,7 +5,7 @@
        xsd.target-namespace="http://archiva.apache.org/model/1.2.0">
   <id>archiva-base-model</id>
   <name>ArchivaBaseModel</name>
-  <version>1.2.1</version>
+  <version>1.2.3</version>
   <description>Archiva Model</description>
   <defaults>
     <default>
             <multiplicity>*</multiplicity>
           </association>
         </field>
+        <field>
+          <name>archivaAuditLogs</name>
+          <version>1.3.0+</version>
+          <association>
+            <type>ArchivaAuditLogs</type>
+            <multiplicity>*</multiplicity>
+          </association>
+        </field>
       </fields>
       <codeSegments>
         <codeSegment>
         </codeSegment>
       </codeSegments>
     </class>
+    <class stash.storable="true"
+           jpox.table="AUDIT_LOGS">
+      <name>ArchivaAuditLogs</name>
+      <version>1.2.3+</version>
+      <fields>
+        <field stash.maxSize="50">
+          <name>repositoryId</name>
+          <version>1.2.3+</version>
+          <identifier>false</identifier>
+          <required>true</required>
+          <type>String</type>
+          <description>
+            The repository id where the operation was done.
+          </description>
+        </field>
+        <field>
+          <name>eventDate</name>
+          <version>1.2.3+</version>
+          <identifier>false</identifier>
+          <required>true</required>
+          <type>Date</type>
+          <description>
+            The timestamp on when the event happened.
+          </description>
+        </field>
+        <field>
+          <name>artifact</name>
+          <version>1.2.3+</version>
+          <identifier>false</identifier>
+          <required>false</required>
+          <type>String</type>
+          <description>
+            The affected artifact, if there is one.
+          </description>
+        </field>
+        <field>
+          <name>event</name>
+          <version>1.2.3+</version>
+          <identifier>false</identifier>
+          <required>false</required>
+          <type>String</type>
+          <description>
+            The event that happened.
+          </description>
+        </field>
+        <field>
+          <name>username</name>
+          <version>1.2.3+</version>
+          <identifier>false</identifier>
+          <required>true</required>
+          <type>String</type>
+          <description>
+            The user who executed the event.
+          </description>
+        </field>
+      </fields>
+      <codeSegments>
+        <codeSegment>
+          <version>1.2.3+</version>
+          <code><![CDATA[
+    private static final long serialVersionUID = -7113629916828442780L;
+          ]]></code>
+        </codeSegment>
+      </codeSegments>
+    </class>
   </classes>
 </model>
diff --git a/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/ArchivaAuditLogsDao.java b/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/ArchivaAuditLogsDao.java
new file mode 100644 (file)
index 0000000..639c5d6
--- /dev/null
@@ -0,0 +1,35 @@
+package org.apache.maven.archiva.database;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.List;
+
+import org.apache.maven.archiva.model.ArchivaAuditLogs;
+
+public interface ArchivaAuditLogsDao
+{
+    public List<ArchivaAuditLogs> queryAuditLogs( Constraint constraint )
+        throws ObjectNotFoundException, ArchivaDatabaseException;
+
+    public ArchivaAuditLogs saveAuditLogs( ArchivaAuditLogs logs );
+    
+    public void deleteAuditLogs( ArchivaAuditLogs logs )
+        throws ArchivaDatabaseException;
+}
diff --git a/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/MostRecentArchivaAuditLogsConstraint.java b/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/MostRecentArchivaAuditLogsConstraint.java
new file mode 100644 (file)
index 0000000..af3c791
--- /dev/null
@@ -0,0 +1,43 @@
+package org.apache.maven.archiva.database.constraints;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.archiva.model.ArchivaAuditLogs;
+
+public class MostRecentArchivaAuditLogsConstraint
+    extends AbstractSimpleConstraint
+{
+    private String sql;
+
+    public MostRecentArchivaAuditLogsConstraint()
+    {
+        sql = "SELECT FROM " + ArchivaAuditLogs.class.getName() + " ORDER BY eventDate DESCENDING RANGE 0,1";
+    }
+
+    public Class<?> getResultClass()
+    {
+        return ArchivaAuditLogs.class;
+    }
+
+    public String getSelectSql()
+    {
+        return sql;
+    }
+}
diff --git a/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoArchivaAuditLogsDao.java b/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoArchivaAuditLogsDao.java
new file mode 100644 (file)
index 0000000..2e73fb1
--- /dev/null
@@ -0,0 +1,61 @@
+package org.apache.maven.archiva.database.jdo;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.List;
+
+import org.apache.maven.archiva.database.ArchivaAuditLogsDao;
+import org.apache.maven.archiva.database.ArchivaDatabaseException;
+import org.apache.maven.archiva.database.Constraint;
+import org.apache.maven.archiva.database.ObjectNotFoundException;
+import org.apache.maven.archiva.model.ArchivaAuditLogs;
+
+/**
+ * JdoArchivaAuditLogsDao
+ * 
+ * @version  
+ * 
+ * @plexus.component role-hint="jdo"
+ */
+public class JdoArchivaAuditLogsDao
+    implements ArchivaAuditLogsDao
+{
+    /**
+     * @plexus.requirement role-hint="archiva"
+     */
+    private JdoAccess jdo;
+
+    public void deleteAuditLogs( ArchivaAuditLogs logs )
+        throws ArchivaDatabaseException
+    {
+        jdo.removeObject( logs );
+    }
+
+    public List<ArchivaAuditLogs> queryAuditLogs( Constraint constraint )
+        throws ObjectNotFoundException, ArchivaDatabaseException
+    {
+        return (List<ArchivaAuditLogs>) jdo.queryObjects( ArchivaAuditLogs.class, constraint );
+    }
+
+    public ArchivaAuditLogs saveAuditLogs( ArchivaAuditLogs logs )
+    {
+        return (ArchivaAuditLogs) jdo.saveObject( logs );
+    }
+}
index 5a1d04da7fc84d6d00de20dcb049151bc1da1f09..c936965aa1680b347342c79491bcf5f5080845a9 100644 (file)
@@ -20,11 +20,14 @@ package org.apache.maven.archiva.web.action;
  */\r
 \r
 import java.util.ArrayList;\r
+import java.util.Calendar;\r
 import java.util.List;\r
 import java.util.Map;\r
 \r
 import javax.servlet.http.HttpServletRequest;\r
 \r
+import org.apache.maven.archiva.database.ArchivaAuditLogsDao;\r
+import org.apache.maven.archiva.model.ArchivaAuditLogs;\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
@@ -53,6 +56,11 @@ public abstract class PlexusActionSupport
      */\r
     private List<AuditListener> auditListeners = new ArrayList<AuditListener>();\r
 \r
+    /**\r
+     * @plexus.requirement role-hint="jdo"\r
+     */\r
+    private ArchivaAuditLogsDao auditLogsDao;\r
+    \r
     private String principal;\r
 \r
     @SuppressWarnings("unchecked")\r
@@ -85,6 +93,15 @@ public abstract class PlexusActionSupport
         {\r
             listener.auditEvent( event );\r
         }\r
+        \r
+        ArchivaAuditLogs auditLogs = new ArchivaAuditLogs();\r
+        auditLogs.setArtifact( resource );\r
+        auditLogs.setEvent( action );\r
+        auditLogs.setEventDate( Calendar.getInstance().getTime() );\r
+        auditLogs.setRepositoryId( repositoryId );\r
+        auditLogs.setUsername( getPrincipal() );\r
+        \r
+        auditLogsDao.saveAuditLogs( auditLogs );\r
     }\r
 \r
     protected void triggerAuditEvent( String resource, String action )\r
index c61ba16ffd10ca6d8561a0dbb0274c6288f77713..8e0c83fbb910dc49d13a1628500a12bb89eb6555 100644 (file)
@@ -41,6 +41,7 @@ import org.apache.maven.archiva.common.utils.VersionUtil;
 import org.apache.maven.archiva.configuration.ArchivaConfiguration;
 import org.apache.maven.archiva.configuration.Configuration;
 import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
+import org.apache.maven.archiva.database.ArchivaAuditLogsDao;
 import org.apache.maven.archiva.model.ArchivaProjectModel;
 import org.apache.maven.archiva.model.ArchivaRepositoryMetadata;
 import org.apache.maven.archiva.model.ArtifactReference;
@@ -149,7 +150,7 @@ public class UploadAction
      * @plexus.requirement
      */
     private ArchivaTaskScheduler scheduler;
-
+    
     private ChecksumAlgorithm[] algorithms = new ChecksumAlgorithm[]{ChecksumAlgorithm.SHA1, ChecksumAlgorithm.MD5};
 
     private ProjectModelWriter pomWriter = new ProjectModel400Writer();
index 8aae78e7b6a5eb35159bd65dc79c0deb5b31e0ef..f8b0bf929ac66a284dc8ef1eb705483f7492b787 100644 (file)
@@ -25,6 +25,12 @@ import java.util.List;
 
 import javax.servlet.http.HttpServletRequest;
 
+import org.apache.maven.archiva.database.ArchivaAuditLogsDao;
+import org.apache.maven.archiva.database.ArchivaDatabaseException;
+import org.apache.maven.archiva.database.Constraint;
+import org.apache.maven.archiva.database.ObjectNotFoundException;
+import org.apache.maven.archiva.database.constraints.MostRecentArchivaAuditLogsConstraint;
+import org.apache.maven.archiva.model.ArchivaAuditLogs;
 import org.apache.maven.archiva.security.AccessDeniedException;
 import org.apache.maven.archiva.security.ArchivaSecurityException;
 import org.apache.maven.archiva.security.PrincipalNotFoundException;
@@ -51,6 +57,11 @@ public class ViewAuditLogReportAction
      */
     private UserRepositories userRepositories;
     
+    /**
+     * @plexus.requirement role-hint="jdo"
+     */
+    private ArchivaAuditLogsDao auditLogsDao;
+    
     private String repository;
 
     private List<String> repositories;
@@ -61,16 +72,8 @@ public class ViewAuditLogReportAction
         
     private int rowCount = 30;
     
-    public int getRowCount()
-    {
-        return rowCount;
-    }
-
-    public void setRowCount( int rowCount )
-    {
-        this.rowCount = rowCount;
-    }
-
+    private List<ArchivaAuditLogs> auditLogs = new ArrayList<ArchivaAuditLogs>();    
+    
     public SecureActionBundle getSecureActionBundle()
         throws SecureActionException
     {        
@@ -87,12 +90,25 @@ public class ViewAuditLogReportAction
     {     
         repositories = getObservableRepositories();
         
+        Constraint constraint = new MostRecentArchivaAuditLogsConstraint();
         
+        try
+        {
+            this.auditLogs = auditLogsDao.queryAuditLogs( constraint );            
+        }
+        catch( ObjectNotFoundException e )
+        {
+            log.warn( "No audit logs found." );
+        }
+        catch ( ArchivaDatabaseException e )
+        {
+            log.warn( "Error occurred while querying audit logs." );
+        }
     }
     
     public String execute()
         throws Exception
-    {
+    {   
         return SUCCESS;
     }
     
@@ -156,4 +172,24 @@ public class ViewAuditLogReportAction
     {
         this.artifactId = artifactId;
     }
+    
+    public List<ArchivaAuditLogs> getAuditLogs()
+    {
+        return auditLogs;
+    }
+
+    public void setAuditLogs( List<ArchivaAuditLogs> auditLogs )
+    {
+        this.auditLogs = auditLogs;
+    }
+
+    public int getRowCount()
+    {
+        return rowCount;
+    }
+
+    public void setRowCount( int rowCount )
+    {
+        this.rowCount = rowCount;
+    }
 }
index bf46297129a1378eb3065f9ee5625549e7a0c861..d968a7ab632b4f5913425c09475b0aa9a0a2ace0 100644 (file)
@@ -19,6 +19,7 @@
 
 <%@ taglib prefix="s" uri="/struts-tags" %>
 <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
+<%@ taglib uri="http://www.extremecomponents.org" prefix="ec" %>
 
 <html>
 <head>
@@ -44,7 +45,7 @@
 <div id="contentArea">
   
   <s:form action="viewAuditLogReport" namespace="/report" validate="false">
-  
+     
     <div id="auditLogReport">  
                <s:select label="Repository" name="repository" list="repositories"/>
                
                
            <s:submit value="View Audit Log"/>
     </div>
-  </s:form>    
+  </s:form> 
+  
+  
+  <table border="1">
+    <tr>
+      <th align="center">Event</th>
+      <th align="center">Repository</th>
+      <th align="center">Artifact</th>
+      <th align="center">Event Date</th>
+      <th align="center">Username</th>
+    </tr>
+    <c:forEach items="${auditLogs}" var="auditLog" varStatus="i">
+      <tr>
+        <td>${auditLog.event}</td>
+        <td>${auditLog.repositoryId}</td>
+          <td>${auditLog.artifact}</td>
+          <td>${auditLog.eventDate}</td>
+          <td>${auditLog.username}</td>
+        </tr>
+    </c:forEach>
+  </table>   
 
 </div>