Search in sources :

Example 1 with IdmAuditDto

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

the class IdmTreeNodeController method findRevisions.

@ResponseBody
@RequestMapping(value = "{backendId}/revisions", method = RequestMethod.GET)
@PreAuthorize("hasAuthority('" + CoreGroupPermission.AUDIT_READ + "')")
@ApiOperation(value = "Tree node audit - read all revisions", nickname = "getTreeNodeRevisions", tags = { IdmTreeNodeController.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 Resources<?> findRevisions(@ApiParam(value = "Node's uuid identifier.", required = true) @PathVariable("backendId") String backendId, Pageable pageable) {
    IdmTreeNodeDto treeNode = getDto(backendId);
    if (treeNode == null) {
        throw new ResultCodeException(CoreResultCode.NOT_FOUND, ImmutableMap.of("treeNode", backendId));
    }
    Page<IdmAuditDto> results = this.auditService.findRevisionsForEntity(IdmTreeNode.class.getSimpleName(), UUID.fromString(backendId), pageable);
    return toResources(results, IdmTreeNode.class);
}
Also used : IdmTreeNode(eu.bcvsolutions.idm.core.model.entity.IdmTreeNode) IdmAuditDto(eu.bcvsolutions.idm.core.api.audit.dto.IdmAuditDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) 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 2 with IdmAuditDto

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

the class IdmAuditController method previousVersion.

@ResponseBody
@RequestMapping(method = RequestMethod.GET, value = "/{revId}/diff/previous")
@PreAuthorize("hasAuthority('" + CoreGroupPermission.AUDIT_READ + "')")
@ApiOperation(value = "Audit log detail", nickname = "getAuditLogPreviousVersion", 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 = "") }) }, notes = "Returns previous version for given audit log")
public ResponseEntity<?> previousVersion(@ApiParam(value = "Audit log's identifier.", required = true) @PathVariable @NotNull String revId) {
    IdmAuditDto currentAudit = auditService.get(revId);
    IdmAuditDto previousAudit;
    ResponseEntity<IdmAuditDto> resource = null;
    try {
        IdmAuditDto dto = null;
        previousAudit = auditService.findPreviousRevision(Long.valueOf(currentAudit.getId().toString()));
        // previous version dost'n exist
        if (previousAudit != null) {
            dto = new IdmAuditDto();
            mapper.map(previousAudit, dto);
            dto.setRevisionValues(auditService.getValuesFromVersion(auditService.findPreviousVersion(Class.forName(previousAudit.getType()), previousAudit.getEntityId(), Long.valueOf(previousAudit.getId().toString()))));
            resource = new ResponseEntity<IdmAuditDto>(dto, HttpStatus.OK);
        } else {
            resource = new ResponseEntity<IdmAuditDto>(HttpStatus.NOT_FOUND);
        }
    } catch (ClassNotFoundException e) {
        throw new ResultCodeException(CoreResultCode.NOT_FOUND, ImmutableMap.of("audit class", currentAudit.getType()), e);
    }
    return resource;
}
Also used : 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 3 with IdmAuditDto

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

the class DefaultAuditService method findPreviousVersion.

@Override
public Object findPreviousVersion(Long currentRevisionId) {
    IdmAuditDto revision = this.get(currentRevisionId);
    Object result = null;
    IdmAuditDto previousRevision;
    try {
        previousRevision = this.findPreviousRevision(currentRevisionId);
        if (previousRevision != null) {
            result = this.find(Class.forName(previousRevision.getType()), previousRevision.getEntityId(), Long.valueOf(previousRevision.getId().toString()));
        }
    } catch (ClassNotFoundException e) {
        throw new ResultCodeException(CoreResultCode.NOT_FOUND, ImmutableMap.of("class", revision.getType()), e);
    }
    return result;
}
Also used : IdmAuditDto(eu.bcvsolutions.idm.core.api.audit.dto.IdmAuditDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException)

Example 4 with IdmAuditDto

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

the class DefaultAuditService method getDiffBetweenVersion.

@Override
public Map<String, Object> getDiffBetweenVersion(String clazz, Long firstRevId, Long secondRevId) {
    Map<String, Object> result = new HashMap<>();
    IdmAuditDto firstRevision = this.get(firstRevId);
    // first revision must exist
    if (firstRevision == null) {
        throw new ResultCodeException(CoreResultCode.NOT_FOUND, ImmutableMap.of("audit", firstRevId));
    }
    if (clazz == null) {
        clazz = firstRevision.getType();
    }
    IdmAuditDto secondRevision = null;
    if (secondRevId == null) {
        try {
            secondRevision = (IdmAuditDto) this.findPreviousVersion(Class.forName(clazz), firstRevision.getEntityId(), Long.valueOf(firstRevision.getId().toString()));
        } catch (NumberFormatException e) {
            throw new ResultCodeException(CoreResultCode.BAD_VALUE, ImmutableMap.of("audit", firstRevision.getId()), e);
        } catch (ClassNotFoundException e) {
            throw new ResultCodeException(CoreResultCode.NOT_FOUND, ImmutableMap.of("audit class", clazz), e);
        }
    } else {
        secondRevision = this.get(secondRevId);
    }
    // check if we have second revision
    if (secondRevision == null) {
        throw new ResultCodeException(CoreResultCode.NOT_FOUND, ImmutableMap.of("audit", secondRevId));
    }
    // check if revision are from same type (class, entity id)
    if (!firstRevision.getEntityId().equals(secondRevision.getEntityId())) {
        throw new ResultCodeException(CoreResultCode.AUDIT_REVISION_NOT_SAME, ImmutableMap.of("revision", clazz));
    }
    // now we will receive version from audit tables
    try {
        Object firstVersion = this.getRevision(clazz, firstRevision.getEntityId(), firstRevId);
        Object secondVersion = this.getRevision(clazz, secondRevision.getEntityId(), secondRevId);
        List<String> auditedClass = this.getAllAuditedEntitiesNames();
        Map<String, Object> firstValues = null;
        Map<String, Object> secondValues = null;
        // first revision is DEL, all attributes are null
        if (firstRevision.getModification().equals(RevisionType.DEL.name())) {
            firstValues = Collections.emptyMap();
        } else {
            firstValues = this.getValuesFromVersion(firstVersion, auditedClass);
        }
        if (secondRevision.getModification().equals(RevisionType.DEL.name())) {
            secondValues = Collections.emptyMap();
        } else {
            secondValues = this.getValuesFromVersion(secondVersion, auditedClass);
        }
        Set<Entry<String, Object>> entries = firstValues.entrySet();
        if (entries.isEmpty()) {
            entries = secondValues.entrySet();
        }
        for (Entry<String, Object> entry : entries) {
            if (!Objects.equals(entry.getValue(), secondValues.get(entry.getKey()))) {
                result.put(entry.getKey(), secondValues.get(entry.getKey()));
            }
        }
    } catch (ClassNotFoundException e) {
        throw new ResultCodeException(CoreResultCode.NOT_FOUND, ImmutableMap.of("audit class", clazz), e);
    }
    return result;
}
Also used : Entry(java.util.Map.Entry) HashMap(java.util.HashMap) IdmAuditDto(eu.bcvsolutions.idm.core.api.audit.dto.IdmAuditDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException)

Example 5 with IdmAuditDto

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

the class DefaultAuditService method findRevisions.

@Override
public <T> List<IdmAuditDto> findRevisions(Class<T> classType, UUID entityId) {
    IdmAuditFilter filter = new IdmAuditFilter();
    filter.setEntityId(entityId);
    filter.setType(classType.getName());
    Pageable page = new PageRequest(0, Integer.MAX_VALUE, new Sort("timestamp"));
    Page<IdmAuditDto> result = this.find(filter, page);
    return result.getContent();
}
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) Sort(org.springframework.data.domain.Sort)

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