use of org.sagebionetworks.bridge.exceptions.BridgeServiceException in project BridgeServer2 by Sage-Bionetworks.
the class CacheAdminService method removeItem.
/**
* Delete an item by its key from the cache (cannot delete sessions).
* @param cacheKey
*/
public void removeItem(String cacheKey) {
checkArgument(isNotBlank(cacheKey));
Long removed = null;
if (CacheKey.isPublic(cacheKey)) {
try (Jedis jedis = jedisPool.getResource()) {
removed = jedis.del(cacheKey);
}
}
if (removed == null || removed == 0) {
throw new BridgeServiceException("Item could not be removed from cache: does key '" + cacheKey + "' exist?");
}
}
use of org.sagebionetworks.bridge.exceptions.BridgeServiceException in project BridgeServer2 by Sage-Bionetworks.
the class ConsentPdf method createPdf.
private byte[] createPdf(final String consentDoc) {
try (ByteArrayBuilder byteArrayBuilder = new ByteArrayBuilder()) {
ITextRenderer renderer = new ITextRenderer();
renderer.setDocumentFromString(consentDoc);
renderer.layout();
renderer.createPDF(byteArrayBuilder);
byteArrayBuilder.flush();
return byteArrayBuilder.toByteArray();
} catch (DocumentException e) {
throw new BridgeServiceException(e);
}
}
use of org.sagebionetworks.bridge.exceptions.BridgeServiceException in project BridgeServer2 by Sage-Bionetworks.
the class AppService method restoreVerification.
// Helper method to fetch consent notification email verification data from the cache.
private VerificationData restoreVerification(String sptoken) {
checkArgument(isNotBlank(sptoken));
CacheKey cacheKey = CacheKey.verificationToken(sptoken);
String json = cacheProvider.getObject(cacheKey, String.class);
if (json != null) {
try {
cacheProvider.removeObject(cacheKey);
return BridgeObjectMapper.get().readValue(json, VerificationData.class);
} catch (IOException e) {
throw new BridgeServiceException(e);
}
}
return null;
}
use of org.sagebionetworks.bridge.exceptions.BridgeServiceException in project BridgeServer2 by Sage-Bionetworks.
the class AccountWorkflowService method resetPassword.
/**
* Use a supplied password reset token to change the password on an account. If the supplied
* token is not valid, this method throws an exception. If the token is valid but the account
* does not exist, an exception is also thrown (this would be unusual).
*/
public void resetPassword(PasswordReset passwordReset) {
checkNotNull(passwordReset);
// This pathway is unusual as the token may have been sent via email or phone, so test for both.
CacheKey emailCacheKey = CacheKey.passwordResetForEmail(passwordReset.getSptoken(), passwordReset.getAppId());
CacheKey phoneCacheKey = CacheKey.passwordResetForPhone(passwordReset.getSptoken(), passwordReset.getAppId());
String email = cacheProvider.getObject(emailCacheKey, String.class);
Phone phone = cacheProvider.getObject(phoneCacheKey, Phone.class);
if (email == null && phone == null) {
throw new BadRequestException(PASSWORD_RESET_TOKEN_EXPIRED);
}
cacheProvider.removeObject(emailCacheKey);
cacheProvider.removeObject(phoneCacheKey);
App app = appService.getApp(passwordReset.getAppId());
ChannelType channelType = null;
AccountId accountId = null;
if (email != null) {
accountId = AccountId.forEmail(app.getIdentifier(), email);
channelType = ChannelType.EMAIL;
} else if (phone != null) {
accountId = AccountId.forPhone(app.getIdentifier(), phone);
channelType = ChannelType.PHONE;
} else {
throw new BridgeServiceException("Could not reset password");
}
Account account = accountService.getAccount(accountId).orElseThrow(() -> new EntityNotFoundException(Account.class));
accountService.changePassword(account, channelType, passwordReset.getPassword());
}
use of org.sagebionetworks.bridge.exceptions.BridgeServiceException in project BridgeServer2 by Sage-Bionetworks.
the class ConsentService method sendConsentViaSMS.
private void sendConsentViaSMS(App app, Subpopulation subpop, StudyParticipant participant, ConsentPdf consentPdf) {
String shortUrl;
try {
ObjectMetadata metadata = new ObjectMetadata();
metadata.setSSEAlgorithm(ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION);
String fileName = getSignedConsentUrl();
DateTime expiresOn = getDownloadExpiration();
s3Helper.writeBytesToS3(USERSIGNED_CONSENTS_BUCKET, fileName, consentPdf.getBytes(), metadata);
URL url = s3Helper.generatePresignedUrl(USERSIGNED_CONSENTS_BUCKET, fileName, expiresOn, HttpMethod.GET);
shortUrl = urlShortenerService.shortenUrl(url.toString(), SIGNED_CONSENT_DOWNLOAD_EXPIRE_IN_SECONDS);
} catch (IOException e) {
throw new BridgeServiceException(e);
}
TemplateRevision revision = templateService.getRevisionForUser(app, SMS_SIGNED_CONSENT);
SmsMessageProvider provider = new SmsMessageProvider.Builder().withApp(app).withPhone(participant.getPhone()).withExpirationPeriod(EXPIRATION_PERIOD_KEY, SIGNED_CONSENT_DOWNLOAD_EXPIRE_IN_SECONDS).withTransactionType().withTemplateRevision(revision).withToken(BridgeConstants.CONSENT_URL, shortUrl).build();
smsService.sendSmsMessage(participant.getId(), provider);
}
Aggregations