use of eu.bcvsolutions.idm.core.api.exception.ResultCodeException in project CzechIdMng by bcvsolutions.
the class DefaultRequestManager method resolveItem.
private void resolveItem(IdmRequestItemDto item) throws ClassNotFoundException, IOException {
Assert.notNull(item, "Item is mandatory!");
RequestOperationType type = item.getOperation();
// Get DTO service
@SuppressWarnings("unchecked") Class<? extends Requestable> dtoClass = (Class<? extends Requestable>) Class.forName(item.getOwnerType());
// Get service
@SuppressWarnings("unchecked") ReadWriteDtoService<Requestable, BaseFilter> dtoService = (ReadWriteDtoService<Requestable, BaseFilter>) this.getServiceByItem(item, dtoClass);
// Create or Update DTO
if (RequestOperationType.ADD == type || RequestOperationType.UPDATE == type) {
Requestable dto = this.convertItemToDto(item, dtoClass);
// confidential storage
if (dto instanceof IdmFormValueDto) {
IdmFormValueDto formValueDto = (IdmFormValueDto) dto;
if (formValueDto.isConfidential()) {
formValueDto.setValue(this.getConfidentialPersistentValue(item));
}
}
// Save without check a permissions
dto = dtoService.save(dto);
item.setResult(new OperationResultDto(OperationState.EXECUTED));
item.setState(RequestState.EXECUTED);
requestItemService.save(item);
return;
}
// Delete DTO
if (RequestOperationType.REMOVE == type) {
Assert.notNull(item.getOwnerId(), "Id in item is required for delete!");
Requestable dtoToDelete = dtoService.get(item.getOwnerId());
if (dtoToDelete == null) {
item.setResult(new //
OperationResultDto.Builder(//
OperationState.NOT_EXECUTED).setException(new ResultCodeException(CoreResultCode.NOT_FOUND, //
ImmutableMap.of("entity", item.getOriginalCreatorId()))).build());
requestItemService.save(item);
return;
}
// Delete without check a permissions
dtoService.deleteById(dtoToDelete.getId());
item.setResult(new OperationResultDto(OperationState.EXECUTED));
item.setState(RequestState.EXECUTED);
requestItemService.save(item);
return;
}
}
use of eu.bcvsolutions.idm.core.api.exception.ResultCodeException in project CzechIdMng by bcvsolutions.
the class DefaultRequestManager method delete.
@SuppressWarnings("unchecked")
@Override
@Transactional
public <R extends Requestable> R delete(Serializable requestId, R dto, BasePermission... permission) {
Assert.notNull(dto, "DTO is required!");
Assert.notNull(requestId, "Request ID is required!");
IdmRequestDto request = requestService.get(requestId);
Assert.notNull(request, "Request is required!");
// update existing item
if (request != null && !(RequestState.CONCEPT == request.getState() || RequestState.IN_PROGRESS == request.getState() || RequestState.EXCEPTION == request.getState())) {
throw new ResultCodeException(CoreResultCode.REQUEST_ITEM_CANNOT_BE_CREATED, ImmutableMap.of("dto", dto.toString(), "state", request.getState().name()));
}
// Exists item for same original owner?
IdmRequestItemDto item = this.findRequestItem(request.getId(), dto);
// him.
if (item != null) {
requestItemService.delete(item);
return this.get(request.getId(), (UUID) dto.getId(), (Class<R>) dto.getClass(), permission);
}
// Check permissions on the target service
ReadDtoService<R, ?> dtoReadService = getDtoService(dto);
dtoReadService.checkAccess(dto, permission);
if (item == null) {
item = createRequestItem(request.getId(), dto);
}
item.setOwnerId((UUID) dto.getId());
item.setOperation(RequestOperationType.REMOVE);
item.setData(null);
// Update or create new request item
item = requestItemService.save(item);
// Set ID of request item to result DTO
dto.setRequestItem(item.getId());
return get(request.getId(), dto);
}
use of eu.bcvsolutions.idm.core.api.exception.ResultCodeException in project CzechIdMng by bcvsolutions.
the class DatabaseTableMonitoringEvaluator method evaluate.
@Override
public IdmMonitoringResultDto evaluate(IdmMonitoringDto monitoring) {
String serviceName = getParameterConverter().toString(monitoring.getEvaluatorProperties(), PARAMETER_READ_SERVICE_BEAN_NAME);
Object bean;
try {
bean = context.getBean(serviceName);
if (bean == null || !(bean instanceof ReadDtoService<?, ?>)) {
throw new ResultCodeException(CoreResultCode.NOT_FOUND, ImmutableMap.of("entity", serviceName));
}
} catch (BeansException ex) {
throw new ResultCodeException(CoreResultCode.NOT_FOUND, ImmutableMap.of("entity", serviceName), ex);
}
//
ReadDtoService<?, ?> readService = (ReadDtoService<?, ?>) bean;
long treshold = getParameterConverter().toLong(monitoring.getEvaluatorProperties(), PARAMETER_THRESHOLD, DEFAULT_THRESHOLD);
long count = readService.count(null);
ResultModel resultModel = new DefaultResultModel(CoreResultCode.MONITORING_DATABASE_TABLE, ImmutableMap.of("tableName", String.valueOf(getTableName(readService)), "dtoName", String.valueOf(getDtoName(readService)), "count", Long.toString(count)));
IdmMonitoringResultDto result = new IdmMonitoringResultDto();
result.setValue(Long.toString(count));
result.setResult(new OperationResultDto.Builder(OperationState.EXECUTED).setModel(resultModel).build());
if (treshold < count) {
result.setLevel(NotificationLevel.WARNING);
}
//
return result;
}
use of eu.bcvsolutions.idm.core.api.exception.ResultCodeException in project CzechIdMng by bcvsolutions.
the class PasswordPreValidationIntegrationTest method testAdvancedEnabled.
@Test
public void testAdvancedEnabled() {
IdmPasswordPolicyDto policy = new IdmPasswordPolicyDto();
policy.setName(System.currentTimeMillis() + "");
policy.setDefaultPolicy(true);
policy.setMinPasswordLength(10);
policy.setMaxPasswordLength(20);
policy.setPasswordLengthRequired(true);
policy.setMinUpperChar(5);
policy.setUpperCharRequired(true);
policy.setMinLowerChar(4);
policy.setLowerCharRequired(true);
policy.setEnchancedControl(true);
policy.setMinRulesToFulfill(1);
policy.setMinNumber(3);
policy.setNumberRequired(false);
policy.setMinSpecialChar(2);
policy.setSpecialCharRequired(false);
policy.setIdentityAttributeCheck("EMAIL, USERNAME");
PasswordChangeDto passwordChange = new PasswordChangeDto();
passwordChange.setIdm(true);
policy = passwordPolicyService.save(policy);
try {
idmIdentityService.validatePassword(passwordChange);
} catch (ResultCodeException ex) {
Map<String, Object> parametrs = new HashMap<String, Object>();
parametrs.put("minNumber", 3);
parametrs.put("minSpecialChar", 2);
assertEquals(10, ex.getError().getError().getParameters().get("minLength"));
assertEquals(20, ex.getError().getError().getParameters().get("maxLength"));
assertEquals(5, ex.getError().getError().getParameters().get("minUpperChar"));
assertEquals(4, ex.getError().getError().getParameters().get("minLowerChar"));
assertEquals(parametrs.toString(), ex.getError().getError().getParameters().get("minRulesToFulfill").toString());
// special char base, passwordSimilarUsername, passwordSimilarEmail ->
assertEquals(9, ex.getError().getError().getParameters().size());
policy.setDefaultPolicy(false);
passwordPolicyService.save(policy);
}
}
use of eu.bcvsolutions.idm.core.api.exception.ResultCodeException in project CzechIdMng by bcvsolutions.
the class RequestManagerTest method testChangeRoleWithGuaranteesApprove.
@Test
public void testChangeRoleWithGuaranteesApprove() {
// Create role with guarantee
IdmIdentityDto guarantee = getHelper().createIdentity();
IdmRoleDto changedRole = getHelper().createRole();
getHelper().createRoleGuarantee(changedRole, guarantee);
// Create request
IdmRequestDto request = requestManager.createRequest(changedRole);
Assert.assertNotNull(request);
Assert.assertEquals(request.getOwnerType(), changedRole.getClass().getName());
Assert.assertEquals(request.getOwnerId(), changedRole.getId());
// Change role (without save)
changedRole.setDescription(getHelper().createName());
changedRole.setPriority(1000);
// Create request item
Requestable requestable = requestManager.post(request.getId(), changedRole);
Assert.assertNotNull(requestable);
Assert.assertNotNull(requestable.getRequestItem());
Assert.assertTrue(requestable instanceof IdmRoleDto);
IdmRoleDto roleFromRequest = (IdmRoleDto) requestable;
// Is not same instance
Assert.assertTrue(changedRole != roleFromRequest);
// Has same values as new role
Assert.assertEquals(changedRole.getPriority(), roleFromRequest.getPriority());
Assert.assertEquals(changedRole.getDescription(), roleFromRequest.getDescription());
IdmRoleDto currentRole = roleService.get(changedRole.getId());
Assert.assertNotEquals(changedRole.getPriority(), currentRole.getPriority());
Assert.assertNotEquals(changedRole.getDescription(), currentRole.getDescription());
// Start request
IdmRequestDto executedRequest = requestManager.startRequest(request.getId(), true);
Assert.assertNotNull(executedRequest);
// Role has guarantee, approval process must be started
Assert.assertEquals(RequestState.IN_PROGRESS, executedRequest.getState());
loginAsNoAdmin(guarantee.getUsername());
try {
completeTasksFromUsers(guarantee.getId().toString(), "approve");
} catch (ResultCodeException e) {
fail("User has permission to approve task. Error message: " + e.getLocalizedMessage());
} catch (Exception e) {
fail("Some problem: " + e.getLocalizedMessage());
}
// Reload the request (after approving)
executedRequest = requestService.get(executedRequest.getId());
Assert.assertEquals(RequestState.EXECUTED, executedRequest.getState());
IdmRoleDto executedRole = roleService.get(roleFromRequest.getId());
// Role must exists now
Assert.assertNotNull(executedRole);
// Has same values as new role
Assert.assertEquals(changedRole.getCode(), executedRole.getCode());
Assert.assertEquals(changedRole.getName(), executedRole.getName());
Assert.assertEquals(changedRole.getPriority(), executedRole.getPriority());
Assert.assertEquals(changedRole.getDescription(), executedRole.getDescription());
}
Aggregations