use of eu.bcvsolutions.idm.core.api.audit.dto.IdmAuditDto in project CzechIdMng by bcvsolutions.
the class DefaultAuditServiceTest method identityAuditCreateModify.
@Test
public void identityAuditCreateModify() {
IdmIdentityDto identity = this.constructIdentity("aud_test", "test", "test");
identity = identityService.save(identity);
identity = identityService.get(identity.getId());
IdmRoleDto role = roleService.save(constructRole("aud_test_role"));
helper.createIdentityRole(identity, role);
//
List<IdmAuditDto> result = auditService.findRevisions(IdmIdentity.class, identity.getId());
// only one remove audited list
assertEquals(1, result.size());
IdmAuditDto audit = result.get(result.size() - 1);
assertEquals(RevisionType.ADD.toString(), audit.getModification());
// TODO: list aren't audited
// assertEquals(true, audit.getChangedAttributes().contains("roles"));
// assertEquals(2, audit.getModifiedEntityNames().size());
//
// assertEquals(true,
// audit.getModifiedEntityNames().toString().contains("IdmIdentityRole"));
}
use of eu.bcvsolutions.idm.core.api.audit.dto.IdmAuditDto in project CzechIdMng by bcvsolutions.
the class DefaultAuditServiceTest method createAndEditOneTransaction.
@Test
public void createAndEditOneTransaction() {
String username = "test_user_" + System.currentTimeMillis();
IdmIdentityDto newIdentity = getTransactionTemplate().execute(new TransactionCallback<IdmIdentityDto>() {
public IdmIdentityDto doInTransaction(TransactionStatus transactionStatus) {
IdmIdentityDto identity = new IdmIdentityDto();
identity.setUsername(username);
identity.setFirstName(username);
identity.setLastName(username);
identity = identityService.save(identity);
//
identity.setEmail("example@example.tld");
identity.setLastName(username + "edit");
return identityService.save(identity);
}
});
assertEquals(newIdentity.getUsername(), username);
MultiValueMap<String, Object> parameters = new LinkedMultiValueMap<>();
parameters.put("username", ImmutableList.of(username));
List<IdmAuditDto> audits = auditService.findEntityWithRelation(IdmIdentity.class, parameters, null).getContent();
assertEquals(2, audits.size());
//
String contractChangedAttribute = audits.get(0).getChangedAttributes();
assertTrue(contractChangedAttribute.contains("externe"));
assertTrue(contractChangedAttribute.contains("position"));
assertTrue(contractChangedAttribute.contains("identity"));
assertTrue(contractChangedAttribute.contains("disabled"));
assertTrue(contractChangedAttribute.contains("main"));
//
String identityChangedAttribute = audits.get(1).getChangedAttributes();
assertTrue(identityChangedAttribute.contains("state"));
assertTrue(identityChangedAttribute.contains("email"));
assertTrue(identityChangedAttribute.contains("lastName"));
}
use of eu.bcvsolutions.idm.core.api.audit.dto.IdmAuditDto in project CzechIdMng by bcvsolutions.
the class DefaultAuditServiceTest method editAndDeleteOneTrasaction.
@Test
public void editAndDeleteOneTrasaction() {
String username = "test_user_" + System.currentTimeMillis();
IdmIdentityDto identity = new IdmIdentityDto();
identity.setUsername(username);
identity.setFirstName(username);
identity.setLastName(username);
identityService.save(identity);
IdmIdentityDto newIdentity = getTransactionTemplate().execute(new TransactionCallback<IdmIdentityDto>() {
public IdmIdentityDto doInTransaction(TransactionStatus transactionStatus) {
IdmIdentityDto identity = identityService.getByCode(username);
identity.setFirstName(username + "--edit");
identity = identityService.save(identity);
// hibernate send this as one query
//
identityService.delete(identity);
return null;
}
});
assertEquals(newIdentity, null);
MultiValueMap<String, Object> parameters = new LinkedMultiValueMap<>();
parameters.put("username", ImmutableList.of(username));
List<IdmAuditDto> audits = auditService.findEntityWithRelation(IdmIdentity.class, parameters, null).getContent();
// add idenity + contract -- delete identity + contract
assertEquals(4, audits.size());
}
use of eu.bcvsolutions.idm.core.api.audit.dto.IdmAuditDto in project CzechIdMng by bcvsolutions.
the class DefaultAuditServiceTest method diffAuditTest.
@Test
public void diffAuditTest() {
IdmIdentityDto identity = this.constructIdentity("test_diff", "John", "Doe");
identity = saveInTransaction(identity, identityService);
// identityRepository.save(identity);
identity = identityService.get(identity.getId());
identity.setEmail("example@example.ex");
identity.setFirstName("Leonard");
identity.setLastName("Nimoy");
identity = saveInTransaction(identity, identityService);
// identityRepository.save(identity);
identity = identityService.get(identity.getId());
identity.setEmail(null);
identity.setFirstName("John");
identity.setLastName("Doe");
identity = saveInTransaction(identity, identityService);
List<IdmAuditDto> result = auditService.findRevisions(IdmIdentity.class, identity.getId());
assertEquals(3, result.size());
getTransactionTemplate().execute(new TransactionCallback<Object>() {
public Object doInTransaction(TransactionStatus transactionStatus) {
IdmAuditDto idmAudit = result.get(0);
IdmIdentity version1 = auditService.findVersion(IdmIdentity.class, idmAudit.getEntityId(), Long.parseLong(idmAudit.getId().toString()));
idmAudit = result.get(1);
IdmIdentity version2 = auditService.findVersion(IdmIdentity.class, idmAudit.getEntityId(), Long.parseLong(idmAudit.getId().toString()));
idmAudit = result.get(2);
IdmIdentity version3 = auditService.findVersion(IdmIdentity.class, idmAudit.getEntityId(), Long.parseLong(idmAudit.getId().toString()));
// sample test to default value
assertEquals(version1.getFirstName(), "John");
assertEquals(version1.getLastName(), "Doe");
assertEquals(version2.getFirstName(), "Leonard");
assertEquals(version2.getLastName(), "Nimoy");
assertEquals(version2.getEmail(), "example@example.ex");
assertEquals(version3.getFirstName(), "John");
assertEquals(version3.getLastName(), "Doe");
assertNull(version3.getEmail());
// get diff between version
// test version #1 with #2
Map<String, Object> diff = auditService.getDiffBetweenVersion(parseSerializableToString(result.get(0).getId()), parseSerializableToString(result.get(1).getId()));
// 3 modification from IdmIdentity
assertEquals(3, diff.size());
assertTrue(diff.containsKey("firstName"));
assertTrue(diff.containsKey("lastName"));
assertTrue(diff.containsKey("email"));
assertEquals("Leonard", diff.get("firstName"));
assertEquals("Nimoy", diff.get("lastName"));
assertEquals("example@example.ex", diff.get("email"));
// test version #2 with #3
diff = auditService.getDiffBetweenVersion(parseSerializableToString(result.get(1).getId()), parseSerializableToString(result.get(2).getId()));
// 3 modification from IdmIdentity
assertEquals(3, diff.size());
assertTrue(diff.containsKey("firstName"));
assertTrue(diff.containsKey("lastName"));
assertTrue(diff.containsKey("email"));
assertEquals("John", diff.get("firstName"));
assertEquals("Doe", diff.get("lastName"));
assertEquals(null, diff.get("email"));
// final test version #1 with #3
diff = auditService.getDiffBetweenVersion(parseSerializableToString(result.get(0).getId()), parseSerializableToString(result.get(2).getId()));
// all diff values are from AbstractEntity modifier, modified date, modifier id
// modified only
assertEquals(0, diff.size());
return null;
}
});
}
use of eu.bcvsolutions.idm.core.api.audit.dto.IdmAuditDto in project CzechIdMng by bcvsolutions.
the class IdmIdentityController method findRevisions.
@ResponseBody
@RequestMapping(value = "/{backendId}/revisions", method = RequestMethod.GET)
@PreAuthorize("hasAuthority('" + CoreGroupPermission.IDENTITY_READ + "')")
@ApiOperation(value = "Identity audit - read all revisions", nickname = "getIdentityRevisions", tags = { IdmIdentityController.TAG }, authorizations = { @Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { @AuthorizationScope(scope = CoreGroupPermission.IDENTITY_READ, description = "") }), @Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { @AuthorizationScope(scope = CoreGroupPermission.IDENTITY_READ, description = "") }) })
public Resources<?> findRevisions(@ApiParam(value = "Identity's uuid identifier or username.", required = true) @PathVariable("backendId") String backendId, Pageable pageable) {
IdmIdentityDto originalEntity = getDto(backendId);
if (originalEntity == null) {
throw new ResultCodeException(CoreResultCode.NOT_FOUND, ImmutableMap.of("identity", backendId));
}
// get original entity id
Page<IdmAuditDto> results = this.auditService.findRevisionsForEntity(IdmIdentity.class.getSimpleName(), originalEntity.getId(), pageable);
return toResources(results, IdmAuditDto.class);
}
Aggregations