Package org.jets3t.service.security

Examples of org.jets3t.service.security.OAuth2Tokens


    @Override
    public void authorizeHttpRequest(HttpUriRequest httpMethod, HttpContext context)
            throws ServiceException
    {
        if (getProviderCredentials() instanceof OAuth2Credentials) {
            OAuth2Tokens tokens;
            try {
                tokens = ((OAuth2Credentials)getProviderCredentials()).getOAuth2Tokens();
            }
            catch(IOException e) {
                throw new ServiceException("Failure retrieving OAuth2 tokens", e);
            }
            if (tokens == null) {
                throw new ServiceException(
                        "Cannot authenticate using OAuth2 until initial tokens are provided"
                                + ", i.e. via setOAuth2Tokens()");
            }
            log.debug("Authorizing service request with OAuth2 access token: "
                    + tokens.getAccessToken());
            httpMethod.setHeader("Authorization", "OAuth " + tokens.getAccessToken());
            httpMethod.setHeader("x-goog-api-version", "2");
        } else {
            super.authorizeHttpRequest(httpMethod, context);
        }
    }
View Full Code Here


    protected boolean isRecoverable403(HttpUriRequest httpRequest, Exception exception)
    {
        if (getProviderCredentials() instanceof OAuth2Credentials) {
            // Only retry if we're using OAuth2 authentication and can refresh the access token
            // TODO Any way to distinguish between expired access token and other 403 reasons?
            OAuth2Tokens tokens;
            try {
                tokens = ((OAuth2Credentials)getProviderCredentials()).getOAuth2Tokens();
            }
            catch(IOException e) {
                return false;
            }
            if (tokens != null) {
                tokens.expireAccessToken();
                return true;
            }
        }
        return super.isRecoverable403(httpRequest, exception);
    }
View Full Code Here

            if(accessToken == null || refreshToken == null) {
                throw new IOException("OAuth2 authentication-to-tokens error, missing token(s) in data: "
                        + responseData);
            }

            return new OAuth2Tokens(
                    accessToken, refreshToken,
                    OAuth2Tokens.calculateExpiry(expiresIn));
        }
        else {
            throw new IllegalStateException("Unsupported implementation: " + this.implementation);
View Full Code Here

            if(accessToken == null) {
                throw new IOException("OAuth2 error refreshing access token, missing token in data: "
                        + responseData);
            }

            return new OAuth2Tokens(
                    accessToken, tokens.getRefreshToken(),
                    OAuth2Tokens.calculateExpiry(expiresIn));
        }
        else {
            throw new IllegalStateException("Unsupported implementation: " + this.implementation);
View Full Code Here

TOP

Related Classes of org.jets3t.service.security.OAuth2Tokens

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.