3
* Service Provider Example -- AssertionConsumer
5
* Copyright (C) 2004 Entr'ouvert
6
* http://lasso.entrouvert.org
8
* Authors: Christophe Nowicki <cnowicki@easter-eggs.com>
10
* This program is free software; you can redistribute it and/or modify
11
* it under the terms of the GNU General Public License as published by
12
* the Free Software Foundation; either version 2 of the License, or
13
* (at your option) any later version.
15
* This program is distributed in the hope that it will be useful,
16
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
* GNU General Public License for more details.
20
* You should have received a copy of the GNU General Public License
21
* along with this program; if not, write to the Free Software
22
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25
$config = unserialize(file_get_contents('config.inc'));
27
require_once 'DB.php';
30
if (!$_GET['SAMLart']) {
38
$server_dump = file_get_contents($config['server_dump_filename']);
40
$server = LassoServer::newfromdump($server_dump);
42
$login = new LassoLogin($server);
44
$login->initRequest($_SERVER['QUERY_STRING'], lassoHttpMethodRedirect);
45
$login->buildRequestMsg();
47
$url = parse_url($login->msgUrl);
50
"POST %s HTTP/1.1\r\nHost: %s:%d\r\nContent-Length: %d\r\nContent-Type: text/xml\r\n\r\n%s\r\n",
51
$url['path'], $url['host'], $url['port'], strlen($login->msgBody), $login->msgBody);
53
# PHP 4.3.0 with OpenSSL support required
54
$fp = fsockopen("ssl://" . $url['host'], $url['port'], $errno, $errstr, 30) or die($errstr ($errno));
58
if (!preg_match("/^HTTP\/1\\.. 200/i", $ret)) {
59
die("Wrong artifact");
63
$reponse .= @fread($fp, 8192);
68
list($header, $body) = preg_split("/(\r\n\r\n|\n\n)/", $reponse, 2);
70
$login->processResponseMsg($body);
72
$db = &DB::connect($config['dsn']);
75
die($db->getMessage());
77
$query = "SELECT user_id FROM nameidentifiers WHERE name_identifier='" . $login->nameIdentifier . "'";
78
$res =& $db->query($query);
80
if (DB::isError($res))
81
die($res->getMessage());
83
if ($res->numRows() > 0)
85
// User already exist in the database
86
$row =& $res->fetchRow();
89
# Get Identity Dump from the data base
90
$query = "SELECT identity_dump FROM users WHERE user_id='$user_id'";
91
$res =& $db->query($query);
94
die($db->getMessage());
96
$row =& $res->fetchRow();
98
$login->setIdentityFromDump($row[0]);
104
$session = $login->session;
106
$_SESSION["nameidentifier"] = $login->nameIdentifier;
107
$_SESSION["session_dump"] = $session->dump();
108
$_SESSION["user_id"] = $user_id;
110
$url = "index.php?SID=". $SID;
117
$identity = $login->identity;
118
$identity_dump = $identity->dump();
120
$session = $login->session;
123
$identity_dump_quoted = $db->quoteSmart($identity_dump);
124
$query = "INSERT INTO users (user_id,identity_dump,created) VALUES(nextval('user_id_seq'), $identity_dump_quoted, NOW())";
125
$res =& $db->query($query);
126
if (DB::isError($res))
127
print $res->getMessage(). "\n";
130
$query = "SELECT last_value FROM user_id_seq";
131
$res =& $db->query($query);
132
if (DB::isError($res))
133
print $res->getMessage(). "\n";
134
$row = $res->fetchRow();
137
// Insert into nameidentifiers
138
$query = "INSERT INTO nameidentifiers VALUES('".$login->nameIdentifier."', '$user_id')";
139
$res =& $db->query($query);
140
if (DB::isError($res))
141
print $res->getMessage(). "\n";
144
$_SESSION["nameidentifier"] = $login->nameIdentifier;
145
$_SESSION["session_dump"] = $session->dump();
146
$_SESSION["user_id"] = $user_id;
148
$url = "register.php?SID=". $SID;
152
$query = "UPDATE users SET last_login=NOW() WHERE user_id='$user_id'";
153
$res =& $db->query($query);
154
if (DB::isError($res))
155
print $res->getMessage(). "\n";
161
header("Request-URI: $url");
162
header("Content-Location: $url");
163
header("Location: $url");