Package com.box.boxjavalibv2.resourcemanagers

Examples of com.box.boxjavalibv2.resourcemanagers.IBoxOAuthManager


    }

    private static void revokeOAuthToken(BoxConfiguration configuration, CachedBoxClient cachedBoxClient)
        throws BoxServerException, BoxRestException, AuthFatalFailureException {

        final BoxClient boxClient = cachedBoxClient.getBoxClient();
        synchronized (boxClient) {

            if (boxClient.isAuthenticated()) {

                LOG.debug("Revoking OAuth refresh token for {}", cachedBoxClient);

                // revoke OAuth token
                boxClient.getOAuthManager().revokeOAuth(boxClient.getAuthData().getAccessToken(),
                    configuration.getClientId(), configuration.getClientSecret());

                // notify the OAuthListener of revoked token
                cachedBoxClient.getListener().onRefresh(null);
                // mark auth data revoked
                boxClient.getOAuthDataController().setOAuthData(null);
            }
        }
    }
View Full Code Here


                }

                return httpClient;
            }
        };
        final BoxClient boxClient = new BoxClient(clientId, clientSecret, null, null,
            restClient, configuration.getBoxConfig());

        // enable OAuth auto-refresh
        boxClient.setAutoRefreshOAuth(true);

        // wrap the configured storage in a caching storage
        final CachingSecureStorage storage = new CachingSecureStorage(authSecureStorage);

        // set up a listener to notify secure storage and user provided listener, store it in configuration!
        final OAuthHelperListener listener = new OAuthHelperListener(storage, configuration.getRefreshListener());
        boxClient.addOAuthRefreshListener(listener);

        final CachedBoxClient cachedBoxClient = new CachedBoxClient(boxClient, userName, clientId, storage, listener, clientConnectionManager);
        LOG.debug("BoxClient created {}", cachedBoxClient);
        return cachedBoxClient;
    }
View Full Code Here

    }

    public static void getOAuthToken(BoxConfiguration configuration, CachedBoxClient cachedBoxClient)
        throws AuthFatalFailureException, BoxRestException, BoxServerException, InterruptedException {

        final BoxClient boxClient = cachedBoxClient.getBoxClient();
        synchronized (boxClient) {
            if (boxClient.isAuthenticated()) {
                return;
            }

            LOG.debug("Getting OAuth token for {}...", cachedBoxClient);

            final IAuthSecureStorage authSecureStorage = cachedBoxClient.getSecureStorage();
            if (authSecureStorage != null && authSecureStorage.getAuth() != null) {

                LOG.debug("Using secure storage for {}", cachedBoxClient);
                // authenticate using stored refresh token
                boxClient.authenticateFromSecureStorage(authSecureStorage);
            } else {

                LOG.debug("Using OAuth {}", cachedBoxClient);
                // authorize App for user, and create OAuth token with refresh token
                final IAuthFlowUI authFlowUI = new LoginAuthFlowUI(configuration, boxClient);
                final CountDownLatch latch = new CountDownLatch(1);
                final LoginAuthFlowListener listener = new LoginAuthFlowListener(latch);
                boxClient.authenticate(authFlowUI, true, listener);

                // wait for login to finish or timeout
                if (!latch.await(configuration.getLoginTimeout(), TimeUnit.SECONDS)) {
                    if (!boxClient.isAuthenticated()) {
                        throw new RuntimeCamelException(String.format("Login timeout for %s", cachedBoxClient));
                    }
                }
                final Exception ex = listener.getException();
                if (ex != null) {
                    throw new RuntimeCamelException(String.format("Login error for %s: %s",
                        cachedBoxClient, ex.getMessage()), ex);
                }
            }

            LOG.debug("OAuth token created for {}", cachedBoxClient);
            // notify the cached client listener for the first time, since BoxClient doesn't!!!
            cachedBoxClient.getListener().onRefresh(boxClient.getAuthData());
        }
    }
View Full Code Here

    }

    public static void shutdownBoxClient(BoxConfiguration configuration, CachedBoxClient cachedBoxClient)
        throws BoxServerException, BoxRestException, AuthFatalFailureException {

        final BoxClient boxClient = cachedBoxClient.getBoxClient();
        synchronized (boxClient) {

            LOG.debug("Shutting down {} ...", cachedBoxClient);
            try {
                // revoke token if requested
                if (configuration.isRevokeOnShutdown()) {
                    revokeOAuthToken(configuration, cachedBoxClient);
                }
            } finally {

                boxClient.setConnectionOpen(false);
                // close connections in the underlying HttpClient
                @SuppressWarnings("deprecation")
                final ClientConnectionManager connectionManager = cachedBoxClient.getClientConnectionManager();
                if (connectionManager != null) {
                    LOG.debug("Closing connections for {}", cachedBoxClient);
View Full Code Here

                }

                return httpClient;
            }
        };
        final BoxClient boxClient = new BoxClient(clientId, clientSecret, null, null,
            restClient, configuration.getBoxConfig());

        // enable OAuth auto-refresh
        boxClient.setAutoRefreshOAuth(true);

        // wrap the configured storage in a caching storage
        final CachingSecureStorage storage = new CachingSecureStorage(authSecureStorage);

        // set up a listener to notify secure storage and user provided listener, store it in configuration!
        final OAuthHelperListener listener = new OAuthHelperListener(storage, configuration.getRefreshListener());
        boxClient.addOAuthRefreshListener(listener);

        final CachedBoxClient cachedBoxClient = new CachedBoxClient(boxClient, userName, clientId, storage, listener, clientConnectionManager);
        LOG.debug("BoxClient created {}", cachedBoxClient);
        return cachedBoxClient;
    }
View Full Code Here

    }

    public static void getOAuthToken(BoxConfiguration configuration, CachedBoxClient cachedBoxClient)
        throws AuthFatalFailureException, BoxRestException, BoxServerException, InterruptedException {

        final BoxClient boxClient = cachedBoxClient.getBoxClient();
        synchronized (boxClient) {
            if (boxClient.isAuthenticated()) {
                return;
            }

            LOG.debug("Getting OAuth token for {}...", cachedBoxClient);

            final IAuthSecureStorage authSecureStorage = cachedBoxClient.getSecureStorage();
            if (authSecureStorage != null && authSecureStorage.getAuth() != null) {

                LOG.debug("Using secure storage for {}", cachedBoxClient);
                // authenticate using stored refresh token
                boxClient.authenticateFromSecureStorage(authSecureStorage);
            } else {

                LOG.debug("Using OAuth {}", cachedBoxClient);
                // authorize App for user, and create OAuth token with refresh token
                final IAuthFlowUI authFlowUI = new LoginAuthFlowUI(configuration, boxClient);
                final CountDownLatch latch = new CountDownLatch(1);
                final LoginAuthFlowListener listener = new LoginAuthFlowListener(latch);
                boxClient.authenticate(authFlowUI, true, listener);

                // wait for login to finish or timeout
                if (!latch.await(configuration.getLoginTimeout(), TimeUnit.SECONDS)) {
                    if (!boxClient.isAuthenticated()) {
                        throw new RuntimeCamelException(String.format("Login timeout for %s", cachedBoxClient));
                    }
                }
                final Exception ex = listener.getException();
                if (ex != null) {
                    throw new RuntimeCamelException(String.format("Login error for %s: %s",
                        cachedBoxClient, ex.getMessage()), ex);
                }
            }

            LOG.debug("OAuth token created for {}", cachedBoxClient);
            // notify the cached client listener for the first time, since BoxClient doesn't!!!
            cachedBoxClient.getListener().onRefresh(boxClient.getAuthData());
        }
    }
View Full Code Here

    }

    public static void shutdownBoxClient(BoxConfiguration configuration, CachedBoxClient cachedBoxClient)
        throws BoxServerException, BoxRestException, AuthFatalFailureException {

        final BoxClient boxClient = cachedBoxClient.getBoxClient();
        synchronized (boxClient) {

            LOG.debug("Shutting down {} ...", cachedBoxClient);
            try {
                // revoke token if requested
                if (configuration.isRevokeOnShutdown()) {
                    revokeOAuthToken(configuration, cachedBoxClient);
                }
            } finally {

                boxClient.setConnectionOpen(false);
                // close connections in the underlying HttpClient
                @SuppressWarnings("deprecation")
                final ClientConnectionManager connectionManager = cachedBoxClient.getClientConnectionManager();
                if (connectionManager != null) {
                    LOG.debug("Closing connections for {}", cachedBoxClient);
View Full Code Here

    }

    private static void revokeOAuthToken(BoxConfiguration configuration, CachedBoxClient cachedBoxClient)
        throws BoxServerException, BoxRestException, AuthFatalFailureException {

        final BoxClient boxClient = cachedBoxClient.getBoxClient();
        synchronized (boxClient) {

            if (boxClient.isAuthenticated()) {

                LOG.debug("Revoking OAuth refresh token for {}", cachedBoxClient);

                // revoke OAuth token
                boxClient.getOAuthManager().revokeOAuth(boxClient.getAuthData().getAccessToken(),
                    configuration.getClientId(), configuration.getClientSecret());

                // notify the OAuthListener of revoked token
                cachedBoxClient.getListener().onRefresh(null);
                // mark auth data revoked
                boxClient.getOAuthDataController().setOAuthData(null);
            }
        }
    }
View Full Code Here

                throw new IllegalArgumentException("Missing required property sharedLink");
            }
        default:
        }

        final BoxClient boxClient = cachedBoxClient.getBoxClient();
        switch (apiName) {
        case COLLABORATIONS:
            apiProxy = boxClient.getCollaborationsManager();
            break;
        case COMMENTS:
            apiProxy = boxClient.getCommentsManager();
            break;
        case EVENTS:
            apiProxy = boxClient.getEventsManager();
            break;
        case FILES:
            apiProxy = boxClient.getFilesManager();
            break;
        case FOLDERS:
            apiProxy = boxClient.getFoldersManager();
            break;
        case GROUPS:
            apiProxy = boxClient.getGroupsManager();
            break;
        case SEARCH:
            apiProxy = boxClient.getSearchManager();
            break;
        case SHARED_FILES:
            apiProxy = boxClient.getSharedFilesManager(sharedLink, sharedPassword);
            break;
        case SHARED_FOLDERS:
            apiProxy = boxClient.getSharedFoldersManager(sharedLink, sharedPassword);
            break;
        case SHARED_COMMENTS:
            apiProxy = boxClient.getSharedCommentsManager(sharedLink, sharedPassword);
            break;
        case SHARED_ITEMS:
            apiProxy = boxClient.getSharedItemsManager(sharedLink, sharedPassword);
            break;
        case USERS:
            apiProxy = boxClient.getUsersManager();
            break;
        default:
        }
    }
View Full Code Here

                + "clientId, clientSecret, userName and either authSecureStorage or userPassword");
        }
        LOG.debug("Creating BoxClient for login:{}, client_id:{} ...", userName, clientId);

        // if set, use configured connection manager builder
        final BoxConnectionManagerBuilder connectionManagerBuilder = configuration.getConnectionManagerBuilder();
        final BoxConnectionManagerBuilder connectionManager = connectionManagerBuilder != null
            ? connectionManagerBuilder : new BoxConnectionManagerBuilder();

        // create REST client for BoxClient
        final ClientConnectionManager[] clientConnectionManager = new ClientConnectionManager[1];
        final IBoxRESTClient restClient = new BoxRESTClient(connectionManager.build()) {
            @Override
            public HttpClient getRawHttpClient() {
                final HttpClient httpClient = super.getRawHttpClient();
                clientConnectionManager[0] = httpClient.getConnectionManager();
                final SchemeRegistry schemeRegistry = clientConnectionManager[0].getSchemeRegistry();
View Full Code Here

TOP

Related Classes of com.box.boxjavalibv2.resourcemanagers.IBoxOAuthManager

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.