Skip navigation links

Oracle Fusion Middleware Java API Reference for the Oracle Access Management OAuth Service
11g Release 2 Patch Set 3 (11.1.2.3)

E59498-01


oracle.security.idaas.oauth.sdk.http
Class OAuthRestClient

java.lang.Object
  extended by oracle.security.idaas.oauth.sdk.http.OAuthRestClient

All Implemented Interfaces:
OAuthClient

public class OAuthRestClient
extends java.lang.Object
implements OAuthClient

Implements an HTTP handler to interface with the Oracle OAuth Server.

This client requires the following libraries:

Example:

 
 public static void main(String[] args) {
  Properties serverInfo = new Properties();
  serverInfo.put("oauthServiceProfileUrl", "http://www.example.com:14100/ms_oauth/oauth2/endpoints/oauthservice");
  serverInfo.put("useProxy", "false");

  OAuthClient me = new OAuthRestClient(serverInfo);

  ClientIdSecretPair clid = null;
  String clientid="8cc47cefb6514ac49bb02bc3aedac068";

  try {
    clid = new ClientIdSecretPair(clientId, "welcome1");
  } catch (Exception e) {
  }

  try {
    ClientAssertionTokenRequest ct1 = new ClientAssertionTokenRequest(clid);
    ClientAssertionTokenResponse tokResp = (ClientAssertionTokenResponse) me.createToken(ct1);

    if (tokResp.isError()) {
      System.out.println(tokResp.getErrorMessage());
    } else {
      System.out.println("Response=" + tokResp.getAccessToken().toString());
    }
  } catch (Exception e) {
    e.printStackTrace();
  }
 }
 
 

Constructor Summary

OAuthRestClient(java.io.InputStream inputStream)
          Constructor reading the configuration from the given InputStream.
OAuthRestClient(java.util.Properties properties)
          Constructor using a Java Properties format for client configuration.
OAuthRestClient(java.net.URL config)
          Constructor using URL location of the Properties file containing client configuration.

  Method Summary

 OAuthTokenResponse createToken(OAuthTokenRequest request)
          Returns a token based on the parameter set in the request.
protected static HttpResponse execHttpRequest(java.lang.String url, java.lang.String method, java.util.Map<java.lang.String,java.lang.String> requestOptions, java.lang.String httpData, java.lang.String useProxy, java.lang.String proxyHost, java.lang.String proxyPort, boolean output)
          Handles the HTTP request using the given parameters.
protected static java.lang.String getCurl(java.lang.String url, java.lang.String method, java.util.Map<java.lang.String,java.lang.String> requestOptions, java.lang.String httpData)
          Builds and outputs as String the curl equivalent command of the HTTP request.
 java.lang.String getProperty(java.lang.String key)
          Returns the value of given key.
 void setProperty(java.lang.String key, java.lang.String value)
          Changes the value of corresponding key.
 RevocationResponse terminateToken(RevocationRequest request)
          Terminates a Token and returns the result.
 AccessTokenValidationResponse validateToken(AccessTokenValidationRequest request)
          Returns the result of the token validation.

  Methods inherited from class java.lang.Object

clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

 

Constructor Detail

OAuthRestClient

public OAuthRestClient(java.util.Properties properties)
Constructor using a Java Properties format for client configuration. The minimum configuration shall include the following string properties:
Parameters:
properties - configuration

OAuthRestClient

public OAuthRestClient(java.net.URL config)
                throws java.io.IOException
Constructor using URL location of the Properties file containing client configuration. The minimum configuration shall include the following string properties:
 oauthServiceProfileUrl=http://hostname:portNumber/ms_oauth/oauth2/endpoints/...
 useProxy=true|false
 proxyHost=hostname
 proxyPort=portNumber
 outputCurlCde=true|false
 
Parameters:
config - configuration
Throws:
java.io.IOException - if an I/O error occurs.

OAuthRestClient

public OAuthRestClient(java.io.InputStream inputStream)
                throws java.io.IOException
Constructor reading the configuration from the given InputStream. The minimum configuration shall include the following string properties:
 oauthServiceProfileUrl=http://hostname:portNumber/ms_oauth/oauth2/endpoints/...
 useProxy=true|false
 proxyHost=hostname
 proxyPort=portNumber
 outputCurlCde=true|false
 
Parameters:
inputStream - Configuration information
Throws:
java.io.IOException - if an I/O error occurs.

Method Detail

setProperty

public void setProperty(java.lang.String key,
                        java.lang.String value)
Changes the value of corresponding key.
Parameters:
key - of attribute
value - of attribute

getProperty

public java.lang.String getProperty(java.lang.String key)
Returns the value of given key.
Parameters:
key - of attribute
Returns:
string formatted value

createToken

public OAuthTokenResponse createToken(OAuthTokenRequest request)
                               throws OAuthSdkException
Returns a token based on the parameter set in the request.

This implementation is using the java instrospection to build and instantiate the response based on the provided request class name.

OAuthSdkException encapsulates and is thrown in the following cases:

Specified by:
createToken in interface OAuthClient
Parameters:
request - an token request
Returns:
a response including a token or an error
Throws:
OAuthSdkException - reports an issue as described above

validateToken

public AccessTokenValidationResponse validateToken(AccessTokenValidationRequest request)
                                            throws OAuthSdkException
Returns the result of the token validation. It includes:

OAuthSdkException encapsulates and is thrown in the following cases:

Specified by:
validateToken in interface OAuthClient
Parameters:
request - contains the token and requested claims
Returns:
the validation result
Throws:
OAuthSdkException - see details above

terminateToken

public RevocationResponse terminateToken(RevocationRequest request)
                                  throws OAuthSdkException
Description copied from interface: OAuthClient
Terminates a Token and returns the result.
Specified by:
terminateToken in interface OAuthClient
Parameters:
request - contains the revocation token information
Returns:
the response
Throws:
OAuthSdkException - in case of failure

execHttpRequest

protected static HttpResponse execHttpRequest(java.lang.String url,
                                              java.lang.String method,
                                              java.util.Map<java.lang.String,java.lang.String> requestOptions,
                                              java.lang.String httpData,
                                              java.lang.String useProxy,
                                              java.lang.String proxyHost,
                                              java.lang.String proxyPort,
                                              boolean output)
                                       throws java.io.IOException
Handles the HTTP request using the given parameters.
Parameters:
url - oauth tokens endpoint
method - POST or GET or PUT or DELETE
requestOptions - key value pair of the header parameters
httpData - data to be sent
useProxy - true if a proxy is required
proxyHost - hostname of the proxy
proxyPort - port number of the proxy
output - if true the equivalent curl command will be displayed to the standard output
Returns:
the result of the call
Throws:
java.io.IOException - if an I/O error occurs.

getCurl

protected static java.lang.String getCurl(java.lang.String url,
                                          java.lang.String method,
                                          java.util.Map<java.lang.String,java.lang.String> requestOptions,
                                          java.lang.String httpData)
Builds and outputs as String the curl equivalent command of the HTTP request.
Parameters:
url - endpoint
method - POST or GET
requestOptions - key value pairs of options
httpData - body of request
Returns:
the curl command

Skip navigation links

Copyright (c) 2014, 2015,
Oracle and/or its affiliates. All Rights Reserved.