org.sakaiproject.hybrid.util
Class NakamuraAuthenticationHelper

java.lang.Object
  extended by org.sakaiproject.hybrid.util.NakamuraAuthenticationHelper

public class NakamuraAuthenticationHelper
extends Object

Useful helper for interacting with Nakamura's authentication REST end-points. Note: thread safe.


Nested Class Summary
static class NakamuraAuthenticationHelper.AuthInfo
          Static final class for storing cached results from Nakamura lookup.
static class NakamuraAuthenticationHelper.DefaultHttpClientProvider
          Implementation is thread safe.
static interface NakamuraAuthenticationHelper.HttpClientProvider
          A simple abstraction to allow for unit testing of NakamuraAuthenticationHelper.
 
Field Summary
static String CONFIG_ANONYMOUS
          sakai.properties The name of the nakamura anonymous principal.
static String CONFIG_COOKIE_NAME
          sakai.properties The name of the cookie that is set by nakamura.
static String CONFIG_PREFIX
          All sakai.properties settings will be prefixed with this string.
protected  String hostname
          The hostname we will use to lookup the sharedSecret for access to validateUrl.
protected  NakamuraAuthenticationHelper.HttpClientProvider httpClientProvider
          A simple abstraction to allow for proper unit testing
protected  String principal
          The nakamura user that has permissions to GET /var/cluster/user.cookie.json.
protected  org.sakaiproject.component.api.ServerConfigurationService serverConfigurationService
           
protected static String THREAD_LOCAL_CACHE_KEY
          The key that will be used to cache AuthInfo hits in ThreadLocal.
protected  org.sakaiproject.thread_local.api.ThreadLocalManager threadLocalManager
           
protected  String validateUrl
          The Nakamura RESTful service to validate authenticated users.
protected  XSakaiToken xSakaiToken
           
 
Constructor Summary
NakamuraAuthenticationHelper(org.sakaiproject.component.api.ComponentManager componentManager, String validateUrl, String principal, String hostname)
          Class is immutable and thread safe.
 
Method Summary
 NakamuraAuthenticationHelper.AuthInfo getPrincipalLoggedIntoNakamura(javax.servlet.http.HttpServletRequest request)
          Calls Nakamura to determine the identity of the current user.
protected  String getSecret(javax.servlet.http.HttpServletRequest request)
          Gets the authentication key from SAKAI-TRACKING cookie.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CONFIG_PREFIX

public static final String CONFIG_PREFIX
All sakai.properties settings will be prefixed with this string.


CONFIG_ANONYMOUS

public static final String CONFIG_ANONYMOUS
sakai.properties The name of the nakamura anonymous principal.


CONFIG_COOKIE_NAME

public static final String CONFIG_COOKIE_NAME
sakai.properties The name of the cookie that is set by nakamura.


THREAD_LOCAL_CACHE_KEY

protected static final String THREAD_LOCAL_CACHE_KEY
The key that will be used to cache AuthInfo hits in ThreadLocal. This will handle cases where AuthInfo is requested more than once per request.


validateUrl

protected transient String validateUrl
The Nakamura RESTful service to validate authenticated users. A good default is provided.


principal

protected transient String principal
The nakamura user that has permissions to GET /var/cluster/user.cookie.json. A good default is provided.


hostname

protected transient String hostname
The hostname we will use to lookup the sharedSecret for access to validateUrl. A good default is provided.


httpClientProvider

protected transient NakamuraAuthenticationHelper.HttpClientProvider httpClientProvider
A simple abstraction to allow for proper unit testing


threadLocalManager

protected transient org.sakaiproject.thread_local.api.ThreadLocalManager threadLocalManager

serverConfigurationService

protected transient org.sakaiproject.component.api.ServerConfigurationService serverConfigurationService

xSakaiToken

protected transient XSakaiToken xSakaiToken
Constructor Detail

NakamuraAuthenticationHelper

public NakamuraAuthenticationHelper(org.sakaiproject.component.api.ComponentManager componentManager,
                                    String validateUrl,
                                    String principal,
                                    String hostname)
Class is immutable and thread safe.

Parameters:
validateUrl - The Nakamura REST end-point we will use to validate the cookie.
principal - The principal that will be used when connecting to Nakamura REST end-point. Must have permissions to read /var/cluster/user.cookie.json.
hostname - The hostname we will use to lookup the sharedSecret for access to validateUrl
Throws:
IllegalArgumentException
IllegalStateException
Method Detail

getPrincipalLoggedIntoNakamura

public NakamuraAuthenticationHelper.AuthInfo getPrincipalLoggedIntoNakamura(javax.servlet.http.HttpServletRequest request)
Calls Nakamura to determine the identity of the current user.

Parameters:
request -
Returns:
null if user cannot be authenticated.
Throws:
IllegalArgumentException
IllegalStateException - For all unexpected cause Exceptions.

getSecret

protected String getSecret(javax.servlet.http.HttpServletRequest request)
Gets the authentication key from SAKAI-TRACKING cookie.

Parameters:
request -
Returns:
null if no secret can be found.


Copyright © 2009-2013 The Sakai Foundation. All Rights Reserved.