private void updateStatus(String applicationId, String credentialsId, CredentialsStatus status) throws CredentialsServiceException { Validate.notBlank(applicationId, "Invalid application ID provided!"); Validate.notBlank(credentialsId, "Invalid credentials ID provided!"); try { this.credentialsDao.updateStatus(applicationId, credentialsId, status); } catch (Exception cause) { String message = MessageFormat.format("[{0}] An unexpected exception occured while updating" + " credentials [{1}]", applicationId, credentialsId); LOG.error(message, cause); throw new CredentialsServiceException(cause); } } }
@Override public Optional<CredentialsDto> lookupCredentials(String applicationId, String credentialsId) throws CredentialsServiceException { Validate.notBlank(applicationId, "Invalid application ID provided!"); Validate.notBlank(credentialsId, "Invalid credentials ID provided!"); try { return this.credentialsDao.find(applicationId, credentialsId).map(Credentials::toDto); } catch (Exception cause) { String message = MessageFormat.format("[{0}] An unexpected exception occured while " + "searching for credentials [{1}]", applicationId, credentialsId); LOG.error(message, cause); throw new CredentialsServiceException(cause); } }
@Override public CredentialsDto provideCredentials(String applicationId, CredentialsDto credentials) throws CredentialsServiceException { Validate.notBlank(applicationId, "Invalid application ID provided!"); Validate.notNull(credentials, "Invalid credentials provided!"); try { byte[] credentialsBody = credentials.getCredentialsBody(); credentials.setId(Base64Utils.encodeToString(Sha1HashUtils.hashToBytes(credentialsBody))); return this.credentialsDao.save(applicationId, credentials).toDto(); } catch (Exception cause) { String message = MessageFormat.format("[{0}] An unexpected exception occured while saving " + "credentials!", applicationId); LOG.error(message, cause); throw new CredentialsServiceException(cause); } }