org.restlet.ext.oauth
Class OAuthProxy

java.lang.Object
  extended by org.restlet.Restlet
      extended by org.restlet.routing.Filter
          extended by 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

Field Summary
 
Fields inherited from class org.restlet.routing.Filter
CONTINUE, SKIP, STOP
 
Constructor Summary
OAuthProxy(OAuthParameters params, Context ctx)
          Sets up an OauthProxy.
OAuthProxy(OAuthParameters params, Context ctx, boolean useBasicSecret)
          Sets up an OAuthProxy.
OAuthProxy(OAuthParameters params, Context ctx, boolean useBasicSecret, Client requestClient)
          Sets up an OAuthProxy.
OAuthProxy(OAuthParameters params, Context ctx, boolean useBasicSecret, Filter interceptor)
          Sets up an OAuthProxy.
 
Method Summary
protected  int beforeHandle(Request request, Response response)
           
static String getVersion()
          Returns the current proxy's version.
 void start()
           
 void stop()
           
 
Methods inherited from class org.restlet.routing.Filter
afterHandle, doHandle, getNext, handle, hasNext, setNext, setNext
 
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
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

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,
                  Filter interceptor)
Sets up an OAuthProxy.

Parameters:
params - The OAuth parameters.
useBasicSecret - If true use http basic authentication otherwise use form based.
ctx - The Restlet context.
interceptor - A predefined client filter that will be used for remote request. Useful when a community has non complian request or response parameters that need to be normalized.

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
Method Detail

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-2013 Restlet.