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);
}
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);
}
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());
}
}
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());
}
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());
*/
}
Aggregations