Search in sources :

Example 1 with JWTEncryptionPreferences

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);
    }
}
Also used : JWTEncryptionPreferences(com.box.sdk.JWTEncryptionPreferences) InMemoryLRUAccessTokenCache(com.box.sdk.InMemoryLRUAccessTokenCache) IAccessTokenCache(com.box.sdk.IAccessTokenCache) RuntimeCamelException(org.apache.camel.RuntimeCamelException) BoxAPIException(com.box.sdk.BoxAPIException) BoxAPIException(com.box.sdk.BoxAPIException) GeneralSecurityException(java.security.GeneralSecurityException) FailingHttpStatusCodeException(com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException) RuntimeCamelException(org.apache.camel.RuntimeCamelException) IOException(java.io.IOException)

Example 2 with JWTEncryptionPreferences

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);
    }
}
Also used : JWTEncryptionPreferences(com.box.sdk.JWTEncryptionPreferences) InMemoryLRUAccessTokenCache(com.box.sdk.InMemoryLRUAccessTokenCache) IAccessTokenCache(com.box.sdk.IAccessTokenCache) RuntimeCamelException(org.apache.camel.RuntimeCamelException) BoxAPIException(com.box.sdk.BoxAPIException) BoxAPIException(com.box.sdk.BoxAPIException) GeneralSecurityException(java.security.GeneralSecurityException) FailingHttpStatusCodeException(com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException) RuntimeCamelException(org.apache.camel.RuntimeCamelException) IOException(java.io.IOException)

Aggregations

BoxAPIException (com.box.sdk.BoxAPIException)2 IAccessTokenCache (com.box.sdk.IAccessTokenCache)2 InMemoryLRUAccessTokenCache (com.box.sdk.InMemoryLRUAccessTokenCache)2 JWTEncryptionPreferences (com.box.sdk.JWTEncryptionPreferences)2 FailingHttpStatusCodeException (com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException)2 IOException (java.io.IOException)2 GeneralSecurityException (java.security.GeneralSecurityException)2 RuntimeCamelException (org.apache.camel.RuntimeCamelException)2