use of eu.bcvsolutions.idm.core.api.exception.EntityNotFoundException in project CzechIdMng by bcvsolutions.
the class AbstractRequestDtoController method delete.
/**
* Deletes DTO by given id
*
* @param requestId
* @param backendId
* @return
*/
@ApiOperation(value = "Delete record", authorizations = { @Authorization(SwaggerConfig.AUTHENTICATION_BASIC), @Authorization(SwaggerConfig.AUTHENTICATION_CIDMST) })
public //
ResponseEntity<?> delete(//
@ApiParam(value = "Request ID", required = true) String requestId, @ApiParam(value = "Record's uuid identifier or unique code.", required = true) String backendId) {
//
DTO dto = getDto(requestId, backendId);
if (dto == null) {
throw new EntityNotFoundException(getService().getEntityClass(), backendId);
}
Requestable resultDto = requestManager.delete(requestId, dto, IdmBasePermission.DELETE);
@SuppressWarnings("unchecked") ResourceSupport resource = toResource(requestId, (DTO) resultDto);
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 IdmNotificationAttachmentController method download.
@RequestMapping(value = "/{backendId}/download", method = RequestMethod.GET)
@ResponseBody
@PreAuthorize("hasAuthority('" + NotificationGroupPermission.NOTIFICATION_READ + "')")
@ApiOperation(value = "Download notification attachment", nickname = "downloadNotificationAttachment", tags = { IdmNotificationAttachmentController.TAG }, notes = "Returns input stream to notification attachment.", authorizations = { @Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { @AuthorizationScope(scope = NotificationGroupPermission.NOTIFICATION_READ, description = "") }), @Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { @AuthorizationScope(scope = NotificationGroupPermission.NOTIFICATION_READ, description = "") }) })
public ResponseEntity<InputStreamResource> download(@ApiParam(value = "Notification attachment uuid identifier.", required = true) @PathVariable String backendId) {
IdmNotificationAttachmentDto dto = getDto(backendId);
if (dto == null) {
throw new EntityNotFoundException(getService().getEntityClass(), backendId);
}
//
UUID attachmentId = dto.getAttachment();
IdmAttachmentDto attachment = attachmentManager.get(attachmentId);
if (attachment == null) {
throw new EntityNotFoundException(attachmentManager.getEntityClass(), attachmentId);
}
//
InputStream is = attachmentManager.getAttachmentData(attachment.getId());
//
try {
BodyBuilder response = ResponseEntity.ok().contentLength(is.available()).header(HttpHeaders.CONTENT_DISPOSITION, String.format("attachment; filename=\"%s\"", attachment.getName()));
// append media type, if it's filled
String mimetype = attachment.getMimetype();
if (StringUtils.isNotBlank(mimetype)) {
response = response.contentType(MediaType.valueOf(attachment.getMimetype()));
}
//
return response.body(new InputStreamResource(is));
} catch (IOException e) {
throw new ResultCodeException(CoreResultCode.INTERNAL_SERVER_ERROR, e);
}
}
use of eu.bcvsolutions.idm.core.api.exception.EntityNotFoundException in project CzechIdMng by bcvsolutions.
the class DefaultLoginService method switchUserLogout.
@Override
public LoginDto switchUserLogout() {
IdmTokenDto currentToken = tokenManager.getCurrentToken();
ConfigurationMap properties = currentToken.getProperties();
String originalUsername = properties.getString(JwtAuthenticationMapper.PROPERTY_ORIGINAL_USERNAME);
UUID originalId = properties.getUuid(JwtAuthenticationMapper.PROPERTY_ORIGINAL_IDENTITY_ID);
String loggedAction = siemLogger.buildAction(SiemLoggerManager.LOGIN_LEVEL_KEY, SiemLoggerManager.SWITCH_SUBLEVEL_KEY);
String subjectUsername = securityService.getCurrentUsername();
String subjectUuid = Objects.toString(securityService.getCurrentId(), "");
String targetUuid = Objects.toString(originalId, "");
try {
//
if (originalId == null) {
throw new ResultCodeException(CoreResultCode.NULL_ATTRIBUTE, ImmutableMap.of("attribute", "originalUsername"));
}
// change logged token authorities
IdmIdentityDto identity = identityService.get(originalId);
if (identity == null) {
throw new EntityNotFoundException(IdmIdentity.class, originalId);
}
//
// Preserve the first original user => switch is available repetitively, but original user is preserved.
properties.remove(JwtAuthenticationMapper.PROPERTY_ORIGINAL_USERNAME);
properties.remove(JwtAuthenticationMapper.PROPERTY_ORIGINAL_IDENTITY_ID);
currentToken.setProperties(properties);
IdmTokenDto switchedToken = jwtTokenMapper.createToken(identity, currentToken);
//
// login by updated token
LOG.info("Identity with username [{}] - logout from switched user [{}].", originalUsername, securityService.getCurrentUsername());
//
LoginDto login = login(identity, switchedToken);
siemLogger.log(loggedAction, SiemLoggerManager.SUCCESS_ACTION_STATUS, originalUsername, targetUuid, subjectUsername, subjectUuid, null, null);
return login;
} catch (Exception e) {
siemLogger.log(loggedAction, SiemLoggerManager.FAILED_ACTION_STATUS, originalUsername, targetUuid, subjectUsername, subjectUuid, null, e.getMessage());
throw e;
}
}
use of eu.bcvsolutions.idm.core.api.exception.EntityNotFoundException in project CzechIdMng by bcvsolutions.
the class DefaultTwoFactorAuthenticationManager method confirm.
@Override
@Transactional
public boolean confirm(UUID identityId, TwoFactorRegistrationConfirmDto registrationConfirm) {
Assert.notNull(identityId, "Identity identifier is required.");
Assert.notNull(registrationConfirm, "Two factor confirm request is required.");
//
// support two factor authentication, even when identity is not authenticated by IdM (secret is required to persist only)
IdmPasswordDto password = passwordService.findOrCreateByIdentity(identityId);
if (password == null) {
throw new EntityNotFoundException(IdmIdentityDto.class, identityId);
}
//
GuardedString verificationSecret = registrationConfirm.getVerificationSecret();
GuardedString verificationCode = registrationConfirm.getVerificationCode();
//
if (!verifyCode(verificationSecret, verificationCode)) {
throw new ResultCodeException(CoreResultCode.TWO_FACTOR_VERIFICATION_CODE_FAILED);
}
//
password.setVerificationSecret(verificationSecret.asString());
passwordService.save(password);
//
IdmProfileDto profile = profileService.findOrCreateByIdentity(identityId);
profile.setTwoFactorAuthenticationType(registrationConfirm.getTwoFactorAuthenticationType());
profileService.save(profile);
//
return true;
}
use of eu.bcvsolutions.idm.core.api.exception.EntityNotFoundException in project CzechIdMng by bcvsolutions.
the class DefaultTwoFactorAuthenticationManager method requireTwoFactorAuthentication.
@Override
@Transactional
public boolean requireTwoFactorAuthentication(UUID identityId, UUID tokenId) {
// check two factor authentication is enabled
TwoFactorAuthenticationType twoFactorAuthenticationType = getTwoFactorAuthenticationType(identityId);
if (twoFactorAuthenticationType == null) {
return false;
}
//
IdmTokenDto token = tokenManager.getToken(tokenId);
if (token.isSecretVerified()) {
// token was already verified
return false;
}
//
if (TwoFactorAuthenticationType.NOTIFICATION == twoFactorAuthenticationType) {
IdmPasswordDto password = passwordService.findOneByIdentity(identityId);
if (password == null) {
throw new EntityNotFoundException(IdmIdentityDto.class, identityId);
}
sendVerificationCode(identityService.get(identityId), generateCode(new GuardedString(password.getVerificationSecret())));
}
//
return true;
}
Aggregations