mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
Merge branch 'feature/RM-5235_Audit_DeleteUser' into 'master'
RM-5235_Audit_DeleteUser See merge request records-management/records-management!925
This commit is contained in:
@@ -4,6 +4,7 @@ rm.audit.delete-object=Delete Object
|
||||
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.linkTo=Link to
|
||||
rm.audit.moveTo=Move to
|
||||
rm.audit.copyTo=Copy to
|
||||
|
@@ -57,6 +57,13 @@
|
||||
<property name="label" value="rm.audit.create-person"/>
|
||||
</bean>
|
||||
|
||||
<bean id="audit-event.delete-person" parent="audit-event"
|
||||
class="org.alfresco.module.org_alfresco_module_rm.audit.event.DeletePersonAuditEvent">
|
||||
<property name="nodeService" ref="nodeService" />
|
||||
<property name="name" value="Delete Person" />
|
||||
<property name="label" value="rm.audit.delete-person" />
|
||||
</bean>
|
||||
|
||||
<bean id="audit-event.login-success" parent="audit-event" class="org.alfresco.module.org_alfresco_module_rm.audit.event.AuditEvent">
|
||||
<property name="name" value="Login.Success"/>
|
||||
<property name="label" value="rm.audit.login-succeeded"/>
|
||||
|
@@ -1514,6 +1514,15 @@ public class RecordsManagementAuditServiceImpl extends AbstractLifecycleBean
|
||||
json.put("nodeName", userName == null ? "": userName);
|
||||
json.put("createPerson", true);
|
||||
}
|
||||
else if (entry.getEvent().equals("Delete Person") && entry.getNodeRef() != null)
|
||||
{
|
||||
if (entry.getBeforeProperties() != null)
|
||||
{
|
||||
String userName = (String) entry.getBeforeProperties().get(ContentModel.PROP_USERNAME);
|
||||
json.put("nodeName", userName == null ? "" : userName);
|
||||
}
|
||||
json.put("deletePerson", true);
|
||||
}
|
||||
else
|
||||
{
|
||||
json.put("nodeName", entry.getNodeName() == null ? "": entry.getNodeName());
|
||||
@@ -1567,7 +1576,6 @@ public class RecordsManagementAuditServiceImpl extends AbstractLifecycleBean
|
||||
}
|
||||
|
||||
json.put("changedValues", changedValues);
|
||||
|
||||
writer.write(json.toString());
|
||||
}
|
||||
catch (JSONException je)
|
||||
|
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* #%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 <http://www.gnu.org/licenses/>.
|
||||
* #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 person deletion.
|
||||
*
|
||||
* @author Rodica Sutu
|
||||
* @since 2.7
|
||||
*/
|
||||
@BehaviourBean
|
||||
public class DeletePersonAuditEvent 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:person"
|
||||
)
|
||||
public void beforeDeleteNode(NodeRef nodeRef)
|
||||
{
|
||||
//retrieve the username property to be audited
|
||||
Map<QName, Serializable> userName = new HashMap<>();
|
||||
userName.put(ContentModel.PROP_USERNAME, nodeService.getProperty(nodeRef, ContentModel.PROP_USERNAME));
|
||||
|
||||
//audit the property values before the delete event
|
||||
recordsManagementAuditService.auditEvent(nodeRef, getName(), userName, null, true, false);
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -33,6 +33,8 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.module.org_alfresco_module_rm.audit.RecordsManagementAuditEntry;
|
||||
@@ -459,6 +461,63 @@ public class RecordsManagementAuditServiceImplTest extends BaseRMTestCase
|
||||
assertTrue("Expected to hit successful login attempt for Charles Dickons (cdickons)", found);
|
||||
}
|
||||
|
||||
/**
|
||||
* Given I have deleted a user
|
||||
* When I will get the RM audit filter by delete user event
|
||||
* Then there will be an entry for the deleted user
|
||||
* And the audit entry has the username property value audited
|
||||
* @throws Exception
|
||||
*/
|
||||
@org.junit.Test
|
||||
public void testAuditForDeletedUser() throws Exception
|
||||
{
|
||||
doBehaviourDrivenTest(new BehaviourDrivenTest()
|
||||
{
|
||||
final static String DELETE_USER_AUDIT_EVENT = "Delete Person";
|
||||
String userName = "auditDeleteUser";
|
||||
NodeRef user;
|
||||
List<RecordsManagementAuditEntry> entry;
|
||||
|
||||
@Override
|
||||
public void given() throws Exception
|
||||
{
|
||||
// create a user
|
||||
user = createPerson(userName);
|
||||
personService.deletePerson(userName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void when() throws Exception
|
||||
{
|
||||
// set the audit wuery param
|
||||
RecordsManagementAuditQueryParameters params = new RecordsManagementAuditQueryParameters();
|
||||
params.setEvent(DELETE_USER_AUDIT_EVENT);
|
||||
|
||||
// get the audit events for "Delete Person"
|
||||
entry = getAuditTrail(params, 1, ADMIN_USER);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void then() throws Exception
|
||||
{
|
||||
assertEquals("Delete user event is not audited.", DELETE_USER_AUDIT_EVENT, entry.get(0).getEvent());
|
||||
assertEquals(user.getId(), entry.get(0).getNodeName());
|
||||
assertEquals("Unexpected nr of properties audited for cm:person type when deleting a user.",
|
||||
1, entry.get(0).getBeforeProperties().size());
|
||||
assertEquals("Wrong value for username property is audited",
|
||||
userName, entry.get(0).getBeforeProperties().get(ContentModel.PROP_USERNAME));
|
||||
}
|
||||
@Override
|
||||
public void after()
|
||||
{
|
||||
// Stop and delete all entries
|
||||
rmAuditService.stopAuditLog(filePlan);
|
||||
rmAuditService.clearAuditLog(filePlan);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
/** === Helper methods === */
|
||||
|
||||
private List<RecordsManagementAuditEntry> getAuditTrail(String asUser)
|
||||
|
Reference in New Issue
Block a user