use of eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleRequestDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmAutomaticRoleRequestServiceIntegrationTest method notRightForExecuteImmediatelyExceptionTest.
@Test(expected = RoleRequestException.class)
public void notRightForExecuteImmediatelyExceptionTest() {
this.logout();
IdmIdentityDto identity = getHelper().createIdentity();
// Log as user without right for immediately execute role request (without
// approval)
Collection<GrantedAuthority> authorities = IdmAuthorityUtils.toAuthorities(moduleService.getAvailablePermissions()).stream().filter(authority -> {
return !CoreGroupPermission.AUTOMATIC_ROLE_REQUEST_ADMIN.equals(authority.getAuthority()) && !IdmGroupPermission.APP_ADMIN.equals(authority.getAuthority());
}).collect(Collectors.toList());
SecurityContextHolder.getContext().setAuthentication(new IdmJwtAuthentication(new IdmIdentityDto(identity.getUsername()), null, authorities, "test"));
IdmRoleDto role = prepareRole();
IdmAutomaticRoleRequestDto request = new IdmAutomaticRoleRequestDto();
request.setState(RequestState.EXECUTED);
request.setOperation(RequestOperationType.ADD);
request.setRequestType(AutomaticRoleRequestType.ATTRIBUTE);
request.setExecuteImmediately(true);
request.setName(role.getCode());
request.setRole(role.getId());
request = roleRequestService.save(request);
Assert.assertEquals(RequestState.CONCEPT, request.getState());
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("test");
rule = ruleRequestService.save(rule);
// We expect exception state (we don`t have right for execute without approval)
roleRequestService.startRequestInternal(request.getId(), true);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleRequestDto in project CzechIdMng by bcvsolutions.
the class DefaultAutomaticRoleManager method createAutomaticRoleByAttribute.
@Override
public IdmAutomaticRoleAttributeDto createAutomaticRoleByAttribute(IdmAutomaticRoleAttributeDto automaticRole, boolean executeImmediately, IdmAutomaticRoleAttributeRuleDto... rules) {
IdmAutomaticRoleRequestDto request = new IdmAutomaticRoleRequestDto();
request.setOperation(RequestOperationType.ADD);
request.setRequestType(AutomaticRoleRequestType.ATTRIBUTE);
request.setExecuteImmediately(executeImmediately);
request.setName(automaticRole.getName());
request.setRole(automaticRole.getRole());
request = roleRequestService.save(request);
if (rules != null) {
for (IdmAutomaticRoleAttributeRuleDto rule : rules) {
IdmAutomaticRoleAttributeRuleRequestDto ruleRequest = new IdmAutomaticRoleAttributeRuleRequestDto();
ruleRequest.setRequest(request.getId());
ruleRequest.setOperation(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);
}
}
request = roleRequestService.startRequestInternal(request.getId(), true);
if (RequestState.EXECUTED == request.getState()) {
UUID createdAutomaticRoleId = request.getAutomaticRole();
Assert.notNull(createdAutomaticRoleId, "Automatic role identifier is required.");
return automaticRoleAttributeService.get(request.getAutomaticRole());
}
if (RequestState.IN_PROGRESS == request.getState()) {
throw new AcceptedException(request.getId().toString());
}
if (RequestState.EXCEPTION == request.getState()) {
throw new CoreException(request.getResult().getCause());
}
return null;
}
use of eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleRequestDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmAutomaticRoleRequestService method deleteInternal.
@Override
@Transactional
public void deleteInternal(IdmAutomaticRoleRequestDto dto) {
// Stop connected WF process
cancelWF(dto);
// First we have to delete all rule concepts for this request
if (dto.getId() != null) {
IdmAutomaticRoleAttributeRuleRequestFilter ruleFilter = new IdmAutomaticRoleAttributeRuleRequestFilter();
ruleFilter.setRoleRequestId(dto.getId());
List<IdmAutomaticRoleAttributeRuleRequestDto> ruleConcepts = automaticRoleRuleRequestService.find(ruleFilter, null).getContent();
ruleConcepts.forEach(concept -> {
automaticRoleRuleRequestService.delete(concept);
});
}
super.deleteInternal(dto);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleRequestDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmFormAttributeService method deleteInternal.
@Override
@Transactional
@SuppressWarnings({ "rawtypes", "unchecked" })
public void deleteInternal(IdmFormAttributeDto dto) {
Assert.notNull(dto, "DTO is required.");
// attribute with filled values cannot be deleted
IdmFormValueFilter filter = new IdmFormValueFilter();
filter.setAttributeId(dto.getId());
formValueServices.getPlugins().forEach(formValueService -> {
if (formValueService.find(filter, PageRequest.of(0, 1)).getTotalElements() > 0) {
throw new ResultCodeException(CoreResultCode.FORM_ATTRIBUTE_DELETE_FAILED_HAS_VALUES, ImmutableMap.of("formAttribute", dto.getCode()));
}
});
//
// check rules for automatic role attributes
IdmAutomaticRoleAttributeRuleFilter automaticRoleRuleFilter = new IdmAutomaticRoleAttributeRuleFilter();
automaticRoleRuleFilter.setFormAttributeId(dto.getId());
long totalElements = automaticRoleAttributeService.find(automaticRoleRuleFilter, PageRequest.of(0, 1)).getTotalElements();
if (totalElements > 0) {
// some automatic roles use this attribute
throw new ResultCodeException(CoreResultCode.FORM_ATTRIBUTE_DELETE_FAILED_AUTOMATIC_ROLE_RULE_ASSIGNED, ImmutableMap.of("formAttribute", dto.getId()));
}
// Check on using this attribute on role (sub-definition)
if (dto.getId() != null) {
IdmRoleFormAttributeFilter roleFormAttributeFilter = new IdmRoleFormAttributeFilter();
roleFormAttributeFilter.setFormAttribute(dto.getId());
List<IdmRoleFormAttributeDto> attributes = roleFormAttributeService.find(roleFormAttributeFilter, PageRequest.of(0, 1)).getContent();
if (attributes.size() > 0) {
IdmRoleDto roleDto = DtoUtils.getEmbedded(attributes.get(0), IdmRoleFormAttribute_.role.getName(), IdmRoleDto.class);
throw new ResultCodeException(CoreResultCode.FORM_ATTRIBUTE_DELETE_FAILED_ROLE_ATTRIBUTE, ImmutableMap.of("definition", dto.getCode(), "role", roleDto.getCode()));
}
}
//
// Check rules requests for automatic role attributes. Deletes relation on this form attribute.
IdmAutomaticRoleAttributeRuleRequestFilter automaticRoleRuleRequestFilter = new IdmAutomaticRoleAttributeRuleRequestFilter();
automaticRoleRuleRequestFilter.setFormAttributeId(dto.getId());
List<IdmAutomaticRoleAttributeRuleRequestDto> ruleRequests = automaticRoleAttributeRequestService.find(automaticRoleRuleRequestFilter, null).getContent();
ruleRequests.forEach(rule -> {
rule.setFormAttribute(null);
automaticRoleAttributeRequestService.save(rule);
});
//
super.deleteInternal(dto);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleRequestDto 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 = ExceptionUtils.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