Revision: 2269
Author: olavmrk
Date: Mon Apr 26 01:59:58 2010
Log: Add PersistentAuthData option to save a subset of the state array in the session.
http://code.google.com/p/simplesamlphp/source/detail?r=2269

Modified:
 /trunk/lib/SimpleSAML/Auth/Default.php
 /trunk/lib/SimpleSAML/IdP.php
 /trunk/lib/SimpleSAML/Session.php

=======================================
--- /trunk/lib/SimpleSAML/Auth/Default.php      Fri Apr 16 00:05:31 2010
+++ /trunk/lib/SimpleSAML/Auth/Default.php      Mon Apr 26 01:59:58 2010
@@ -64,6 +64,28 @@
                }
                self::loginCompleted($state);
        }
+
+
+       /**
+        * Extract the persistent authentication state from the state array.
+        *
+        * @param array $state  The state after the login.
+        * @return array  The persistent authentication state.
+        */
+       private static function extractPersistentAuthState(array &$state) {
+
+               /* Save persistent authentication data. */
+               $persistentAuthState = array();
+               if (isset($state['PersistentAuthData'])) {
+                       foreach ($state['PersistentAuthData'] as $key) {
+                               if (isset($state[$key])) {
+                                       $persistentAuthState[$key] = 
$state[$key];
+                               }
+                       }
+               }
+
+               return $persistentAuthState;
+       }


        /**
@@ -82,7 +104,7 @@

                /* Save session state. */
                $session = SimpleSAML_Session::getInstance();
-               $session->doLogin($state['SimpleSAML_Auth_Default.id']);
+ $session->doLogin($state['SimpleSAML_Auth_Default.id'], self::extractPersistentAuthState($state));
                $session->setAttributes($state['Attributes']);
                if(array_key_exists('Expires', $state)) {
                        $session->setSessionDuration($state['Expires'] - 
time());
@@ -217,7 +239,7 @@
                assert('is_string($redirectTo)');

                $session = SimpleSAML_Session::getInstance();
-               $session->doLogin($authId);
+               $session->doLogin($authId, 
self::extractPersistentAuthState($state));

                if (array_key_exists('Attributes', $state)) {
                        $session->setAttributes($state['Attributes']);
=======================================
--- /trunk/lib/SimpleSAML/IdP.php       Wed Feb 24 06:40:44 2010
+++ /trunk/lib/SimpleSAML/IdP.php       Mon Apr 26 01:59:58 2010
@@ -400,6 +400,11 @@
                        if ($needAuth) {
                                $this->authenticate($state);
                                assert('FALSE');
+                       } else {
+                               $session = SimpleSAML_Session::getInstance();
+                               foreach ($session->getAuthState() as $k => $v) {
+                                       $state[$k] = $v;
+                               }
                        }
                        $this->postAuth($state);
                } catch (SimpleSAML_Error_Exception $e) {
=======================================
--- /trunk/lib/SimpleSAML/Session.php   Wed Feb 24 01:52:55 2010
+++ /trunk/lib/SimpleSAML/Session.php   Mon Apr 26 01:59:58 2010
@@ -85,6 +85,14 @@
        private $logoutState;


+       /**
+        * Persistent authentication state.
+        *
+        * @array
+        */
+       private $authState;
+
+
        /**
         * The list of IdP-SP associations.
         *
@@ -354,9 +362,10 @@
         *
         * If the user already has logged in, the user will be logged out first.
         *
-        * @param @authority  The authority the user logged in with.
+        * @param string $authority  The authority the user logged in with.
+ * @param array|NULL $authState The persistent auth state for this authority.
         */
-       public function doLogin($authority) {
+       public function doLogin($authority, array $authState = NULL) {
                assert('is_string($authority)');

                SimpleSAML_Logger::debug('Session: doLogin("' . $authority . 
'")');
@@ -370,6 +379,7 @@

                $this->authenticated = TRUE;
                $this->authority = $authority;
+               $this->authState = $authState;

                $this->sessionstarted = time();

@@ -395,6 +405,7 @@
                $this->authority = NULL;
                $this->attributes = NULL;
                $this->logoutState = NULL;
+               $this->authState = NULL;
                $this->idp = NULL;

                /* Delete data which expires on logout. */
@@ -903,6 +914,25 @@

                return $this->logoutState;
        }
+
+
+       /**
+        * Get the current persistent authentication state.
+        *
+ * @return array The current persistent authentication state, or NULL if not authenticated.
+        */
+       public function getAuthState() {
+               if (!$this->isAuthenticated()) {
+                       return NULL;
+               }
+
+               if (!isset($this->authState)) {
+                       /* No AuthState for this login handler. */
+                       return array();
+               }
+
+               return $this->authState;
+       }


        /**

--
You received this message because you are subscribed to the Google Groups 
"simpleSAMLphp commits" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/simplesamlphp-commits?hl=en.

Reply via email to