use of eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleRequestDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmAutomaticRoleRequestServiceIntegrationTest method testCreateAutomaticAttributeRoleWithApproval.
@Test
public void testCreateAutomaticAttributeRoleWithApproval() {
IdmRoleDto role = prepareRole();
IdmIdentityDto identity = helper.createIdentity();
IdmIdentityDto guaranteeIdentity = helper.createIdentity();
IdmRoleGuaranteeDto guarantee = new IdmRoleGuaranteeDto();
guarantee.setRole(role.getId());
guarantee.setGuarantee(guaranteeIdentity.getId());
role.getGuarantees().add(guarantee);
role = roleService.save(role);
IdmAutomaticRoleAttributeDto automaticRole = new IdmAutomaticRoleAttributeDto();
automaticRole.setRole(role.getId());
automaticRole.setName(role.getName());
IdmAutomaticRoleAttributeRuleDto rule = new IdmAutomaticRoleAttributeRuleDto();
rule.setAttributeName(IdmIdentity_.username.getName());
rule.setComparison(AutomaticRoleAttributeRuleComparison.EQUALS);
rule.setType(AutomaticRoleAttributeRuleType.IDENTITY);
rule.setValue(identity.getUsername());
// Create automatic role via manager
try {
automaticRole = automaticRoleManager.createAutomaticRoleByAttribute(automaticRole, false, rule);
} catch (AcceptedException ex) {
// The request is in approval
Assert.assertNotNull(ex.getIdentifier());
UUID requestId = UUID.fromString(ex.getIdentifier());
loginAsNoAdmin(guaranteeIdentity.getUsername());
try {
completeTasksFromUsers(guaranteeIdentity.getUsername(), "approve");
} catch (ResultCodeException e) {
fail("User has permission to approve task. Error message: " + e.getLocalizedMessage());
} catch (Exception e) {
fail("Some problem: " + e.getLocalizedMessage());
}
IdmAutomaticRoleRequestDto request = roleRequestService.get(requestId);
Assert.assertEquals(RequestState.EXECUTED, request.getState());
Assert.assertNotNull(request.getAutomaticRole());
automaticRole = automaticRoleAttributeService.get(request.getAutomaticRole());
Assert.assertNotNull(automaticRole);
Assert.assertEquals(role.getId(), automaticRole.getRole());
return;
}
fail("Automatic role request have to be approving by gurantee!");
}
use of eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleRequestDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmAutomaticRoleRequestServiceIntegrationTest method testCreateAutomaticAttributeRole.
@Test
public void testCreateAutomaticAttributeRole() {
IdmRoleDto role = prepareRole();
IdmIdentityDto guaranteeIdentity = helper.createIdentity();
IdmRoleGuaranteeDto guarantee = new IdmRoleGuaranteeDto();
guarantee.setRole(role.getId());
guarantee.setGuarantee(guaranteeIdentity.getId());
role.getGuarantees().add(guarantee);
role = roleService.save(role);
IdmAutomaticRoleRequestDto request = new IdmAutomaticRoleRequestDto();
request.setState(RequestState.EXECUTED);
request.setOperation(RequestOperationType.ADD);
request.setRequestType(AutomaticRoleRequestType.ATTRIBUTE);
request.setExecuteImmediately(true);
request.setName(role.getName());
request.setRole(role.getId());
request = roleRequestService.save(request);
Assert.assertEquals(RequestState.CONCEPT, request.getState());
IdmIdentityDto identity = helper.createIdentity();
IdmAutomaticRoleAttributeRuleRequestDto rule = new IdmAutomaticRoleAttributeRuleRequestDto();
rule.setRequest(request.getId());
rule.setOperation(RequestOperationType.ADD);
rule.setAttributeName(IdmIdentity_.username.getName());
rule.setComparison(AutomaticRoleAttributeRuleComparison.EQUALS);
rule.setType(AutomaticRoleAttributeRuleType.IDENTITY);
rule.setValue(identity.getUsername());
rule = ruleRequestService.save(rule);
request = roleRequestService.startRequestInternal(request.getId(), true);
// Recalculate
Assert.assertNotNull(request.getAutomaticRole());
this.recalculateSync(request.getAutomaticRole());
request = roleRequestService.get(request.getId());
Assert.assertEquals(RequestState.EXECUTED, request.getState());
List<IdmIdentityRoleDto> identityRoles = identityRoleService.findAllByIdentity(identity.getId());
Assert.assertFalse(identityRoles.isEmpty());
Assert.assertEquals(role.getId(), identityRoles.get(0).getRole());
Assert.assertNotNull(identityRoles.get(0).getRoleTreeNode());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleRequestDto in project CzechIdMng by bcvsolutions.
the class AutomaticRoleRequestApprovalProcessor method process.
@Override
public EventResult<IdmAutomaticRoleRequestDto> process(EntityEvent<IdmAutomaticRoleRequestDto> event) {
IdmAutomaticRoleRequestDto dto = event.getContent();
boolean checkRight = (boolean) event.getProperties().get(CHECK_RIGHT_PROPERTY);
// Find approval process (by role priority)
String wfDefinition = findWfDefinition(dto);
// If none process definition was found, then is request approved;
if (Strings.isNullOrEmpty(wfDefinition)) {
LOG.info("None approval process definition was found, request [{}] for automatic role is approved.", dto);
return new DefaultEventResult<>(event, this);
}
boolean supports = this.supportsAutomaticRole(wfDefinition);
if (!supports) {
LOG.info("Approval process definition [{}] does not supports approving for automatic role. Default approval process will be used [{}]. Automatic role request [{}]", wfDefinition, DEFAULT_WF_PROCESS_NAME, dto);
wfDefinition = DEFAULT_WF_PROCESS_NAME;
}
boolean approved = service.startApprovalProcess(dto, checkRight, event, wfDefinition);
DefaultEventResult<IdmAutomaticRoleRequestDto> result = new DefaultEventResult<>(event, this);
result.setSuspended(!approved);
return result;
}
use of eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleRequestDto in project CzechIdMng by bcvsolutions.
the class DefaultAutomaticRoleManager method changeAutomaticRoleRules.
@Override
public IdmAutomaticRoleAttributeDto changeAutomaticRoleRules(IdmAutomaticRoleAttributeDto automaticRole, boolean executeImmediately, IdmAutomaticRoleAttributeRuleDto... newRules) {
Assert.notNull(automaticRole);
Assert.notNull(automaticRole.getId(), "Automatic role must exists!");
IdmAutomaticRoleRequestDto request = new IdmAutomaticRoleRequestDto();
request.setOperation(RequestOperationType.UPDATE);
request.setRequestType(AutomaticRoleRequestType.ATTRIBUTE);
request.setExecuteImmediately(executeImmediately);
request.setAutomaticRole(automaticRole.getId());
request.setName(automaticRole.getName());
request.setRole(automaticRole.getRole());
final IdmAutomaticRoleRequestDto createdRequest = roleRequestService.save(request);
ArrayList<IdmAutomaticRoleAttributeRuleDto> rules = Lists.newArrayList(newRules);
if (rules != null) {
// Creates request for change or add rule
rules.forEach(rule -> {
IdmAutomaticRoleAttributeRuleRequestDto ruleRequest = new IdmAutomaticRoleAttributeRuleRequestDto();
ruleRequest.setRequest(createdRequest.getId());
ruleRequest.setOperation(rule.getId() != null ? RequestOperationType.UPDATE : RequestOperationType.ADD);
ruleRequest.setAttributeName(rule.getAttributeName());
ruleRequest.setComparison(rule.getComparison());
ruleRequest.setType(rule.getType());
ruleRequest.setFormAttribute(rule.getFormAttribute());
ruleRequest.setValue(rule.getValue());
ruleRequest.setRule(rule.getId());
ruleRequest = ruleRequestService.save(ruleRequest);
});
}
IdmAutomaticRoleAttributeRuleFilter ruleFilter = new IdmAutomaticRoleAttributeRuleFilter();
ruleFilter.setAutomaticRoleAttributeId(automaticRole.getId());
List<IdmAutomaticRoleAttributeRuleDto> currentRules = ruleService.find(ruleFilter, null).getContent();
currentRules.stream().filter(currentRule -> {
return rules == null || !rules.contains(currentRule);
}).forEach(ruleToDelete -> {
// Creates request for remove rule
IdmAutomaticRoleAttributeRuleRequestDto ruleRequest = new IdmAutomaticRoleAttributeRuleRequestDto();
ruleRequest.setRequest(createdRequest.getId());
ruleRequest.setOperation(RequestOperationType.REMOVE);
ruleRequest.setAttributeName(ruleToDelete.getAttributeName());
ruleRequest.setComparison(ruleToDelete.getComparison());
ruleRequest.setType(ruleToDelete.getType());
ruleRequest.setFormAttribute(ruleToDelete.getFormAttribute());
ruleRequest.setValue(ruleToDelete.getValue());
ruleRequest.setRule(ruleToDelete.getId());
ruleRequest = ruleRequestService.save(ruleRequest);
});
IdmAutomaticRoleRequestDto executedRequest = roleRequestService.startRequestInternal(createdRequest.getId(), true);
if (RequestState.EXECUTED == executedRequest.getState()) {
UUID createdAutomaticRoleId = executedRequest.getAutomaticRole();
Assert.notNull(createdAutomaticRoleId);
return automaticRoleAttributeService.get(executedRequest.getAutomaticRole());
}
if (RequestState.IN_PROGRESS == executedRequest.getState()) {
throw new AcceptedException(executedRequest.getId().toString());
}
if (RequestState.EXCEPTION == executedRequest.getState()) {
throw new CoreException(executedRequest.getResult().getCause());
}
return null;
}
use of eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleRequestDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmAutomaticRoleRequestService method startRequest.
@Override
@Transactional
public IdmAutomaticRoleRequestDto startRequest(UUID requestId, boolean checkRight) {
IdmAutomaticRoleRequestDto request = get(requestId);
Assert.notNull(request, "Request is required!");
// Validation on exist some rule
if (AutomaticRoleRequestType.ATTRIBUTE == request.getRequestType() && RequestOperationType.REMOVE != request.getOperation()) {
IdmAutomaticRoleAttributeRuleRequestFilter ruleFilter = new IdmAutomaticRoleAttributeRuleRequestFilter();
ruleFilter.setRoleRequestId(requestId);
List<IdmAutomaticRoleAttributeRuleRequestDto> ruleConcepts = automaticRoleRuleRequestService.find(ruleFilter, null).getContent();
if (ruleConcepts.isEmpty()) {
throw new RoleRequestException(CoreResultCode.AUTOMATIC_ROLE_REQUEST_START_WITHOUT_RULE, ImmutableMap.of("request", request.getName()));
}
}
try {
IdmAutomaticRoleRequestService service = this.getIdmAutomaticRoleRequestService();
if (!(service instanceof DefaultIdmAutomaticRoleRequestService)) {
throw new CoreException("We expects instace of DefaultIdmAutomaticRoleRequestService!");
}
return ((DefaultIdmAutomaticRoleRequestService) service).startRequestNewTransactional(requestId, checkRight);
} catch (Exception ex) {
LOG.error(ex.getLocalizedMessage(), ex);
request = get(requestId);
Throwable exceptionToLog = resolveException(ex);
// TODO: I set only cause of exception, not code and properties. If are
// properties set, then request cannot be save!
request.setResult(new OperationResultDto.Builder(OperationState.EXCEPTION).setCause(exceptionToLog).build());
request.setState(RequestState.EXCEPTION);
return save(request);
}
}
Aggregations