3 /*-------------------------------------------------------------------------------------
5 * Filename : Authentication_Session.php
6 * Date : 11th July 2012
8 * Copyright (C) 2012 Melvin Carvalho, Akbar Hossain, László Török
10 * Permission is hereby granted, free of charge, to any person obtaining a copy
11 * of this software and associated documentation files (the "Software"), to deal
12 * in the Software without restriction, including without limitation the rights
13 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14 * copies of the Software, and to permit persons to whom the Software is furnished
15 * to do so, subject to the following conditions:
17 * The above copyright notice and this permission notice shall be included in all
18 * copies or substantial portions of the Software.
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
21 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
22 * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
23 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
24 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 * Everything should be made as simple as possible, but no simpler."
30 //-------------------------------------------------------------------------------------
32 * Persist authentication information in the session storage
34 * @author Akbar Hossain
35 * @modified Andrei Sambra
37 class Authentication_Session
41 public $isAuthenticated = 0;
43 private $authnSession = NULL;
45 const IS_AUTHENTICATED = 'Authentication_isAuthenticated';
46 const WEBID = 'Authentication_webid';
49 * Created authenticated session
50 * @param int $isAuthenticated
51 * @param string $webid
53 public function __construct($isAuthenticated = 0, $webid = NULL)
55 $this->authnSession = session_name();
57 if (isset($this->authnSession))
59 $this->isAuthenticated = isset($_SESSION[self::IS_AUTHENTICATED]) ?
60 $_SESSION[self::IS_AUTHENTICATED]:$isAuthenticated;
62 $this->webid = isset($_SESSION[self::WEBID]) ?
63 $_SESSION[self::WEBID]:$webid;
68 * Set an authenticated webid
71 public function setAuthenticatedWebid($webid)
73 if ( ! is_null($webid))
75 $_SESSION[self::IS_AUTHENTICATED] = 1;
76 $_SESSION[self::WEBID] = $webid;
78 $this->isAuthenticated = 1;
79 $this->webid = $webid;
84 * Unset authenticated webid for current session
86 public function unsetAuthenticatedWebid()
88 $_SESSION[self::IS_AUTHENTICATED] = 0;
89 $_SESSION[self::WEBID] = NULL;
91 $this->isAuthenticated = 0;