3 /*-------------------------------------------------------------------------------------
5 * Filename : Authentication.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 require_once(dirname(__FILE__)."/Authentication_Delegated.php");
35 * Top-level authentication class that integrates multiple authentication
36 * procedures. (session or delegated WebID)
38 * @modified Andrei Sambra
40 class Authentication {
42 * After succesful authentication contains the webid
46 public $isAuthenticated = 0;
47 public $authnDiagnostic = NULL;
48 private $session = NULL;
50 const STATUS_AUTH_VIA_SESSION = "Authenticated via a session";
52 public function __construct($ARCConfig, $sig = NULL)
54 // Authenticate via session and return
55 $this->session = new Authentication_Session();
56 if ($this->session->isAuthenticated) {
57 $this->webid = $this->session->webid;
58 $this->isAuthenticated = $this->session->isAuthenticated;
59 $this->authnDiagnostic = self::STATUS_AUTH_VIA_SESSION;
63 // Authenticate via delegated login
64 $sig = isset($sig)?$sig:$_GET["sig"];
67 $authDelegate = new Authentication_Delegated(FALSE);
69 $this->webid = $authDelegate->webid;
70 $this->isAuthenticated = $authDelegate->isAuthenticated;
71 $this->authnDiagnostic = $authDelegate->authnDiagnostic;
74 if ($this->isAuthenticated)
76 $this->session->setAuthenticatedWebid($this->webid);
80 $this->session->unsetAuthenticatedWebid();
86 * Is the current user authenticated?
89 public function isAuthenticated()
91 return $this->isAuthenticated;
95 * Leave the authenticated session
97 public function logout()
99 $this->isAuthenticated = 0;
100 $this->session->unsetAuthenticatedWebid();