use of eu.bcvsolutions.idm.core.api.dto.filter.IdmProfileFilter in project CzechIdMng by bcvsolutions.
the class IdentityDeleteProcessor method process.
@Override
public EventResult<IdmIdentityDto> process(EntityEvent<IdmIdentityDto> event) {
IdmIdentityDto identity = event.getContent();
UUID identityId = identity.getId();
Assert.notNull(identityId, "Identity ID is required!");
boolean forceDelete = getBooleanProperty(PROPERTY_FORCE_DELETE, event.getProperties());
//
// delete contract slices
IdmContractSliceFilter sliceFilter = new IdmContractSliceFilter();
sliceFilter.setIdentity(identityId);
contractSliceService.find(sliceFilter, null).forEach(guarantee -> {
contractSliceService.delete(guarantee);
});
// delete contract slice guarantees
IdmContractSliceGuaranteeFilter sliceGuaranteeFilter = new IdmContractSliceGuaranteeFilter();
sliceGuaranteeFilter.setGuaranteeId(identityId);
contractSliceGuaranteeService.find(sliceGuaranteeFilter, null).forEach(guarantee -> {
contractSliceGuaranteeService.delete(guarantee);
});
//
// contracts
identityContractService.findAllByIdentity(identityId).forEach(identityContract -> {
// when identity is deleted, then HR processes has to be skipped (prevent to update deleted identity, when contract is removed)
Map<String, Serializable> properties = new HashMap<>();
properties.put(IdmIdentityContractService.SKIP_HR_PROCESSES, Boolean.TRUE);
// propagate force attribute
properties.put(PROPERTY_FORCE_DELETE, forceDelete);
// prepare event
IdentityContractEvent contractEvent = new IdentityContractEvent(IdentityContractEventType.DELETE, identityContract, properties);
contractEvent.setPriority(PriorityType.HIGH);
//
identityContractService.publish(contractEvent);
});
// delete contract guarantees
IdmContractGuaranteeFilter filter = new IdmContractGuaranteeFilter();
filter.setGuaranteeId(identityId);
contractGuaranteeService.find(filter, null).forEach(guarantee -> {
contractGuaranteeService.delete(guarantee);
});
// remove role guarantee
IdmRoleGuaranteeFilter roleGuaranteeFilter = new IdmRoleGuaranteeFilter();
roleGuaranteeFilter.setGuarantee(identityId);
roleGuaranteeService.find(roleGuaranteeFilter, null).forEach(roleGuarantee -> {
roleGuaranteeService.delete(roleGuarantee);
});
// remove password
passwordProcessor.deletePassword(identity);
// delete password history for identity
passwordHistoryService.deleteAllByIdentity(identityId);
// disable related tokens - tokens has to be disabled to prevent their usage (when tokens are deleted, then token is recreated)
tokenManager.disableTokens(identity);
//
// delete all identity's profiles
IdmProfileFilter profileFilter = new IdmProfileFilter();
profileFilter.setIdentityId(identityId);
profileService.find(profileFilter, null).forEach(profile -> {
profileService.delete(profile);
});
// remove all IdentityRoleValidRequest for this identity
List<IdmIdentityRoleValidRequestDto> validRequests = identityRoleValidRequestService.findAllValidRequestForIdentityId(identityId);
identityRoleValidRequestService.deleteAll(validRequests);
//
// delete all identity's delegations - delegate
IdmDelegationDefinitionFilter delegationFilter = new IdmDelegationDefinitionFilter();
delegationFilter.setDelegateId(identityId);
delegationDefinitionService.find(delegationFilter, null).forEach(delegation -> {
delegationDefinitionService.delete(delegation);
});
//
// delete all identity's delegations - delegator
delegationFilter = new IdmDelegationDefinitionFilter();
delegationFilter.setDelegatorId(identityId);
delegationDefinitionService.find(delegationFilter, null).forEach(delegation -> {
delegationDefinitionService.delete(delegation);
});
// deletes identity
if (forceDelete) {
LOG.debug("Identity [{}] should be deleted by caller after all asynchronus processes are completed.", identityId);
//
// dirty flag only - will be processed after asynchronous events ends
IdmEntityStateDto stateDeleted = new IdmEntityStateDto();
stateDeleted.setEvent(event.getId());
stateDeleted.setResult(new OperationResultDto.Builder(OperationState.RUNNING).setModel(new DefaultResultModel(CoreResultCode.DELETED)).build());
entityStateManager.saveState(identity, stateDeleted);
//
// set disabled (automatically)
identity.setState(IdentityState.DISABLED);
service.saveInternal(identity);
} else {
// delete all role requests where is this identity applicant
IdmRoleRequestFilter roleRequestFilter = new IdmRoleRequestFilter();
roleRequestFilter.setApplicantId(identityId);
roleRequestService.find(roleRequestFilter, null).forEach(request -> {
roleRequestService.delete(request);
});
//
service.deleteInternal(identity);
}
return new DefaultEventResult<>(event, this);
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmProfileFilter in project CzechIdMng by bcvsolutions.
the class IdmProfileControllerRestTest method testFindByIdentity.
@Test
public void testFindByIdentity() {
IdmIdentityDto owner = getHelper().createIdentity((GuardedString) null);
IdmProfileDto profileOne = prepareDto();
profileOne.setIdentity(owner.getId());
profileOne = createDto(profileOne);
// other
createDto();
// other
createDto();
IdmProfileFilter filter = new IdmProfileFilter();
filter.setIdentityId(owner.getId());
List<IdmProfileDto> results = find(filter);
//
Assert.assertEquals(1, results.size());
Assert.assertEquals(profileOne, results.get(0));
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmProfileFilter in project CzechIdMng by bcvsolutions.
the class DefaultIdmProfileService method findOneByIdentity.
private IdmProfileDto findOneByIdentity(IdmIdentityDto identity, BasePermission... permission) {
Assert.notNull(identity, "Identity is required.");
//
IdmProfileFilter filter = new IdmProfileFilter();
filter.setIdentityId(identity.getId());
List<IdmProfileDto> profiles = find(filter, null, permission).getContent();
//
return profiles.isEmpty() ? null : profiles.get(0);
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmProfileFilter in project CzechIdMng by bcvsolutions.
the class IdmProfileController method toFilter.
@Override
protected IdmProfileFilter toFilter(MultiValueMap<String, Object> parameters) {
IdmProfileFilter filter = new IdmProfileFilter(parameters);
filter.setIdentityId(getParameterConverter().toEntityUuid(parameters, IdmProfileFilter.PARAMETER_IDENTITY_ID, IdmIdentityDto.class));
return filter;
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmProfileFilter in project CzechIdMng by bcvsolutions.
the class IdmIdentityController method collapsePanel.
/**
* Collapse panel on frontend - persist updated identity profile setting.
*
* @param backendId identity codeable identifier
* @param panelId panel identitfier ~ uiKey
* @return updated profile
* @since 11.2.0
*/
@RequestMapping(value = "/{backendId}/profile/panels/{panelId}/collapse", method = RequestMethod.PATCH)
@ResponseBody
@PreAuthorize("hasAuthority('" + CoreGroupPermission.PROFILE_UPDATE + "')")
@ApiOperation(value = "Collapse panel", nickname = "collapsePanel", tags = { IdmIdentityController.TAG }, notes = "Collapse panel - persist updated identity profile setting.", authorizations = { @Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { @AuthorizationScope(scope = CoreGroupPermission.PROFILE_UPDATE, description = "") }), @Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { @AuthorizationScope(scope = CoreGroupPermission.PROFILE_UPDATE, description = "") }) })
public ResponseEntity<?> collapsePanel(@ApiParam(value = "Identity's uuid identifier or username.", required = true) @PathVariable @NotNull String backendId, @ApiParam(value = "Panel identifier - uiKey.", required = true) @PathVariable @NotNull String panelId) {
IdmIdentityDto identity = getDto(backendId);
if (identity == null) {
throw new ResultCodeException(CoreResultCode.NOT_FOUND, ImmutableMap.of("entity", backendId));
}
IdmProfileDto profile = profileService.collapsePanel(backendId, panelId, IdmBasePermission.UPDATE);
//
// refresh with permissions are needed
IdmProfileFilter context = new IdmProfileFilter();
context.setAddPermissions(true);
profile = profileController.getService().get(profile, context, IdmBasePermission.READ);
//
return new ResponseEntity<>(profileController.toResource(profile), HttpStatus.OK);
}
Aggregations