|
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 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object
oracle.security.idaas.oauth.sdk.http.OAuthRestClient
public class OAuthRestClient
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. |
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
public OAuthRestClient(java.util.Properties properties)
properties
- configurationpublic OAuthRestClient(java.net.URL config) throws java.io.IOException
oauthServiceProfileUrl=http://hostname:portNumber/ms_oauth/oauth2/endpoints/... useProxy=true|false proxyHost=hostname proxyPort=portNumber outputCurlCde=true|false
config
- configurationjava.io.IOException
- if an I/O error occurs.public OAuthRestClient(java.io.InputStream inputStream) throws java.io.IOException
oauthServiceProfileUrl=http://hostname:portNumber/ms_oauth/oauth2/endpoints/... useProxy=true|false proxyHost=hostname proxyPort=portNumber outputCurlCde=true|false
inputStream
- Configuration informationjava.io.IOException
- if an I/O error occurs.public void setProperty(java.lang.String key, java.lang.String value)
key
- of attributevalue
- of attributepublic java.lang.String getProperty(java.lang.String key)
key
- of attributepublic OAuthTokenResponse createToken(OAuthTokenRequest request) throws OAuthSdkException
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:
ClassNotFoundException
: when the Response class is not found: verify that the request/response pattern is respected.NoSuchMethodException
: the Response class does not include the mandatory constructor: verify if the response class has a constructor with a HttpResponse
argument.InstantiationException
: unable to instantiate the REsponse class.IllegalAccessException
: this client is not authorized to instantiate the response.InvocationTargetException
: error when calling the Response constructor.IOException
: the client fails to communicate with the server: verify that the server is running and if the provided "oauthServiceProfileUrl" parameter is correct as well as the proxy information.JSONException
).createToken
in interface OAuthClient
request
- an token requestOAuthSdkException
- reports an issue as described abovepublic AccessTokenValidationResponse validateToken(AccessTokenValidationRequest request) throws OAuthSdkException
OAuthSdkException
encapsulates and is thrown in the following cases:
IOException
: the client fails to communicate with the server: verify that the server is running and if the provided "oauthServiceProfileUrl" parameter is correct as well as the proxy information.JSONException
: this method fails to format the obtained response.validateToken
in interface OAuthClient
request
- contains the token and requested claimsOAuthSdkException
- see details abovepublic RevocationResponse terminateToken(RevocationRequest request) throws OAuthSdkException
OAuthClient
terminateToken
in interface OAuthClient
request
- contains the revocation token informationOAuthSdkException
- in case of failureprotected 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
url
- oauth tokens endpointmethod
- POST or GET or PUT or DELETErequestOptions
- key value pair of the header parametershttpData
- data to be sentuseProxy
- true if a proxy is requiredproxyHost
- hostname of the proxyproxyPort
- port number of the proxyoutput
- if true the equivalent curl command will be displayed to the standard outputjava.io.IOException
- if an I/O error occurs.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)
url
- endpointmethod
- POST or GETrequestOptions
- key value pairs of optionshttpData
- body of request
|
Oracle and/or its affiliates. All Rights Reserved. |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |