use of com.box.sdk.JWTEncryptionPreferences in project camel by apache.
the class BoxConnectionHelper method createAppEnterpriseAuthenticatedConnection.
public static BoxAPIConnection createAppEnterpriseAuthenticatedConnection(BoxConfiguration configuration) {
// Create Encryption Preferences
JWTEncryptionPreferences encryptionPref = new JWTEncryptionPreferences();
encryptionPref.setPublicKeyID(configuration.getPublicKeyId());
try {
encryptionPref.setPrivateKey(new String(Files.readAllBytes(Paths.get(configuration.getPrivateKeyFile()))));
} catch (Exception e) {
throw new RuntimeCamelException("Box API connection failed: could not read privateKeyFile", e);
}
encryptionPref.setPrivateKeyPassword(configuration.getPrivateKeyPassword());
encryptionPref.setEncryptionAlgorithm(configuration.getEncryptionAlgorithm());
IAccessTokenCache accessTokenCache = configuration.getAccessTokenCache();
if (accessTokenCache == null) {
accessTokenCache = new InMemoryLRUAccessTokenCache(configuration.getMaxCacheEntries());
}
try {
return BoxDeveloperEditionAPIConnection.getAppEnterpriseConnection(configuration.getEnterpriseId(), configuration.getClientId(), configuration.getClientSecret(), encryptionPref, accessTokenCache);
} catch (BoxAPIException e) {
throw new RuntimeCamelException(String.format("Box API connection failed: API returned the error code %d\n\n%s", e.getResponseCode(), e.getResponse()), e);
}
}
use of com.box.sdk.JWTEncryptionPreferences in project camel by apache.
the class BoxConnectionHelper method createAppUserAuthenticatedConnection.
public static BoxAPIConnection createAppUserAuthenticatedConnection(BoxConfiguration configuration) {
// Create Encryption Preferences
JWTEncryptionPreferences encryptionPref = new JWTEncryptionPreferences();
encryptionPref.setPublicKeyID(configuration.getPublicKeyId());
try {
encryptionPref.setPrivateKey(new String(Files.readAllBytes(Paths.get(configuration.getPrivateKeyFile()))));
} catch (Exception e) {
throw new RuntimeCamelException("Box API connection failed: could not read privateKeyFile", e);
}
encryptionPref.setPrivateKeyPassword(configuration.getPrivateKeyPassword());
encryptionPref.setEncryptionAlgorithm(configuration.getEncryptionAlgorithm());
IAccessTokenCache accessTokenCache = configuration.getAccessTokenCache();
if (accessTokenCache == null) {
accessTokenCache = new InMemoryLRUAccessTokenCache(configuration.getMaxCacheEntries());
}
try {
return BoxDeveloperEditionAPIConnection.getAppUserConnection(configuration.getUserId(), configuration.getClientId(), configuration.getClientSecret(), encryptionPref, accessTokenCache);
} catch (BoxAPIException e) {
throw new RuntimeCamelException(String.format("Box API connection failed: API returned the error code %d\n\n%s", e.getResponseCode(), e.getResponse()), e);
}
}
Aggregations