Search in sources :

Example 6 with IdmAuditDto

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"));
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmAuditDto(eu.bcvsolutions.idm.core.api.audit.dto.IdmAuditDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 7 with IdmAuditDto

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"));
}
Also used : LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) IdmAuditDto(eu.bcvsolutions.idm.core.api.audit.dto.IdmAuditDto) TransactionStatus(org.springframework.transaction.TransactionStatus) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 8 with IdmAuditDto

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());
}
Also used : LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) IdmAuditDto(eu.bcvsolutions.idm.core.api.audit.dto.IdmAuditDto) TransactionStatus(org.springframework.transaction.TransactionStatus) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 9 with IdmAuditDto

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;
        }
    });
}
Also used : IdmAuditDto(eu.bcvsolutions.idm.core.api.audit.dto.IdmAuditDto) TransactionStatus(org.springframework.transaction.TransactionStatus) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity) Map(java.util.Map) MultiValueMap(org.springframework.util.MultiValueMap) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 10 with IdmAuditDto

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);
}
Also used : IdmAuditDto(eu.bcvsolutions.idm.core.api.audit.dto.IdmAuditDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

IdmAuditDto (eu.bcvsolutions.idm.core.api.audit.dto.IdmAuditDto)17 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)8 Test (org.junit.Test)8 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)7 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)6 IdmIdentity (eu.bcvsolutions.idm.core.model.entity.IdmIdentity)5 ApiOperation (io.swagger.annotations.ApiOperation)5 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)5 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)5 IdmRole (eu.bcvsolutions.idm.core.model.entity.IdmRole)4 TransactionStatus (org.springframework.transaction.TransactionStatus)4 LinkedMultiValueMap (org.springframework.util.LinkedMultiValueMap)4 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)3 IdmAuditFilter (eu.bcvsolutions.idm.core.api.audit.dto.filter.IdmAuditFilter)2 PageRequest (org.springframework.data.domain.PageRequest)2 Pageable (org.springframework.data.domain.Pageable)2 IdmTreeNodeDto (eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto)1 AbstractEntity (eu.bcvsolutions.idm.core.api.entity.AbstractEntity)1 BaseEntity (eu.bcvsolutions.idm.core.api.entity.BaseEntity)1