Merge session cache implementations.
[shibboleth/cpp-sp.git] / shibsp / SessionCache.h
index 9e2d453..bb32ae7 100644 (file)
@@ -51,6 +51,27 @@ namespace shibsp {
         virtual const char* getID() const=0;
 
         /**
+         * Returns the session's application ID.
+         *
+         * @return unique ID of application bound to session
+         */
+        virtual const char* getApplicationID() const=0;
+
+        /**
+         * Returns the session expiration.
+         *
+         * @return  the session's expiration time or 0 for none
+         */
+        virtual time_t getExpiration() const=0;
+
+        /**
+         * Returns the last access time of the session.
+         *
+         * @return  the session's last access time
+         */
+        virtual time_t getLastAccess() const=0;
+
+        /**
          * Returns the address of the client associated with the session.
          * 
          * @return  the client's network address
@@ -115,9 +136,16 @@ namespace shibsp {
         /**
          * Returns the resolved attributes associated with the session.
          * 
+         * @return an immutable array of attributes
+         */
+        virtual const std::vector<Attribute*>& getAttributes() const=0;
+
+        /**
+         * Returns the resolved attributes associated with the session, indexed by ID
+         * 
          * @return an immutable map of attributes keyed by attribute ID
          */
-        virtual const std::multimap<std::string,Attribute*>& getAttributes() const=0;
+        virtual const std::multimap<std::string,const Attribute*>& getIndexedAttributes() const=0;
         
         /**
          * Returns the identifiers of the assertion(s) cached by the session.
@@ -166,23 +194,7 @@ namespace shibsp {
     {
         MAKE_NONCOPYABLE(SessionCache);
     protected:
-    
-        /**
-         * Constructor
-         * 
-         * <p>The following XML content is supported to configure the cache:
-         * <dl>
-         *  <dt>cacheTimeout</dt>
-         *  <dd>attribute containing maximum lifetime in seconds for unused sessions to remain in cache</dd>
-         * </dl>
-         * 
-         * @param e root of DOM tree to configure the cache
-         */
-        SessionCache(const xercesc::DOMElement* e);
-        
-        /** maximum lifetime in seconds for unused sessions to be cached */
-        unsigned long m_cacheTimeout;
-        
+        SessionCache() {}
     public:
         virtual ~SessionCache() {}
         
@@ -203,7 +215,7 @@ namespace shibsp {
          * @param authncontext_class    method/category of authentication event, if known
          * @param authncontext_decl specifics of authentication event, if known
          * @param tokens            assertions to cache with session, if any
-         * @param attributes        optional map of resolved Attributes to cache with session
+         * @param attributes        optional array of resolved Attributes to cache with session
          * @return  newly created session's key
          */
         virtual std::string insert(
@@ -218,25 +230,58 @@ namespace shibsp {
             const XMLCh* authncontext_class=NULL,
             const XMLCh* authncontext_decl=NULL,
             const std::vector<const opensaml::Assertion*>* tokens=NULL,
-            const std::multimap<std::string,Attribute*>* attributes=NULL
+            const std::vector<Attribute*>* attributes=NULL
             )=0;
 
         /**
-         * Deletes an existing session or sessions.
+         * Returns active sessions that match particular parameters and records the logout
+         * to prevent race conditions.
+         *
+         * <p>On exit, the mapping between these sessions and the associated information MAY be
+         * removed by the cache, so subsequent calls to this method may not return anything.
+         *
+         * <p>Until logout expiration, any attempt to create a session with the same parameters
+         * will be blocked by the cache.
          * 
          * @param issuer        source of session(s)
          * @param nameid        name identifier associated with the session(s) to terminate
-         * @param index         index of session, or NULL for all sessions associated with other parameters
+         * @param indexes       indexes of sessions, or NULL for all sessions associated with other parameters
+         * @param expires       logout expiration
          * @param application   reference to Application that owns the session(s)
-         * @param sessions      on exit, contains the IDs of the matching sessions removed
+         * @param sessions      on exit, contains the IDs of the matching sessions found
          */
-        virtual void remove(
+        virtual std::vector<std::string>::size_type logout(
             const opensaml::saml2md::EntityDescriptor* issuer,
             const opensaml::saml2::NameID& nameid,
-            const char* index,
+            const std::set<std::string>* indexes,
+            time_t expires,
             const Application& application,
             std::vector<std::string>& sessions
             )=0;
+
+        /**
+         * Determines whether a given session (based on its ID) matches a set of input
+         * criteria.
+         * 
+         * @param key           session key to check
+         * @param issuer        required source of session(s)
+         * @param nameid        required name identifier
+         * @param indexes       session indexes
+         * @param application   reference to Application that owns the Session
+         * @return  true iff the session matches the input criteria
+         */
+        virtual bool matches(
+            const char* key,
+            const opensaml::saml2md::EntityDescriptor* issuer,
+            const opensaml::saml2::NameID& nameid,
+            const std::set<std::string>* indexes,
+            const Application& application
+            )=0;
+
+        /**
+         * Executes a test of the cache's general health.
+         */
+        virtual void test()=0;
 #endif
 
         /**
@@ -264,13 +309,8 @@ namespace shibsp {
         virtual void remove(const char* key, const Application& application)=0;
     };
 
-#ifndef SHIBSP_LITE
     /** SessionCache implementation backed by a StorageService. */
     #define STORAGESERVICE_SESSION_CACHE    "StorageService"
-#endif
-
-    /** SessionCache implementation for lite builds that delegates to a remoted version. */
-    #define REMOTED_SESSION_CACHE    "Remoted"
 
     /**
      * Registers SessionCache classes into the runtime.