/** * Retrieve access token, if needed, retrieve instance url, and set server host URL * {@inheritDoc} * @see org.apache.gobblin.writer.http.HttpWriter#onConnect(org.apache.http.HttpHost) */ @Override public void onConnect(URI serverHost) throws IOException { if (!StringUtils.isEmpty(accessToken)) { return; //No need to be called if accessToken is active. } try { getLog().info("Getting Oauth2 access token."); OAuthClientRequest request = OAuthClientRequest.tokenLocation(serverHost.toString()) .setGrantType(GrantType.PASSWORD) .setClientId(clientId) .setClientSecret(clientSecret) .setUsername(userId) .setPassword(password + securityToken).buildQueryMessage(); OAuthClient client = new OAuthClient(new URLConnectionClient()); OAuthJSONAccessTokenResponse response = client.accessToken(request, OAuth.HttpMethod.POST); accessToken = response.getAccessToken(); setCurServerHost(new URI(response.getParam("instance_url"))); } catch (OAuthProblemException e) { throw new NonTransientException("Error while authenticating with Oauth2", e); } catch (OAuthSystemException e) { throw new RuntimeException("Failed getting access token", e); } catch (URISyntaxException e) { throw new RuntimeException("Failed due to invalid instance url", e); } }
/** * Retrieve access token, if needed, retrieve instance url, and set server host URL * {@inheritDoc} * @see org.apache.gobblin.writer.http.HttpWriter#onConnect(org.apache.http.HttpHost) */ @Override public void onConnect(URI serverHost) throws IOException { if (!StringUtils.isEmpty(accessToken)) { return; //No need to be called if accessToken is active. } try { getLog().info("Getting Oauth2 access token."); OAuthClientRequest request = OAuthClientRequest.tokenLocation(serverHost.toString()) .setGrantType(GrantType.PASSWORD) .setClientId(clientId) .setClientSecret(clientSecret) .setUsername(userId) .setPassword(password + securityToken).buildQueryMessage(); OAuthClient client = new OAuthClient(new URLConnectionClient()); OAuthJSONAccessTokenResponse response = client.accessToken(request, OAuth.HttpMethod.POST); accessToken = response.getAccessToken(); setCurServerHost(new URI(response.getParam("instance_url"))); } catch (OAuthProblemException e) { throw new NonTransientException("Error while authenticating with Oauth2", e); } catch (OAuthSystemException e) { throw new RuntimeException("Failed getting access token", e); } catch (URISyntaxException e) { throw new RuntimeException("Failed due to invalid instance url", e); } }
/** * Helper method to configure the username/password for basic auth or password oauth * @param username Username * @param password Password * @return ApiClient */ public ApiClient setCredentials(String username, String password) { for(Interceptor apiAuthorization : apiAuthorizations.values()) { if (apiAuthorization instanceof HttpBasicAuth) { HttpBasicAuth basicAuth = (HttpBasicAuth) apiAuthorization; basicAuth.setCredentials(username, password); return this; } if (apiAuthorization instanceof OAuth) { OAuth oauth = (OAuth) apiAuthorization; oauth.getTokenRequestBuilder().setUsername(username).setPassword(password); return this; } } return this; }
setRedirectURI(""). setUsername(username). setPassword(password). setScope("openid"). buildBodyMessage();
/** * Helper method to configure the username/password for basic auth or password oauth * @param username Username * @param password Password * @return ApiClient */ public ApiClient setCredentials(String username, String password) { for(Interceptor apiAuthorization : apiAuthorizations.values()) { if (apiAuthorization instanceof HttpBasicAuth) { HttpBasicAuth basicAuth = (HttpBasicAuth) apiAuthorization; basicAuth.setCredentials(username, password); return this; } if (apiAuthorization instanceof OAuth) { OAuth oauth = (OAuth) apiAuthorization; oauth.getTokenRequestBuilder().setUsername(username).setPassword(password); return this; } } return this; }
/** * Helper method to configure the username/password for basic auth or password oauth * @param username Username * @param password Password * @return ApiClient */ public ApiClient setCredentials(String username, String password) { for(Interceptor apiAuthorization : apiAuthorizations.values()) { if (apiAuthorization instanceof HttpBasicAuth) { HttpBasicAuth basicAuth = (HttpBasicAuth) apiAuthorization; basicAuth.setCredentials(username, password); return this; } if (apiAuthorization instanceof OAuth) { OAuth oauth = (OAuth) apiAuthorization; oauth.getTokenRequestBuilder().setUsername(username).setPassword(password); return this; } } return this; }
/** * Helper method to configure the username/password for basic auth or password oauth * @param username Username * @param password Password * @return ApiClient */ public ApiClient setCredentials(String username, String password) { for(Interceptor apiAuthorization : apiAuthorizations.values()) { if (apiAuthorization instanceof HttpBasicAuth) { HttpBasicAuth basicAuth = (HttpBasicAuth) apiAuthorization; basicAuth.setCredentials(username, password); return this; } if (apiAuthorization instanceof OAuth) { OAuth oauth = (OAuth) apiAuthorization; oauth.getTokenRequestBuilder().setUsername(username).setPassword(password); return this; } } return this; }
/** * Helper method to configure the username/password for basic auth or password oauth * @param username Username * @param password Password * @return ApiClient */ public ApiClient setCredentials(String username, String password) { for(Interceptor apiAuthorization : apiAuthorizations.values()) { if (apiAuthorization instanceof HttpBasicAuth) { HttpBasicAuth basicAuth = (HttpBasicAuth) apiAuthorization; basicAuth.setCredentials(username, password); return this; } if (apiAuthorization instanceof OAuth) { OAuth oauth = (OAuth) apiAuthorization; oauth.getTokenRequestBuilder().setUsername(username).setPassword(password); return this; } } return this; }
/** * Helper method to configure the username/password for basic auth or password oauth * @param username Username * @param password Password * @return ApiClient */ public ApiClient setCredentials(String username, String password) { for(Interceptor apiAuthorization : apiAuthorizations.values()) { if (apiAuthorization instanceof HttpBasicAuth) { HttpBasicAuth basicAuth = (HttpBasicAuth) apiAuthorization; basicAuth.setCredentials(username, password); return this; } if (apiAuthorization instanceof OAuth) { OAuth oauth = (OAuth) apiAuthorization; oauth.getTokenRequestBuilder().setUsername(username).setPassword(password); return this; } } return this; }
/** * Helper constructor for single password oauth2 * @param authName Authentication name * @param clientId Client ID * @param secret Client Secret * @param username Username * @param password Password */ public ApiClient(String authName, String clientId, String secret, String username, String password) { this(authName); this.getTokenEndPoint() .setClientId(clientId) .setClientSecret(secret) .setUsername(username) .setPassword(password); }
/** * Helper method to configure the username/password for basic auth or password oauth * @param username Username * @param password Password * @return ApiClient */ public ApiClient setCredentials(String username, String password) { for(Interceptor apiAuthorization : apiAuthorizations.values()) { if (apiAuthorization instanceof HttpBasicAuth) { HttpBasicAuth basicAuth = (HttpBasicAuth) apiAuthorization; basicAuth.setCredentials(username, password); return this; } if (apiAuthorization instanceof OAuth) { OAuth oauth = (OAuth) apiAuthorization; oauth.getTokenRequestBuilder().setUsername(username).setPassword(password); return this; } } return this; }
/** * Helper constructor for single password oauth2 * @param authName Authentication name * @param clientId Client ID * @param secret Client Secret * @param username Username * @param password Password */ public ApiClient(String authName, String clientId, String secret, String username, String password) { this(authName); this.getTokenEndPoint() .setClientId(clientId) .setClientSecret(secret) .setUsername(username) .setPassword(password); }
/** * Helper constructor for single password oauth2 * @param authName Authentication name * @param clientId Client ID * @param secret Client Secret * @param username Username * @param password Password */ public ApiClient(String authName, String clientId, String secret, String username, String password) { this(authName); this.getTokenEndPoint() .setClientId(clientId) .setClientSecret(secret) .setUsername(username) .setPassword(password); }
/** * Helper constructor for single password oauth2 * @param authName Authentication name * @param clientId Client ID * @param secret Client Secret * @param username Username * @param password Password */ public ApiClient(String authName, String clientId, String secret, String username, String password) { this(authName); this.getTokenEndPoint() .setClientId(clientId) .setClientSecret(secret) .setUsername(username) .setPassword(password); }
/** * Helper constructor for single password oauth2 * @param authName Authentication name * @param clientId Client ID * @param secret Client Secret * @param username Username * @param password Password */ public ApiClient(String authName, String clientId, String secret, String username, String password) { this(authName); this.getTokenEndPoint() .setClientId(clientId) .setClientSecret(secret) .setUsername(username) .setPassword(password); }
/** * Helper constructor for single password oauth2 * @param authName Authentication name * @param clientId Client ID * @param secret Client Secret * @param username Username * @param password Password */ public ApiClient(String authName, String clientId, String secret, String username, String password) { this(authName); this.getTokenEndPoint() .setClientId(clientId) .setClientSecret(secret) .setUsername(username) .setPassword(password); }
/** * Helper constructor for single password oauth2 * @param authName Authentication name * @param clientId Client ID * @param secret Client Secret * @param username Username * @param password Password */ public ApiClient(String authName, String clientId, String secret, String username, String password) { this(authName); this.getTokenEndPoint() .setClientId(clientId) .setClientSecret(secret) .setUsername(username) .setPassword(password); }