no.feide.moria.store
Class MoriaCacheStore

java.lang.Object
  extended by no.feide.moria.store.MoriaCacheStore
All Implemented Interfaces:
MoriaStore

public final class MoriaCacheStore
extends java.lang.Object
implements MoriaStore

Distributed store implementation using JBoss Cache.

Version:
$Revision: 1.40 $
Author:
Bjørn Ola Smievoll <b.o@smievoll.no>

Field Summary
private static java.lang.String CACHE_CONFIG_PROPERTY_NAME
          The name of the configuration file property.
private static java.lang.String DATA_ATTRIBUTE
          The common hashmap key for the data attributes (MoriaAuthnAttempt & CachedUserData).
private  java.lang.Boolean isConfigured
          The configured state of the store.
private  no.feide.moria.log.MessageLogger messageLogger
          The logger used by this class.
private  java.lang.String nodeId
          The node identificator for this node ( : ).
private static java.lang.String PRINCIPAL_ATTRIBUTE
          The common hashmap key for the principal.
private static java.lang.String REAL_TTL_PERCENTAGE_PROPERTY_NAME
          The name of the ttl percentage property.
private  org.jboss.cache.TreeCache store
          The cache instance.
private static java.lang.String TICKET_TYPE_ATTRIBUTE
          The common hashmap key for the ticket type.
private  java.util.Map ticketDefaultTTLs
          Map containing the default ttl values.
private  java.util.Map ticketTTLs
          Map to contain the ticket ttl values.
private static java.lang.String TTL_ATTRIBUTE
          The common hashmap key for the time to live.
private static java.lang.String USERORG_ATTRIBUTE
          The common hashmap key for the userorg attribute.
 
Constructor Summary
MoriaCacheStore()
          Constructs a new instance.
 
Method Summary
 java.lang.String cacheUserData(java.util.HashMap attributes, java.lang.String userorg)
          Creates a new CachedUserData object in the store and associates it with an SSO ticket which is returned.
 java.lang.String createAuthnAttempt(java.lang.String[] requestedAttributes, java.lang.String responseURLPrefix, java.lang.String responseURLPostfix, boolean forceInteractiveAuthentication, java.lang.String servicePrincipal)
          Creates an authentication attempt based on a service request.
 java.lang.String createProxyTicket(java.lang.String tgTicketId, java.lang.String servicePrincipal, java.lang.String targetServicePrincipal)
          Creates a new proxy ticket from a TGT and associates the new ticket with the same user data as the TGT.
 java.lang.String createServiceTicket(java.lang.String loginTicketId)
          Creates a service ticket that the service will use when requesting user attributes after a successful authentication.
 java.lang.String createTicketGrantingTicket(java.lang.String ssoTicketId, java.lang.String targetServicePrincipal)
          Creates a new ticket granting ticket, using an sso ticket.
 MoriaAuthnAttempt getAuthnAttempt(java.lang.String ticketId, boolean keep, java.lang.String servicePrincipal)
          Gets the authentication attempt associated with the ticket given as argument.
(package private)  MoriaTicket getFromStore(MoriaTicketType[] ticketTypes, java.lang.String ticketId)
          Retrieves a ticket instance which may be one of a number of types.
(package private)  MoriaTicket getFromStore(MoriaTicketType ticketType, java.lang.String ticketId)
          Retrieves a ticket instance from the store.
 java.lang.String getTicketServicePrincipal(java.lang.String ticketId, MoriaTicketType ticketType)
          Returns the service principal for the ticket.
 java.lang.String getTicketUserorg(java.lang.String ticketId, MoriaTicketType ticketType)
          Gets the userorg of a ticket.
 CachedUserData getUserData(java.lang.String ticketId, java.lang.String servicePrincipal)
          Returns the userdata associated with the incoming ticket, which must be either a proxy ticket, an SSO ticket or ticket granting ticket.
private  void insertIntoStore(MoriaTicket ticket)
          Inserts an authentication attempt or cached user data into the cache.
private  void removeFromStore(MoriaTicket ticket)
          Removes a ticket, and possibly a connected userdata or authnAttempt from the cache.
 void removeSSOTicket(java.lang.String ssoTicketId)
          Removes an SSO ticket from the store.
 void setConfig(java.util.Properties properties)
          Configures the store.
 void setTicketUserorg(java.lang.String ticketId, MoriaTicketType ticketType, java.lang.String userorg)
          Sets the userorg of a ticket.
 void setTransientAttributes(java.lang.String loginTicketId, java.util.HashMap transientAttributes)
          Sets transient attributes stored with authentication attempt in an SSO context, which implies that not all cached (for potential SSO attributes) should be included.
 void setTransientSSOAttributes(java.lang.String loginTicketId, java.lang.String ssoTicketId, java.lang.String[] ssoEnabledAttributeNames)
          Sets transient attributes stored with authentication attempt, copied from a cached user data object.
 void stop()
          Stops this instance of the store.
private  void validateTicket(MoriaTicket ticket, MoriaTicketType[] ticketTypes, java.lang.String servicePrincipal)
          Check validity of ticket against a set of types and expiry time.
private  void validateTicket(MoriaTicket ticket, MoriaTicketType ticketType, java.lang.String servicePrincipal)
          Checks validity of ticket against type and expiry time.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

store

private org.jboss.cache.TreeCache store
The cache instance.


isConfigured

private java.lang.Boolean isConfigured
The configured state of the store.


messageLogger

private no.feide.moria.log.MessageLogger messageLogger
The logger used by this class.


ticketTTLs

private java.util.Map ticketTTLs
Map to contain the ticket ttl values.


ticketDefaultTTLs

private final java.util.Map ticketDefaultTTLs
Map containing the default ttl values.


TICKET_TYPE_ATTRIBUTE

private static final java.lang.String TICKET_TYPE_ATTRIBUTE
The common hashmap key for the ticket type.

See Also:
Constant Field Values

TTL_ATTRIBUTE

private static final java.lang.String TTL_ATTRIBUTE
The common hashmap key for the time to live.

See Also:
Constant Field Values

PRINCIPAL_ATTRIBUTE

private static final java.lang.String PRINCIPAL_ATTRIBUTE
The common hashmap key for the principal.

See Also:
Constant Field Values

nodeId

private java.lang.String nodeId
The node identificator for this node ( : ).


DATA_ATTRIBUTE

private static final java.lang.String DATA_ATTRIBUTE
The common hashmap key for the data attributes (MoriaAuthnAttempt & CachedUserData).

See Also:
Constant Field Values

USERORG_ATTRIBUTE

private static final java.lang.String USERORG_ATTRIBUTE
The common hashmap key for the userorg attribute.

See Also:
Constant Field Values

CACHE_CONFIG_PROPERTY_NAME

private static final java.lang.String CACHE_CONFIG_PROPERTY_NAME
The name of the configuration file property.

See Also:
Constant Field Values

REAL_TTL_PERCENTAGE_PROPERTY_NAME

private static final java.lang.String REAL_TTL_PERCENTAGE_PROPERTY_NAME
The name of the ttl percentage property.

See Also:
Constant Field Values
Constructor Detail

MoriaCacheStore

public MoriaCacheStore()
                throws MoriaStoreException
Constructs a new instance.

Throws:
MoriaStoreException - If creation of JBoss TreeCache fails.
Method Detail

setConfig

public void setConfig(java.util.Properties properties)
               throws MoriaStoreConfigurationException
Configures the store. This method expects the properties no.feide.moria.store.cacheconf and no.feide.moria.store.real_ttl_percentage to be set. The former must point to a JBossCache specific configuration file, the latter contain a value between 1 and 100. The method will return without actually executing and thus maintain the current state if called more than once per object instance.

Specified by:
setConfig in interface MoriaStore
Parameters:
properties - The properties used to configure the store.
Throws:
MoriaStoreConfigurationException - If something fails during the process of starting the store.
java.lang.IllegalArgumentException - If properties is null.
java.lang.NullPointerException - If defaultTTL is null.
See Also:
MoriaStore.setConfig(java.util.Properties)

stop

public void stop()
Stops this instance of the store.

Specified by:
stop in interface MoriaStore
See Also:
MoriaStore.stop()

createAuthnAttempt

public java.lang.String createAuthnAttempt(java.lang.String[] requestedAttributes,
                                           java.lang.String responseURLPrefix,
                                           java.lang.String responseURLPostfix,
                                           boolean forceInteractiveAuthentication,
                                           java.lang.String servicePrincipal)
                                    throws MoriaStoreException
Creates an authentication attempt based on a service request.

Specified by:
createAuthnAttempt in interface MoriaStore
Parameters:
requestedAttributes - The user attributes the requesting service asks for.
responseURLPrefix - The forward part of the url the client is to be redirected to.
responseURLPostfix - The end part of the url the client is to be redirected to.
forceInteractiveAuthentication - If the user should be forced to login interactively. I.e. disable support for single sign-on.
servicePrincipal - The id of the service doing the request.
Returns:
A login ticket identifying the authentication attempt.
Throws:
MoriaStoreException - If the operation fails.
java.lang.IllegalArgumentException - If any of the arguments are null, and if responseURLPrefix or servicePrincipal are zero length.
See Also:
MoriaStore.createAuthnAttempt(java.lang.String[], java.lang.String, java.lang.String, boolean, java.lang.String)

getAuthnAttempt

public MoriaAuthnAttempt getAuthnAttempt(java.lang.String ticketId,
                                         boolean keep,
                                         java.lang.String servicePrincipal)
                                  throws InvalidTicketException,
                                         NonExistentTicketException,
                                         MoriaStoreException
Gets the authentication attempt associated with the ticket given as argument.

Specified by:
getAuthnAttempt in interface MoriaStore
Parameters:
ticketId - The ticket ID. Must be a non-empty string.
keep - If false, the ticket will be removed from the store before returning. Otherwise keep the ticket.
servicePrincipal - The principal used by the service to authenticate itself to Moria. May be null.
Returns:
The authentication attempt.
Throws:
java.lang.IllegalArgumentException - If ticket ID is null or an empty string.
NonExistentTicketException - If the ticket does not exist in the store.
InvalidTicketException - If the ticket is not associated with an authentication attempt.
MoriaStoreException - If the operation fails.
See Also:
MoriaStore.getAuthnAttempt(java.lang.String, boolean, java.lang.String)

cacheUserData

public java.lang.String cacheUserData(java.util.HashMap attributes,
                                      java.lang.String userorg)
                               throws MoriaStoreException
Creates a new CachedUserData object in the store and associates it with an SSO ticket which is returned.

Specified by:
cacheUserData in interface MoriaStore
Parameters:
attributes - The attribute map to be cached.
userorg - The userorg that is to be associated with the ticket.
Returns:
The SSO ticket that identifies the cached user data.
Throws:
MoriaStoreException - If the operation fails.
java.lang.IllegalArgumentException - If attributes is null, or userorg is null or an empty string.
See Also:
MoriaStore.cacheUserData(java.util.HashMap, String)

getUserData

public CachedUserData getUserData(java.lang.String ticketId,
                                  java.lang.String servicePrincipal)
                           throws NonExistentTicketException,
                                  InvalidTicketException,
                                  MoriaStoreException
Returns the userdata associated with the incoming ticket, which must be either a proxy ticket, an SSO ticket or ticket granting ticket.

Specified by:
getUserData in interface MoriaStore
Parameters:
ticketId - A ticket to identify a userdata object (SSO, TGT or PROXY).
servicePrincipal - The name of the service requesting the data,
Returns:
A clone of the object containing the userdata.
Throws:
InvalidTicketException - If the incoming ticket is not of the correct type or has an invalid principal.
NonExistentTicketException - If ticket does not exist.
MoriaStoreException - If the operation fails.
java.lang.IllegalArgumentException - If ticketId is null or zero length, or SSO ticket principal is null or zero length.
See Also:
MoriaStore.getUserData(java.lang.String, java.lang.String)

createServiceTicket

public java.lang.String createServiceTicket(java.lang.String loginTicketId)
                                     throws InvalidTicketException,
                                            NonExistentTicketException,
                                            MoriaStoreException
Creates a service ticket that the service will use when requesting user attributes after a successful authentication.

Specified by:
createServiceTicket in interface MoriaStore
Parameters:
loginTicketId - A login ticket associated with an authentication attempt.
Returns:
A service ticket associated with the authentication attempt object.
Throws:
InvalidTicketException - If the supplied ticket is not a login ticket.
NonExistentTicketException - If ticket does not exist.
MoriaStoreException - If the operation fails.
java.lang.IllegalArgumentException - If loginTicketId is null or zero length.
See Also:
MoriaStore.createServiceTicket(java.lang.String)

createTicketGrantingTicket

public java.lang.String createTicketGrantingTicket(java.lang.String ssoTicketId,
                                                   java.lang.String targetServicePrincipal)
                                            throws InvalidTicketException,
                                                   NonExistentTicketException,
                                                   MoriaStoreException
Creates a new ticket granting ticket, using an sso ticket.

Specified by:
createTicketGrantingTicket in interface MoriaStore
Parameters:
ssoTicketId - An sso ticket that is already associated with a cached userdata object.
targetServicePrincipal - The id of the service that will use the TGT.
Returns:
A ticket-granting ticket that the requesting service may use for later proxy authentication.
Throws:
InvalidTicketException - If the argument ticket is not an SSO ticket or has an invalid principal.
NonExistentTicketException - If ticket does not exist.
MoriaStoreException - If the operation fails.
java.lang.IllegalArgumentException - If any of the arguments are null or zero length.
See Also:
MoriaStore.createTicketGrantingTicket(java.lang.String, java.lang.String)

createProxyTicket

public java.lang.String createProxyTicket(java.lang.String tgTicketId,
                                          java.lang.String servicePrincipal,
                                          java.lang.String targetServicePrincipal)
                                   throws InvalidTicketException,
                                          NonExistentTicketException,
                                          MoriaStoreException
Creates a new proxy ticket from a TGT and associates the new ticket with the same user data as the TGT.

Specified by:
createProxyTicket in interface MoriaStore
Parameters:
tgTicketId - A TGT issued earlier to a service.
servicePrincipal - The id of the service making the request.
targetServicePrincipal - The id of the service that will use the proxy ticket.
Returns:
Proxy ticket that may be used by the requesting service.
Throws:
InvalidTicketException - If the incoming ticket is not a TGT or has an invalid principal.
NonExistentTicketException - If ticket does not exist.
MoriaStoreException - If the operation fails.
java.lang.IllegalArgumentException - If any of the arguments are null or zero length.
See Also:
MoriaStore.createProxyTicket(java.lang.String, java.lang.String, java.lang.String)

setTransientAttributes

public void setTransientAttributes(java.lang.String loginTicketId,
                                   java.util.HashMap transientAttributes)
                            throws InvalidTicketException,
                                   NonExistentTicketException,
                                   MoriaStoreException
Sets transient attributes stored with authentication attempt in an SSO context, which implies that not all cached (for potential SSO attributes) should be included.

Specified by:
setTransientAttributes in interface MoriaStore
Parameters:
loginTicketId - Ticket that identifies the AuthnAttempt that the attributes will be associated with.
transientAttributes - Attributes which are to be stored with the authentication attempt.
Throws:
InvalidTicketException - If ticket is found invalid.
NonExistentTicketException - If ticket does not exist.
MoriaStoreException - If the operation fails.
java.lang.IllegalArgumentException - If loginTicketId is null or zero length, or transientAttributes is null.
See Also:
MoriaStore.setTransientAttributes(java.lang.String, java.util.HashMap)

setTransientSSOAttributes

public void setTransientSSOAttributes(java.lang.String loginTicketId,
                                      java.lang.String ssoTicketId,
                                      java.lang.String[] ssoEnabledAttributeNames)
                               throws InvalidTicketException,
                                      NonExistentTicketException,
                                      MoriaStoreException
Sets transient attributes stored with authentication attempt, copied from a cached user data object.

Specified by:
setTransientSSOAttributes in interface MoriaStore
Parameters:
loginTicketId - Ticket that identifies the AuthnAttempt that the attributes will be associated with.
ssoTicketId - Ticket associated with a set of cached user data.
ssoEnabledAttributeNames - The names of those attributes which should be stored with the authentication attempt. Only those transient (cached) attributes named in this parameter will be stored.
Throws:
InvalidTicketException - If either ticket is found invalid.
NonExistentTicketException - If either ticket does not exist.
MoriaStoreException - If the operation fails.
java.lang.IllegalArgumentException - If either ticket id is null or zero length.
See Also:
MoriaStore.setTransientSSOAttributes(java.lang.String, java.lang.String, java.lang.String[])

removeSSOTicket

public void removeSSOTicket(java.lang.String ssoTicketId)
                     throws NonExistentTicketException,
                            MoriaStoreException
Removes an SSO ticket from the store.

Specified by:
removeSSOTicket in interface MoriaStore
Parameters:
ssoTicketId - The ID of the ticket to remove.
Throws:
NonExistentTicketException - If ticket given by ssoTicketId does not exist, or is empty.
MoriaStoreException - If the operation fails.
See Also:
MoriaStore.removeSSOTicket(java.lang.String)

getTicketServicePrincipal

public java.lang.String getTicketServicePrincipal(java.lang.String ticketId,
                                                  MoriaTicketType ticketType)
                                           throws InvalidTicketException,
                                                  NonExistentTicketException,
                                                  MoriaStoreException
Returns the service principal for the ticket.

Specified by:
getTicketServicePrincipal in interface MoriaStore
Parameters:
ticketId - The ticket id.
ticketType - The ticket type.
Returns:
Service principal.
Throws:
InvalidTicketException - If the ticket is invalid.
NonExistentTicketException - If ticket does not exist.
MoriaStoreException - If the operation fails.
java.lang.IllegalArgumentException - If ticketId is null or zero length.
See Also:
MoriaTicket.getServicePrincipal()

setTicketUserorg

public void setTicketUserorg(java.lang.String ticketId,
                             MoriaTicketType ticketType,
                             java.lang.String userorg)
                      throws InvalidTicketException,
                             NonExistentTicketException,
                             MoriaStoreException
Sets the userorg of a ticket.

Specified by:
setTicketUserorg in interface MoriaStore
Parameters:
ticketId - The ticket id.
ticketType - The ticket type.
userorg - The userorg of the user creating the ticket.
Throws:
InvalidTicketException - if the ticket is invalid.
NonExistentTicketException - If ticket does not exist.
MoriaStoreException - If the operation fails.
java.lang.IllegalArgumentException - If ticketId is null or zero length.
See Also:
MoriaStore.setTicketUserorg(String, MoriaTicketType, String)

getTicketUserorg

public java.lang.String getTicketUserorg(java.lang.String ticketId,
                                         MoriaTicketType ticketType)
                                  throws InvalidTicketException,
                                         NonExistentTicketException,
                                         MoriaStoreException
Gets the userorg of a ticket.

Specified by:
getTicketUserorg in interface MoriaStore
Parameters:
ticketId - the ticket id.
ticketType - the ticket type.
Returns:
the organization of the user creating the ticket, or null if not set.
Throws:
InvalidTicketException - If the ticket is invalid.
NonExistentTicketException - If ticket does not exist.
MoriaStoreException - If the operation fails.
java.lang.IllegalArgumentException - If ticketId is null or zero length.
See Also:
MoriaStore.getTicketUserorg(String, MoriaTicketType)

validateTicket

private void validateTicket(MoriaTicket ticket,
                            MoriaTicketType ticketType,
                            java.lang.String servicePrincipal)
                     throws InvalidTicketException
Checks validity of ticket against type and expiry time.

Parameters:
ticket - Ticket to be checked.
ticketType - The expected type of the ticket.
servicePrincipal - The service expected to be associated with this ticket.
Throws:
java.lang.IllegalArgumentException - If ticket is null, or ticketType is null or zero length.
InvalidTicketException - If ticket is found invalid.

validateTicket

private void validateTicket(MoriaTicket ticket,
                            MoriaTicketType[] ticketTypes,
                            java.lang.String servicePrincipal)
                     throws InvalidTicketException
Check validity of ticket against a set of types and expiry time.

Parameters:
ticket - Ticket to be checked.
ticketTypes - Array of valid types for the ticket.
servicePrincipal - The service that is using the ticket. May be null if no service is available.
Throws:
java.lang.IllegalArgumentException - If ticket is null, or ticketType is null or zero length.
InvalidTicketException - If the ticket is found to be invalid.

getFromStore

MoriaTicket getFromStore(MoriaTicketType[] ticketTypes,
                         java.lang.String ticketId)
                   throws MoriaStoreException
Retrieves a ticket instance which may be one of a number of types.

Parameters:
ticketTypes - Array of potential ticket types for the ticket id.
ticketId - Id of the ticket to be retrieved.
Returns:
A ticket, or null if none found.
Throws:
java.lang.IllegalArgumentException - If the any of arguments are null value or zero length.
MoriaStoreException - If access to the store failed in some way.

getFromStore

MoriaTicket getFromStore(MoriaTicketType ticketType,
                         java.lang.String ticketId)
                   throws MoriaStoreException
Retrieves a ticket instance from the store.

Parameters:
ticketType - The type of ticket.
ticketId - The ID of the ticket.
Returns:
The ticket, or null if none found.
Throws:
java.lang.IllegalArgumentException - If ticketType is null, or if ticketId is null or an empty string.
MoriaStoreException - If operations on the underlying TreeCache fail; acts as a wrapper.

insertIntoStore

private void insertIntoStore(MoriaTicket ticket)
                      throws MoriaStoreException
Inserts an authentication attempt or cached user data into the cache. Either authnAttempt or cachedUserData must be null.

Parameters:
ticket - The ticket to connect to the inserted object.
Throws:
java.lang.IllegalArgumentException - If ticket is null.
MoriaStoreException - If operations on the TreeCache fail.

removeFromStore

private void removeFromStore(MoriaTicket ticket)
                      throws NonExistentTicketException,
                             MoriaStoreException
Removes a ticket, and possibly a connected userdata or authnAttempt from the cache.

Parameters:
ticket - The ticket to be removed.
Throws:
java.lang.IllegalArgumentException - If ticket is null.
NonExistentTicketException - If the ticket does not exist.
MoriaStoreException - If an exception is thrown when operating on the store.


Copyright © 2001-2006 UNINETT FAS. All Rights Reserved.