org.restlet.ext.oauth
Class OAuthProxy
java.lang.Object
org.restlet.Restlet
org.restlet.routing.Filter
org.restlet.ext.oauth.OAuthProxy
- All Implemented Interfaces:
- Uniform
public class OAuthProxy
- extends Filter
A restlet filter for initiating a web server flow or comparable to OAuth 2.0
3-legged authorization.
On successful execution a working OAuth token will be maintained. It is
recommended to put a ServerResource after this filter to display to the end
user on successful service setup.
The following example shows how to gain an accesstoken that will be available
for "DummyResource" to use to access some remote protected resource
{
@code
OAuthParameter params = new OAuthParameters("clientId", "clientSecret",
oauthURL, "scope1 scope2");
OAuthProxy proxy = new OauthProxy(params, getContext(), true);
proxy.setNext(DummyResource.class);
router.attach("/write", write);
//A Slightly more advanced example that also sets some SSL client parameters
Client client = new Client(Protocol.HTTPS);
Context c = new Context();
client.setContext(c);
c.getParameters().add("truststorePath", "pathToKeyStoreFile");
c.getParameters(0.add("truststorePassword", "password");
OAuthParameter params = new OAuthParameters("clientId", "clientSecret",
oauthURL, "scope1 scope2");
OAuthProxy proxy = new OauthProxy(params, getContext(), true, client);
proxy.setNext(DummyResource.class);
router.attach("/write", write);
}
- Author:
- Kristoffer Gronowski
- See Also:
OAuthParameters
| Methods inherited from class org.restlet.Restlet |
createFinder, finalize, getApplication, getAuthor, getContext, getDescription, getFinderClass, getLogger, getName, getOwner, handle, handle, handle, isStarted, isStopped, setAuthor, setContext, setDescription, setFinderClass, setName, setOwner |
OAuthProxy
public OAuthProxy(OAuthParameters params,
Context ctx)
- Sets up an OauthProxy. Defaults to form based authentication and not http
basic.
- Parameters:
params - The OAuth parameters.ctx - The Restlet context.
OAuthProxy
public OAuthProxy(OAuthParameters params,
Context ctx,
boolean useBasicSecret)
- Sets up an OAuthProxy.
- Parameters:
params - The OAuth parameters.useBasicSecret - If true use http basic authentication otherwise use form
based.ctx - The Restlet context.
OAuthProxy
public OAuthProxy(OAuthParameters params,
Context ctx,
boolean useBasicSecret,
Client requestClient)
- Sets up an OAuthProxy.
- Parameters:
params - The OAuth parameters.useBasicSecret - If true use http basic authentication otherwise use form
based.ctx - The Restlet context.requestClient - A predefined client that will be used for remote client
request. Useful when you need to set e.g. SSL initialization
parameters
getVersion
public static String getVersion()
- Returns the current proxy's version.
- Returns:
- The current proxy's version.
beforeHandle
protected int beforeHandle(Request request,
Response response)
- Overrides:
beforeHandle in class Filter
start
public void start()
throws Exception
- Overrides:
start in class Filter
- Throws:
Exception
stop
public void stop()
throws Exception
- Overrides:
stop in class Filter
- Throws:
Exception
Copyright © 2005-2012 Restlet S.A.S..