From 9a8cc02e51c2a79beb50396981217f620a8a95b6 Mon Sep 17 00:00:00 2001 From: Tom Page Date: Tue, 24 Apr 2018 08:45:56 +0100 Subject: [PATCH] RM-5236 Audit events for creating and deleting a user group. --- .../messages/audit-service.properties | 2 + .../rm-audit-context.xml | 12 +++ .../event/CreateUserGroupAuditEvent.java | 50 +++++++++++ .../event/DeleteUserGroupAuditEvent.java | 82 +++++++++++++++++++ 4 files changed, 146 insertions(+) create mode 100644 rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/audit/event/CreateUserGroupAuditEvent.java create mode 100644 rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/audit/event/DeleteUserGroupAuditEvent.java diff --git a/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/messages/audit-service.properties b/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/messages/audit-service.properties index 5f8a331f0a..b066c5d93d 100644 --- a/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/messages/audit-service.properties +++ b/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/messages/audit-service.properties @@ -5,6 +5,8 @@ rm.audit.login-succeeded=Login Successful rm.audit.login-failed=Login Unsuccessful rm.audit.create-person=Create User rm.audit.delete-person=Delete User +rm.audit.create-userGroup=Create User Group +rm.audit.delete-userGroup=Delete User Group rm.audit.linkTo=Link to rm.audit.moveTo=Move to rm.audit.copyTo=Copy to diff --git a/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/rm-audit-context.xml b/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/rm-audit-context.xml index 1a1b993d1a..7b5f03018e 100644 --- a/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/rm-audit-context.xml +++ b/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/rm-audit-context.xml @@ -64,6 +64,18 @@ + + + + + + + + + + + diff --git a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/audit/event/CreateUserGroupAuditEvent.java b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/audit/event/CreateUserGroupAuditEvent.java new file mode 100644 index 0000000000..034e23061e --- /dev/null +++ b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/audit/event/CreateUserGroupAuditEvent.java @@ -0,0 +1,50 @@ +/* + * #%L + * Alfresco Records Management Module + * %% + * Copyright (C) 2005 - 2018 Alfresco Software Limited + * %% + * This file is part of the Alfresco software. + * - + * If the software was purchased under a paid Alfresco license, the terms of + * the paid license agreement will prevail. Otherwise, the software is + * provided under the following open source license terms: + * - + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * - + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * - + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + * #L% + */ +package org.alfresco.module.org_alfresco_module_rm.audit.event; + +import org.alfresco.repo.node.NodeServicePolicies.OnCreateNodePolicy; +import org.alfresco.repo.policy.annotation.Behaviour; +import org.alfresco.repo.policy.annotation.BehaviourBean; +import org.alfresco.repo.policy.annotation.BehaviourKind; +import org.alfresco.service.cmr.repository.ChildAssociationRef; + +/** + * Audits user group creation. + * + * @author Tom Page + * @since 2.7 + */ +@BehaviourBean +public class CreateUserGroupAuditEvent extends AuditEvent implements OnCreateNodePolicy +{ + @Override + @Behaviour(kind = BehaviourKind.CLASS, type = "cm:authorityContainer") + public void onCreateNode(ChildAssociationRef childAssocRef) + { + recordsManagementAuditService.auditEvent(childAssocRef.getChildRef(), getName()); + } +} diff --git a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/audit/event/DeleteUserGroupAuditEvent.java b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/audit/event/DeleteUserGroupAuditEvent.java new file mode 100644 index 0000000000..810aca345d --- /dev/null +++ b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/audit/event/DeleteUserGroupAuditEvent.java @@ -0,0 +1,82 @@ +/* + * #%L + * Alfresco Records Management Module + * %% + * Copyright (C) 2005 - 2018 Alfresco Software Limited + * %% + * This file is part of the Alfresco software. + * - + * If the software was purchased under a paid Alfresco license, the terms of + * the paid license agreement will prevail. Otherwise, the software is + * provided under the following open source license terms: + * - + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * - + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * - + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + * #L% + */ + +package org.alfresco.module.org_alfresco_module_rm.audit.event; + +import java.io.Serializable; +import java.util.HashMap; +import java.util.Map; + +import org.alfresco.model.ContentModel; +import org.alfresco.repo.node.NodeServicePolicies.BeforeDeleteNodePolicy; +import org.alfresco.repo.policy.annotation.Behaviour; +import org.alfresco.repo.policy.annotation.BehaviourBean; +import org.alfresco.repo.policy.annotation.BehaviourKind; +import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.service.cmr.repository.NodeService; +import org.alfresco.service.namespace.QName; + +/** + * Audits user group deletion. + * + * @author Tom Page + * @since 2.7 + */ +@BehaviourBean +public class DeleteUserGroupAuditEvent extends AuditEvent implements BeforeDeleteNodePolicy +{ + /** Node Service */ + private NodeService nodeService; + + /** + * Sets the node service + * + * @param nodeService nodeService to set + */ + public void setNodeService(NodeService nodeService) + { + this.nodeService = nodeService; + } + + /** + * Behaviour that will audit user deletion + * + * @param nodeRef the node to be deleted + */ + @Override + @Behaviour(kind = BehaviourKind.CLASS, type = "cm:authorityContainer") + public void beforeDeleteNode(NodeRef nodeRef) + { + // Retrieve the authority name property to be audited + Map auditProperties = new HashMap<>(); + auditProperties.put(ContentModel.PROP_AUTHORITY_NAME, + nodeService.getProperty(nodeRef, ContentModel.PROP_AUTHORITY_NAME)); + + //audit the property values before the delete event + recordsManagementAuditService.auditEvent(nodeRef, getName(), auditProperties, null, true, false); + } +}