Search in sources :

Example 11 with IdmAuditDto

use of eu.bcvsolutions.idm.core.api.audit.dto.IdmAuditDto in project CzechIdMng by bcvsolutions.

the class IdmRoleController method findRevisions.

@ResponseBody
@RequestMapping(value = "{backendId}/revisions", method = RequestMethod.GET)
@PreAuthorize("hasAuthority('" + CoreGroupPermission.ROLE_READ + "')")
@ApiOperation(value = "Role audit - read all revisions", nickname = "getRoleRevisions", tags = { IdmIdentityController.TAG }, authorizations = { @Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { @AuthorizationScope(scope = CoreGroupPermission.ROLE_READ, description = "") }), @Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { @AuthorizationScope(scope = CoreGroupPermission.ROLE_READ, description = "") }) })
public Resources<?> findRevisions(@ApiParam(value = "Role's uuid identifier or code.", required = true) @PathVariable("backendId") String backendId, Pageable pageable) {
    IdmRoleDto originalDto = getDto(backendId);
    if (originalDto == null) {
        throw new ResultCodeException(CoreResultCode.NOT_FOUND, ImmutableMap.of("role", backendId));
    }
    // 
    Page<IdmAuditDto> results = this.auditService.findRevisionsForEntity(IdmRole.class.getSimpleName(), originalDto.getId(), pageable);
    return toResources(results, IdmAuditDto.class);
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmAuditDto(eu.bcvsolutions.idm.core.api.audit.dto.IdmAuditDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IdmRole(eu.bcvsolutions.idm.core.model.entity.IdmRole) 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)

Example 12 with IdmAuditDto

use of eu.bcvsolutions.idm.core.api.audit.dto.IdmAuditDto in project CzechIdMng by bcvsolutions.

the class IdmAuditController method get.

@ResponseBody
@RequestMapping(method = RequestMethod.GET, value = "/{backendId}")
@PreAuthorize("hasAuthority('" + CoreGroupPermission.AUDIT_READ + "')")
@Override
@ApiOperation(value = "Audit log detail", nickname = "getAuditLog", response = IdmAuditDto.class, tags = { IdmAuditController.TAG }, authorizations = { @Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { @AuthorizationScope(scope = CoreGroupPermission.AUDIT_READ, description = "") }), @Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { @AuthorizationScope(scope = CoreGroupPermission.AUDIT_READ, description = "") }) })
public ResponseEntity<?> get(@ApiParam(value = "Audit log's identifier.", required = true) @PathVariable @NotNull String backendId) {
    IdmAuditDto audit = auditService.get(backendId);
    // Map with all values
    Map<String, Object> revisionValues = null;
    Object revision = null;
    try {
        revision = auditService.findVersion(Class.forName(audit.getType()), audit.getEntityId(), Long.valueOf(audit.getId().toString()));
    } catch (NumberFormatException | ClassNotFoundException e) {
        throw new ResultCodeException(CoreResultCode.BAD_VALUE, ImmutableMap.of("audit", audit), e);
    }
    revisionValues = auditService.getValuesFromVersion(revision);
    // create DTO and fill with values from IdmAudit
    IdmAuditDto auditDto = new IdmAuditDto();
    mapper.map(audit, auditDto);
    auditDto.setRevisionValues(revisionValues);
    return new ResponseEntity<IdmAuditDto>(auditDto, HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) IdmAuditDto(eu.bcvsolutions.idm.core.api.audit.dto.IdmAuditDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) 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)

Example 13 with IdmAuditDto

use of eu.bcvsolutions.idm.core.api.audit.dto.IdmAuditDto in project CzechIdMng by bcvsolutions.

the class DefaultAuditServiceTest method auditQuickSearch.

@Test
public void auditQuickSearch() {
    IdmAuditFilter filter = new IdmAuditFilter();
    filter.setModifier("admin");
    filter.setType(IdmRole.class.getSimpleName());
    Pageable pageable = new PageRequest(0, 10);
    List<IdmAuditDto> result = auditService.find(filter, pageable).getContent();
    for (IdmAuditDto idmAudit : result) {
        assertEquals("admin", idmAudit.getModifier());
        assertEquals(IdmRole.class.getName(), idmAudit.getType());
    }
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) Pageable(org.springframework.data.domain.Pageable) IdmAuditDto(eu.bcvsolutions.idm.core.api.audit.dto.IdmAuditDto) IdmAuditFilter(eu.bcvsolutions.idm.core.api.audit.dto.filter.IdmAuditFilter) IdmRole(eu.bcvsolutions.idm.core.model.entity.IdmRole) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 14 with IdmAuditDto

use of eu.bcvsolutions.idm.core.api.audit.dto.IdmAuditDto in project CzechIdMng by bcvsolutions.

the class DefaultAuditServiceTest method editAndEditOneTrasaction.

@Test
public void editAndEditOneTrasaction() {
    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");
            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(3, 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 15 with IdmAuditDto

use of eu.bcvsolutions.idm.core.api.audit.dto.IdmAuditDto in project CzechIdMng by bcvsolutions.

the class DefaultAuditServiceTest method testFindRevision.

@Test
@Transactional
public void testFindRevision() {
    IdmRole roleRevision = auditService.findRevision(IdmRole.class, UUID.randomUUID(), 123456l);
    assertEquals(null, roleRevision);
    List<IdmAuditDto> result = auditService.find(null).getContent();
    // test only first and second
    try {
        IdmAuditDto idmAudit = result.get(0);
        BaseEntity object = (BaseEntity) auditService.findRevision(Class.forName(idmAudit.getType()), idmAudit.getEntityId(), (Long) idmAudit.getId());
        if (object != null) {
            assertEquals((UUID) object.getId(), idmAudit.getEntityId());
            Class.forName(idmAudit.getType()).cast(object);
        }
        // second
        idmAudit = result.get(1);
        object = (BaseEntity) auditService.findRevision(Class.forName(idmAudit.getType()), idmAudit.getEntityId(), (Long) idmAudit.getId());
        if (object != null) {
            assertEquals((UUID) object.getId(), idmAudit.getEntityId());
            Class.forName(idmAudit.getType()).cast(object);
        }
    } catch (ClassNotFoundException e) {
        fail(e.getLocalizedMessage());
    }
/*
		 * IdmRole roleRevision2 = auditService.getPreviousVersion(roleRevision,
		 * (Long)audit.getId()); assertNotEquals(null, roleRevision2);
		 * assertEquals("audit_test_role", roleRevision2.getName());
		 */
}
Also used : IdmAuditDto(eu.bcvsolutions.idm.core.api.audit.dto.IdmAuditDto) BaseEntity(eu.bcvsolutions.idm.core.api.entity.BaseEntity) IdmRole(eu.bcvsolutions.idm.core.model.entity.IdmRole) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

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