From 6a1209462fabc2ebb49046693cd42705741809db Mon Sep 17 00:00:00 2001 From: "Maria Odea B. Ching" Date: Mon, 14 Dec 2009 02:06:05 +0000 Subject: [MRM-1296] Audit Log Report 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 | 2 +- .../archiva-model/src/main/mdo/archiva-base.xml | 75 +++++++++++++++++++++- .../archiva/database/ArchivaAuditLogsDao.java | 35 ++++++++++ .../MostRecentArchivaAuditLogsConstraint.java | 43 +++++++++++++ .../database/jdo/JdoArchivaAuditLogsDao.java | 61 ++++++++++++++++++ .../archiva/web/action/PlexusActionSupport.java | 17 +++++ .../maven/archiva/web/action/UploadAction.java | 3 +- .../action/reports/ViewAuditLogReportAction.java | 58 +++++++++++++---- .../webapp/WEB-INF/jsp/reports/auditLogReport.jsp | 25 +++++++- 9 files changed, 303 insertions(+), 16 deletions(-) create mode 100644 archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/ArchivaAuditLogsDao.java create mode 100644 archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/MostRecentArchivaAuditLogsConstraint.java create mode 100644 archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoArchivaAuditLogsDao.java diff --git a/archiva-modules/archiva-base/archiva-model/pom.xml b/archiva-modules/archiva-base/archiva-model/pom.xml index f686016c9..413dc92ea 100755 --- a/archiva-modules/archiva-base/archiva-model/pom.xml +++ b/archiva-modules/archiva-base/archiva-model/pom.xml @@ -70,7 +70,7 @@ org.codehaus.modello modello-maven-plugin - 1.2.1 + 1.2.3 false src/main/mdo/archiva-base.xml diff --git a/archiva-modules/archiva-base/archiva-model/src/main/mdo/archiva-base.xml b/archiva-modules/archiva-base/archiva-model/src/main/mdo/archiva-base.xml index de08a8d7b..676e49ccd 100644 --- a/archiva-modules/archiva-base/archiva-model/src/main/mdo/archiva-base.xml +++ b/archiva-modules/archiva-base/archiva-model/src/main/mdo/archiva-base.xml @@ -5,7 +5,7 @@ xsd.target-namespace="http://archiva.apache.org/model/1.2.0"> archiva-base-model ArchivaBaseModel - 1.2.1 + 1.2.3 Archiva Model @@ -75,6 +75,14 @@ * + + archivaAuditLogs + 1.3.0+ + + ArchivaAuditLogs + * + + @@ -2278,5 +2286,70 @@ + + ArchivaAuditLogs + 1.2.3+ + + + repositoryId + 1.2.3+ + false + true + String + + The repository id where the operation was done. + + + + eventDate + 1.2.3+ + false + true + Date + + The timestamp on when the event happened. + + + + artifact + 1.2.3+ + false + false + String + + The affected artifact, if there is one. + + + + event + 1.2.3+ + false + false + String + + The event that happened. + + + + username + 1.2.3+ + false + true + String + + The user who executed the event. + + + + + + 1.2.3+ + + + + 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 index 000000000..639c5d623 --- /dev/null +++ b/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/ArchivaAuditLogsDao.java @@ -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 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 index 000000000..af3c791a3 --- /dev/null +++ b/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/MostRecentArchivaAuditLogsConstraint.java @@ -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 index 000000000..2e73fb1cc --- /dev/null +++ b/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoArchivaAuditLogsDao.java @@ -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 queryAuditLogs( Constraint constraint ) + throws ObjectNotFoundException, ArchivaDatabaseException + { + return (List) jdo.queryObjects( ArchivaAuditLogs.class, constraint ); + } + + public ArchivaAuditLogs saveAuditLogs( ArchivaAuditLogs logs ) + { + return (ArchivaAuditLogs) jdo.saveObject( logs ); + } +} diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/PlexusActionSupport.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/PlexusActionSupport.java index 5a1d04da7..c936965aa 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/PlexusActionSupport.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/PlexusActionSupport.java @@ -20,11 +20,14 @@ package org.apache.maven.archiva.web.action; */ import java.util.ArrayList; +import java.util.Calendar; import java.util.List; import java.util.Map; import javax.servlet.http.HttpServletRequest; +import org.apache.maven.archiva.database.ArchivaAuditLogsDao; +import org.apache.maven.archiva.model.ArchivaAuditLogs; import org.apache.maven.archiva.repository.audit.AuditEvent; import org.apache.maven.archiva.repository.audit.AuditListener; import org.apache.maven.archiva.repository.audit.Auditable; @@ -53,6 +56,11 @@ public abstract class PlexusActionSupport */ private List auditListeners = new ArrayList(); + /** + * @plexus.requirement role-hint="jdo" + */ + private ArchivaAuditLogsDao auditLogsDao; + private String principal; @SuppressWarnings("unchecked") @@ -85,6 +93,15 @@ public abstract class PlexusActionSupport { listener.auditEvent( event ); } + + ArchivaAuditLogs auditLogs = new ArchivaAuditLogs(); + auditLogs.setArtifact( resource ); + auditLogs.setEvent( action ); + auditLogs.setEventDate( Calendar.getInstance().getTime() ); + auditLogs.setRepositoryId( repositoryId ); + auditLogs.setUsername( getPrincipal() ); + + auditLogsDao.saveAuditLogs( auditLogs ); } protected void triggerAuditEvent( String resource, String action ) diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/UploadAction.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/UploadAction.java index c61ba16ff..8e0c83fbb 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/UploadAction.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/UploadAction.java @@ -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(); diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/reports/ViewAuditLogReportAction.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/reports/ViewAuditLogReportAction.java index 8aae78e7b..f8b0bf929 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/reports/ViewAuditLogReportAction.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/reports/ViewAuditLogReportAction.java @@ -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 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 auditLogs = new ArrayList(); + 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 getAuditLogs() + { + return auditLogs; + } + + public void setAuditLogs( List auditLogs ) + { + this.auditLogs = auditLogs; + } + + public int getRowCount() + { + return rowCount; + } + + public void setRowCount( int rowCount ) + { + this.rowCount = rowCount; + } } diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/reports/auditLogReport.jsp b/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/reports/auditLogReport.jsp index bf4629712..d968a7ab6 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/reports/auditLogReport.jsp +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/reports/auditLogReport.jsp @@ -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" %> @@ -44,7 +45,7 @@
- +
@@ -80,7 +81,27 @@
-
+ + + + + + + + + + + + + + + + + + + + +
EventRepositoryArtifactEvent DateUsername
${auditLog.event}${auditLog.repositoryId}${auditLog.artifact}${auditLog.eventDate}${auditLog.username}
-- cgit v1.2.3