use of eu.bcvsolutions.idm.core.api.exception.EntityNotFoundException in project CzechIdMng by bcvsolutions.
the class WorkflowTaskInstanceController method getPermissions.
@RequestMapping(method = RequestMethod.GET, value = "/{backendId}/permissions")
@ApiOperation(value = "Historic task instance detail", nickname = "getHistoricTaskInstance", response = WorkflowTaskInstanceDto.class, tags = { WorkflowTaskInstanceController.TAG })
@Override
public Set<String> getPermissions(@ApiParam(value = "Task instance id.", required = true) @PathVariable String backendId) {
WorkflowFilterDto context = new WorkflowFilterDto();
context.setOnlyInvolved(Boolean.FALSE);
WorkflowTaskInstanceDto taskInstanceDto = workflowTaskInstanceService.get(backendId, context);
if (taskInstanceDto == null) {
throw new EntityNotFoundException(getService().getEntityClass(), backendId);
}
return workflowTaskInstanceService.getPermissions(taskInstanceDto);
}
use of eu.bcvsolutions.idm.core.api.exception.EntityNotFoundException in project CzechIdMng by bcvsolutions.
the class VsRequestController method get.
@Override
@ResponseBody
@RequestMapping(value = "/{backendId}", method = RequestMethod.GET)
@PreAuthorize("hasAuthority('" + VirtualSystemGroupPermission.VS_REQUEST_READ + "')")
@ApiOperation(value = "Request detail", nickname = "getRequest", response = VsRequestDto.class, tags = { VsRequestController.TAG }, authorizations = { @Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { @AuthorizationScope(scope = VirtualSystemGroupPermission.VS_REQUEST_READ, description = "") }), @Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { @AuthorizationScope(scope = VirtualSystemGroupPermission.VS_REQUEST_READ, description = "") }) })
public ResponseEntity<?> get(@ApiParam(value = "Request's uuid identifier.", required = true) @PathVariable @NotNull String backendId) {
VsRequestDto request = this.getDto(backendId);
if (request == null) {
throw new EntityNotFoundException(getService().getEntityClass(), backendId);
}
UUID roleRequestId = request.getRoleRequestId();
if (roleRequestId != null) {
IdmRoleRequestDto roleRequestDto = rolerequestService.get(roleRequestId);
if (roleRequestDto != null) {
UUID roleRequestCreatorId = roleRequestDto.getCreatorId();
if (roleRequestCreatorId != null) {
IdmIdentityDto roleRequestCreator = identityService.get(roleRequestCreatorId);
roleRequestDto.getEmbedded().put(Auditable.PROPERTY_CREATOR, roleRequestCreator);
}
request.getEmbedded().put(IdmConceptRoleRequestService.ROLE_REQUEST_FIELD, roleRequestDto);
}
}
ResourceSupport resource = toResource(request);
if (resource == null) {
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
//
return new ResponseEntity<>(resource, HttpStatus.OK);
}
use of eu.bcvsolutions.idm.core.api.exception.EntityNotFoundException in project CzechIdMng by bcvsolutions.
the class IdentityUsernameExportBulkActionTest method checkPermission.
@Test
public void checkPermission() {
IdmBulkActionDto exampleAction = findBulkAction(IdmIdentity.class, IdentityUsernameExportBulkAction.BULK_ACTION_NAME);
assertNotNull(exampleAction);
IdmIdentityDto identity = getHelper().createIdentity();
exampleAction.setIdentifiers(Sets.newHashSet(identity.getId()));
IdmBulkActionDto processAction = bulkActionManager.processAction(exampleAction);
assertNotNull(processAction.getLongRunningTaskId());
IdmLongRunningTaskDto longRunningTask = longRunningTaskService.get(processAction.getLongRunningTaskId());
IdmIdentityDto adminIdentity = this.createUserWithAuthorities(CoreGroupPermission.IDENTITY, CoreGroupPermission.SCHEDULER);
loginAsNoAdmin(adminIdentity.getUsername());
processAction = bulkActionManager.processAction(exampleAction);
assertNotNull(processAction.getLongRunningTaskId());
IdmLongRunningTaskDto longRunningTask2 = longRunningTaskService.get(processAction.getLongRunningTaskId());
assertFalse(longRunningTask.isRunning());
assertFalse(longRunningTask2.isRunning());
Assert.notNull(longRunningTask, "Task is required.");
Assert.notNull(longRunningTask2, "Task is required.");
UUID attachmentOneId = attachmentManager.getAttachments(longRunningTask, null).getContent().get(0).getId();
try {
longRunningTaskManager.getAttachment(longRunningTask.getId(), attachmentOneId, IdmBasePermission.READ);
fail();
} catch (ForbiddenEntityException e) {
// Correct behavior
} catch (Exception e) {
fail();
}
try {
longRunningTaskManager.getAttachment(UUID.randomUUID(), attachmentOneId, IdmBasePermission.READ);
fail();
} catch (EntityNotFoundException e) {
// Correct behavior
} catch (Exception e) {
fail();
}
UUID attachmentTwoId = attachmentManager.getAttachments(longRunningTask2, null).getContent().get(0).getId();
IdmAttachmentDto attachmentDto = longRunningTaskManager.getAttachment(longRunningTask2.getId(), attachmentTwoId);
assertNotNull(attachmentDto);
}
use of eu.bcvsolutions.idm.core.api.exception.EntityNotFoundException in project CzechIdMng by bcvsolutions.
the class DefaultIdmIncompatibleRoleService method resolveIncompatibleRoles.
@Override
public Set<ResolvedIncompatibleRoleDto> resolveIncompatibleRoles(List<Serializable> rolesOrIdentifiers) {
// search all defined incompatible roles for given roles - business roles can be given
Set<ResolvedIncompatibleRoleDto> incompatibleRoles = new HashSet<>();
if (CollectionUtils.isEmpty(rolesOrIdentifiers)) {
return incompatibleRoles;
}
LOG.debug("Start resolving incompabible roles [{}]", rolesOrIdentifiers);
//
Set<UUID> allRoleIds = new HashSet<>();
Set<IdmRoleDto> roles = new HashSet<>();
// search all sub roles
for (Serializable roleOrIdentifier : rolesOrIdentifiers) {
if (roleOrIdentifier == null) {
continue;
}
roles.clear();
//
IdmRoleDto directRole = null;
if (roleOrIdentifier instanceof IdmRoleDto) {
directRole = (IdmRoleDto) roleOrIdentifier;
} else {
directRole = (IdmRoleDto) lookupService.lookupDto(IdmRoleDto.class, roleOrIdentifier);
}
if (directRole == null) {
throw new EntityNotFoundException(IdmRole.class, roleOrIdentifier);
}
//
roles.add(directRole);
if (directRole.getChildrenCount() > 0) {
roles.addAll(roleCompositionService.resolveDistinctRoles(roleCompositionService.findAllSubRoles(directRole.getId())));
}
//
// resolve incompatible roles
List<UUID> roleIds = roles.stream().map(IdmRoleDto::getId).collect(Collectors.toList());
//
for (IdmIncompatibleRoleDto incompatibleRole : findAllByRoles(roleIds)) {
// find incompatible roles - we need to know, which from the given role is incompatible => ResolvedIncompatibleRoleDto
incompatibleRoles.add(new ResolvedIncompatibleRoleDto(directRole, incompatibleRole));
}
allRoleIds.addAll(roleIds);
}
//
// both sides of incompatible roles should be in the allRoleIds and superior vs. sub role has to be different.
Set<ResolvedIncompatibleRoleDto> resolvedRoles = incompatibleRoles.stream().filter(ir -> {
// superior vs. sub role has to be different.
return !ir.getIncompatibleRole().getSuperior().equals(ir.getIncompatibleRole().getSub());
}).filter(ir -> {
// superior and sub role has to be in all roles.
return allRoleIds.contains(ir.getIncompatibleRole().getSuperior()) && allRoleIds.contains(ir.getIncompatibleRole().getSub());
}).collect(Collectors.toSet());
//
LOG.debug("Resolved incompabible roles [{}]", resolvedRoles.size());
return resolvedRoles;
}
use of eu.bcvsolutions.idm.core.api.exception.EntityNotFoundException in project CzechIdMng by bcvsolutions.
the class DefaultTwoFactorAuthenticationManager method authenticate.
@Override
@Transactional
public LoginDto authenticate(LoginDto loginTwoFactorRequestDto) {
Assert.notNull(loginTwoFactorRequestDto, "Login request is required.");
//
IdmJwtAuthenticationDto claims = null;
String loggedAction = siemLogger.buildAction(SiemLoggerManager.LOGIN_LEVEL_KEY);
String targetName = loginTwoFactorRequestDto.getUsername();
String targetUuid = null;
try {
Optional<Jwt> jwt = HttpFilterUtils.parseToken(loginTwoFactorRequestDto.getToken());
if (!jwt.isPresent()) {
throw new ResultCodeException(CoreResultCode.AUTH_FAILED, "Verification code must be filled");
}
HttpFilterUtils.verifyToken(jwt.get(), jwtAuthenticationMapper.getVerifier());
// authentication dto from request
try {
claims = jwtAuthenticationMapper.getClaims(jwt.get());
targetName = claims.getCurrentUsername();
targetUuid = Objects.toString(claims.getCurrentIdentityId(), "");
} catch (IOException ex) {
throw new ResultCodeException(CoreResultCode.TOKEN_READ_FAILED, ex);
}
// we need to check expiration, before current (automatically prolonged) token is used by mapper
if (claims.getExpiration() != null && claims.getExpiration().isBefore(ZonedDateTime.now())) {
throw new ResultCodeException(CoreResultCode.AUTH_EXPIRED);
}
UUID identityId = claims.getCurrentIdentityId();
IdmIdentityDto identity = identityService.get(identityId);
if (identity == null) {
throw new EntityNotFoundException(IdmIdentityDto.class, identityId);
}
IdmPasswordDto password = passwordService.findOneByIdentity(identityId);
if (password == null) {
throw new EntityNotFoundException(IdmPasswordDto.class, identityId);
}
if (!verifyCode(password, loginTwoFactorRequestDto.getPassword())) {
throw new ResultCodeException(CoreResultCode.TWO_FACTOR_VERIFICATION_CODE_FAILED);
}
//
if (password.isMustChange() && !loginTwoFactorRequestDto.isSkipMustChange()) {
throw new MustChangePasswordException(claims.getCurrentUsername());
}
// set token verified
IdmTokenDto token = tokenManager.getToken(claims.getId());
token.setSecretVerified(true);
// and login - new login dto new to be constructed to preserve original login metadata
LoginDto loginDto = new LoginDto();
loginDto.setUsername(claims.getCurrentUsername());
loginDto.setAuthenticationModule(claims.getFromModule());
//
LoginDto resultLoginDto = jwtAuthenticationService.createJwtAuthenticationAndAuthenticate(loginDto, identity, token);
siemLogger.log(loggedAction, SiemLoggerManager.SUCCESS_ACTION_STATUS, targetName, targetUuid, null, null, null, null);
return resultLoginDto;
} catch (Exception e) {
siemLogger.log(loggedAction, SiemLoggerManager.FAILED_ACTION_STATUS, targetName, targetUuid, null, null, null, e.getMessage());
throw e;
}
}
Aggregations