From 1db82e571dd29835ee669472de1a646314e12aa9 Mon Sep 17 00:00:00 2001 From: Christophe Nowicki Date: Fri, 17 Sep 2004 16:02:24 +0000 Subject: log viewer for the Service Provider and the Identity Provider added logger for in many files updated idp1 metadata, added .php extension added session viewer for the sp (you will be able to view online users) --- php/Attic/examples/sample-idp/admin_user.php | 23 +-- php/Attic/examples/sample-idp/index.php | 24 ++-- php/Attic/examples/sample-idp/log_view.php | 96 ++++++++++--- php/Attic/examples/sample-idp/login.php | 17 +-- php/Attic/examples/sample-idp/setup.php | 27 +++- php/Attic/examples/sample-idp/singleSignOn.php | 116 +++++++++------ php/Attic/examples/sample-idp/soapEndpoint.php | 14 +- php/Attic/examples/sample-idp/user_add.php | 4 +- php/Attic/examples/sample-sp/assertionConsumer.php | 111 +++++++++----- php/Attic/examples/sample-sp/index.php | 58 ++++---- php/Attic/examples/sample-sp/log_view.php | 160 +++++++++++++++++++++ php/Attic/examples/sample-sp/login.php | 40 ++++-- php/Attic/examples/sample-sp/logout.php | 1 - php/Attic/examples/sample-sp/metadata_idp1.xml | 8 +- php/Attic/examples/sample-sp/setup.php | 58 +++++++- php/Attic/examples/sample-sp/view_session.php | 88 ++++++++++++ 16 files changed, 652 insertions(+), 193 deletions(-) create mode 100644 php/Attic/examples/sample-sp/log_view.php create mode 100644 php/Attic/examples/sample-sp/view_session.php (limited to 'php') diff --git a/php/Attic/examples/sample-idp/admin_user.php b/php/Attic/examples/sample-idp/admin_user.php index ca5f14ba..0f0c31c3 100644 --- a/php/Attic/examples/sample-idp/admin_user.php +++ b/php/Attic/examples/sample-idp/admin_user.php @@ -81,7 +81,8 @@ $res =& $db->query($query); if (DB::isError($res)) die($res->getMessage()); - + + $logger->log("Delete User '".$_GET['del']."'", PEAR_LOG_NOTICE); } lasso_init(); @@ -164,21 +165,21 @@ if ((($count - $startUser) > $number_of_users) && !isset($_GET['show_all'])) echo "Next"; else - echo "Next" - ?> - Paginate"; + else + { for ($i = 0; $i < $count; $i += $number_of_users) if ($i == $startUser) echo "| " . ( $i / $number_of_users); else echo "| " . ( $i / $number_of_users) . ""; + if ($count > $number_of_users) + echo "| Show All"; + } ?> - | - - ">Paginate - - ">Show All - | Toggle All add user @@ -237,7 +238,7 @@ - + Lasso at
$config = unserialize(file_get_contents('config.inc')); - require_once 'DB.php'; + // connect to the data base + $db = &DB::connect($config['dsn']); + if (DB::isError($db)) + die($db->getMessage()); session_start(); lasso_init(); ?> - + Lasso Service Provider Example @@ -64,15 +70,16 @@ You can get more informations about Lasso at
-

+

Identity Provider Administration
Setup
- Users Management + Users Management
+ View Online Users
View log

-

+

Identity Provider Fonctionnality
Lasso at

-

- +

+

Lasso at
Status

-

Copyright © 2004 Entr'ouvert

+

Copyright © 2004 Entr'ouvert

disconnect(); lasso_shutdown(); ?> diff --git a/php/Attic/examples/sample-idp/log_view.php b/php/Attic/examples/sample-idp/log_view.php index fb68fbdc..68acc458 100644 --- a/php/Attic/examples/sample-idp/log_view.php +++ b/php/Attic/examples/sample-idp/log_view.php @@ -37,16 +37,27 @@ $number_of_msg = 8; + // Count log messages + $query = "SELECT COUNT(*) FROM log"; + $res =& $db->query($query); + if (DB::isError($res)) + die($res->getMessage()); + + $row = $res->fetchRow(); + $count = $row[0]; + $startMsg = ((empty($_GET['startMsg'])) ? 0 : $_GET['startMsg']); - $query = "SELECT * FROM log"; + $query = "SELECT * FROM log ORDER BY id DESC"; if (!isset($_GET['show_all'])) $query .= " OFFSET $startMsg LIMIT " . ($startMsg + $number_of_msg); - + + $res =& $db->query($query); - if (DB::isError($db)) - die($db->getMessage()); + if (DB::isError($res)) + die($res->getMessage()); + $numRows = $res->numRows(); ?> - View Logs + Lasso Identity Provider Example : View Logs
+ + + @@ -70,38 +111,49 @@ numCols(); - $tableinfo = $db->tableInfo($res); + if ($numRows) + { + $num_col = $res->numCols(); + $tableinfo = $db->tableInfo($res); - $desc = array("emergency", "alert", "critical", "error", "warning", "notice", "informational", "debug"); + $desc = array("emergency", "alert", "critical", "error", "warning", "notice", "informational", "debug"); - while($row = $res->fetchRow()) - { - echo ""; - for ($i = 0; $i < $num_col; $i++) + while($row = $res->fetchRow()) { - switch ($tableinfo[$i]['name']) + echo ""; + for ($i = 0; $i < $num_col; $i++) { - case "id": - break; - case "priority": - echo ""; - break; - default: - echo ""; + switch ($tableinfo[$i]['name']) + { + case "id": + break; + case "priority": + echo ""; + break; + case "message": + echo ""; + break; + default: + echo ""; + } } + echo ""; } - echo ""; } ?> - + + +
Logged events
+ Previous"; + else + echo "Previous" + ?> + | + $number_of_users) && !isset($_GET['show_all'])) + echo "Next"; + else + echo "Next"; + + if (isset($_GET['show_all'])) + echo "| Paginate"; + else + { + for ($i = 0; $i < $count; $i += $number_of_msg) + if ($i == $startMsg) + echo "| " . ( $i / $number_of_msg); + else + echo "| " . ( $i / $number_of_msg) . ""; + if ($count > $number_of_msg) + echo "| Show All"; + } + ?> +
date filename
" . $desc[$row[$i]] . "" . $row[$i] . "" . $desc[$row[$i]] . "" . $row[$i] . "" . $row[$i] . "
 
 

+

Index +

+

Copyright © 2004 Entr'ouvert

diff --git a/php/Attic/examples/sample-idp/login.php b/php/Attic/examples/sample-idp/login.php index 21b196f9..db24681e 100644 --- a/php/Attic/examples/sample-idp/login.php +++ b/php/Attic/examples/sample-idp/login.php @@ -37,6 +37,8 @@ $conf['db'] = $db; $logger = &Log::factory($config['log_handler'], 'log', $_SERVER['PHP_SELF'], $conf); + session_start(); + /* * */ @@ -67,7 +69,7 @@ $logger->log("DB Error :" . $db->getMessage(), PEAR_LOG_CRIT); $logger->log("DB Error :" . $db->getDebugInfo(), PEAR_LOG_DEBUG); die("Internal Server Error"); - } + } send by if ($res->numRows()) { @@ -90,17 +92,17 @@ // Check Login and Password if (!($user_id = authentificateUser($db, $_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']))) { - $logger->log("Authentication failure with login '".$form->exportValue('username')." password '". $form->exportValue('password') ."' IP '" . $_SERVER['REMOTE_ADDR']."'", PEAR_LOG_WARNING); + $logger->log("Authentication failure with login '".$form->exportValue('username')." password '". $form->exportValue('password') ."' IP " . $_SERVER['REMOTE_ADDR'], PEAR_LOG_WARNING); sendHTTPBasicAuth(); $db->disconnect(); exit; } else { - $_SESSION['user_id'] = $user_id; - $_SESSION['username'] = $_SERVER['PHP_AUTH_USER']; - - $logger->log("User '".$_SERVER['PHP_AUTH_USER']."'($user_id) authenticated, local session started", PEAR_LOG_NOTICE); + $_SESSION['user_id'] = $user_id; + $_SESSION['username'] = $_SERVER['PHP_AUTH_USER']; + + $logger->log("User '".$_SERVER['PHP_AUTH_USER']."' ($user_id) authenticated, local session started", PEAR_LOG_NOTICE); /* TODO : load identity and session dump @@ -148,11 +150,10 @@ { if (($user_id = authentificateUser($db, $form->exportValue('username'), $form->exportValue('password')))) { - session_start(); $_SESSION['user_id'] = $user_id; $_SESSION['username'] = $form->exportValue('username'); - $logger->log("User '".$form->exportValue('username')."'($user_id) authenticated, local session started", PEAR_LOG_NOTICE); + $logger->log("User '".$form->exportValue('username')."'($user_id) authenticated, local session started", PEAR_LOG_NOTICE); $url = 'index.php'; header("Request-URI: $url"); diff --git a/php/Attic/examples/sample-idp/setup.php b/php/Attic/examples/sample-idp/setup.php index d71de39f..eaa9fa88 100644 --- a/php/Attic/examples/sample-idp/setup.php +++ b/php/Attic/examples/sample-idp/setup.php @@ -211,10 +211,11 @@ $query = "CREATE TABLE users ( user_id varchar(100) primary key, - username varchar(255) unique, - password varchar(255), + username varchar(255) unique, + password varchar(255), identity_dump text, - session_dump text)"; + session_dump text, + created timestamp)"; $res =& $db->query($query); if (DB::isError($res)) die($res->getMessage()); @@ -279,6 +280,22 @@ die($res->getMessage()); print "OK"; + + print "
Create table 'sessions' : "; + $query = "DROP TABLE sessions CASCADE"; + $res =& $db->query($query); + + $query = "CREATE TABLE sessions ( + id varchar(32) primary key, + expiry integer, + data text + )"; + + $res =& $db->query($query); + if (DB::isError($res)) + die($res->getMessage()); + + print "OK"; $db->disconnect(); @@ -323,9 +340,7 @@ $config['idp-ca'], lassoSignatureMethodRsaSha1); if (empty($server)) - { die("Failed"); - } else print "OK"; @@ -368,7 +383,7 @@ $setup = TRUE; } $setup_log = ob_get_contents(); - ob_end_clean(); + ob_end_clean(); ?> diff --git a/php/Attic/examples/sample-idp/singleSignOn.php b/php/Attic/examples/sample-idp/singleSignOn.php index 9623e32c..96dc50b2 100644 --- a/php/Attic/examples/sample-idp/singleSignOn.php +++ b/php/Attic/examples/sample-idp/singleSignOn.php @@ -56,32 +56,37 @@ } else { - $login = new LassoLogin($server); - - // init login - updateDumpsFromSession($login); - initFromAuthnRequest($login); - - - - // User must *NOT* Authenticate with the IdP - if (!$login->mustAuthenticate()) - { - $user_id = authentificateUser($db, $_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']); - if (!$user_id) - die("Unknown User"); + $login = new LassoLogin($server); + + // init login + updateDumpsFromSession($login); + initFromAuthnRequest($login); + + + // User must *NOT* Authenticate with the IdP + if (!$login->mustAuthenticate()) + { + $user_id = authentificateUser($db, $_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']); + if (!$user_id) + { + $logger->log("User must not authenticate, username and password are not available", PEAR_LOG_CRIT); + die("Unknown User"); + } - $array = getIdentityDumpAndSessionDumpFromUserID($db, $user_id); - if (empty($array)) - die("Could not get Identity and Session Dump"); - - $login->setIdentityFromDump($array['identity_dump']); - $login->setSessionFromDump($array['session_dump']); + $array = getIdentityDumpAndSessionDumpFromUserID($db, $user_id); + if (empty($array)) + { + $logger->log("User must no authenticate, but I don't find session and identity dump in the database", PEAR_LOG_CRIT); + die("Could not get Identity and Session Dump"); + } + + $login->setIdentityFromDump($array['identity_dump']); + $login->setSessionFromDump($array['session_dump']); - doneSingleSignOn($db, $login, $user_id); - $db->disconnect(); - exit; - } + doneSingleSignOn($db, $login, $user_id); + $db->disconnect(); + exit; + } // Check Login and Password if (!($user_id = authentificateUser($db, $_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']))) @@ -206,12 +211,20 @@ */ function updateDumpsFromSession(&$login) { + global $logger; + // Get session and identity dump if there are available if (!empty($_SESSION['session_dump'])) + { + $logger->log("Update user's session dump", PEAR_LOG_DEBUG); $login->setSessionFromDump($_SESSION['session_dump']); + } if (!empty($_SESSION['identity_dump'])) + { + $logger->log("Update user's identity dump", PEAR_LOG_DEBUG); $login->setIdentityFromDump($_SESSION['identity_dump']); + } } /* @@ -237,12 +250,18 @@ */ function authentificateUser($db, $username, $password) { + global $logger; + $query = "SELECT user_id FROM users WHERE username=".$db->quoteSmart($username); $query .= " AND password=".$db->quoteSmart($password); $res =& $db->query($query); if (DB::isError($res)) + { + $logger->log("DB Error :" . $db->getMessage(), PEAR_LOG_CRIT); + $logger->log("DB Error :" . $db->getDebugInfo(), PEAR_LOG_DEBUG); die($res->getMessage()); + } if ($res->numRows()) { @@ -259,11 +278,15 @@ function getUserIDFromNameIdentifier($db, $nameidentifier) { $query = "SELECT user_id FROM nameidentifiers WHERE name_identifier='$nameidentifier'"; - echo $query; + // echo $query; $res =& $db->query($query); - if (DB::isError($res)) - die($res->getMessage()); + if (DB::isError($res)) + { + $logger->log("DB Error :" . $db->getMessage(), PEAR_LOG_CRIT); + $logger->log("DB Error :" . $db->getDebugInfo(), PEAR_LOG_DEBUG); + die($res->getMessage()); + } // UserID not found if (!$res->numRows()) @@ -289,8 +312,8 @@ if ($res->numRows()) { $row =& $res->fetchRow(); - $ret = array("identity_dump" => $row[0], "session_dump" => $row[1]); - return ($ret); + $ret = array("identity_dump" => $row[0], "session_dump" => $row[1]); + return ($ret); } } @@ -300,32 +323,24 @@ */ function doneSingleSignOn($db, &$login, $user_id, $is_first_sso = FALSE) { + global $logger; + $authenticationMethod = (($_SERVER["HTTPS"] == 'on') ? lassoSamlAuthenticationMethodSecureRemotePassword : lassoSamlAuthenticationMethodPassword); // reauth in session_cache_expire, default is 180 minutes $reauthenticateOnOrAfter = strftime("%Y-%m-%dT%H:%M:%SZ", time() + session_cache_expire() * 60); - /* FIXME : there is a segfault when I use a switch statement - switch($login->protocolProfile) - { - case lassoLoginProtocolProfileBrwsArt: - $login->buildArtifactMsg(TRUE, // User is authenticated - $authenticationMethod, $reauthenticateOnOrAfter, lassoHttpMethodRedirect); - break; - case lassoLoginProtocolProfileBrwsPost: - die("TODO : Post\n"); - default: - die("Unknown protocol profile\n"); - } */ - if ($login->protocolProfile == lassoLoginProtocolProfileBrwsArt) $login->buildArtifactMsg(TRUE, // User is authenticated $authenticationMethod, $reauthenticateOnOrAfter, lassoHttpMethodRedirect); else if ($login->protocolProfile == lassoLoginProtocolProfileBrwsPost) die("TODO : Post\n"); // TODO else - die("Unknown protocol profile\n"); + { + $logger->log("Unknown protocol profile", PEAR_LOG_CRIT); + die("Unknown protocol profile\n"); + } if ($is_first_sso) { @@ -335,23 +350,30 @@ $res =& $db->query($query); if (DB::isError($res)) - die($res->getMessage()); + { + $logger->log("DB Error :" . $db->getMessage(), PEAR_LOG_CRIT); + $logger->log("DB Error :" . $db->getDebugInfo(), PEAR_LOG_DEBUG); + die($res->getMessage()); + } } $identity = $login->identity; // do we need to update identity dump? if ($login->isIdentityDirty) - updateIdentityDump($db, $user_id, $identity->dump()); + updateIdentityDump($db, $user_id, $identity->dump()); $session = $login->session; // do we need to update session dump? if ($login->isSessionDirty) - updateSessionDump($db, $user_id, $session->dump()); + updateSessionDump($db, $user_id, $session->dump()); if (empty($login->assertionArtifact)) + { + $logger->log("Assertion Artifact is empty", PEAR_LOG_CRIT); die("assertion Artifact is empty"); + } - saveAssertionArtifact($db, $login->assertionArtifact, $login->assertion); + saveAssertionArtifact($db, $login->assertionArtifact, $login->assertion); unset($_SESSION['login_dump']); // delete login_dump $_SESSION['identity_dump'] = $session->dump(); diff --git a/php/Attic/examples/sample-idp/soapEndpoint.php b/php/Attic/examples/sample-idp/soapEndpoint.php index 887a5063..9172e9fd 100644 --- a/php/Attic/examples/sample-idp/soapEndpoint.php +++ b/php/Attic/examples/sample-idp/soapEndpoint.php @@ -1,6 +1,5 @@ validate()) { - $query = "INSERT INTO users (user_id, username, password) VALUES(nextval('user_id_seq'),"; + $query = "INSERT INTO users (user_id, username, password, created) VALUES(nextval('user_id_seq'),"; $query .= $db->quoteSmart($form->exportValue('username')) . ","; - $query .= $db->quoteSmart($form->exportValue('password')) . ")"; + $query .= $db->quoteSmart($form->exportValue('password')) . ", NOW())"; $res =& $db->query($query); if (DB::isError($res)) diff --git a/php/Attic/examples/sample-sp/assertionConsumer.php b/php/Attic/examples/sample-sp/assertionConsumer.php index 7ae2c7a8..85d67556 100644 --- a/php/Attic/examples/sample-sp/assertionConsumer.php +++ b/php/Attic/examples/sample-sp/assertionConsumer.php @@ -22,24 +22,36 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ - $config = unserialize(file_get_contents('config.inc')); - + require_once 'Log.php'; require_once 'DB.php'; + + $config = unserialize(file_get_contents('config.inc')); + if (!$_GET['SAMLart']) { exit(1); } - + + $db = &DB::connect($config['dsn']); + + if (DB::isError($db)) + die($db->getMessage()); + + // create logger + $conf['db'] = $db; + $logger = &Log::factory($config['log_handler'], 'log', $_SERVER['PHP_SELF'], $conf); + session_start(); lasso_init(); $server_dump = file_get_contents($config['server_dump_filename']); - $server = LassoServer::newfromdump($server_dump); + $server = LassoServer::newFromDump($server_dump); $login = new LassoLogin($server); + $logger->log('Request from ' . $_SERVER['REMOTE_ADDR'], PEAR_LOG_INFO); $login->initRequest($_SERVER['QUERY_STRING'], lassoHttpMethodRedirect); $login->buildRequestMsg(); @@ -49,6 +61,9 @@ "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", $url['path'], $url['host'], $url['port'], strlen($login->msgBody), $login->msgBody); + $logger->log('Send SOAP Request to '. $url['host'] . ":" .$url['port']. $url['path'], PEAR_LOG_INFO); + $logger->log('SOAP Request : ' . $soap, PEAR_LOG_DEBUG); + # PHP 4.3.0 with OpenSSL support required $fp = fsockopen("ssl://" . $url['host'], $url['port'], $errno, $errstr, 30) or die($errstr ($errno)); socket_set_timeout($fp, 10); @@ -78,41 +93,50 @@ else { if (preg_match('/Content\\-Length:\\s+([0-9]+)\\r\\n/', $header, $matches)) - $response = fread($fp, $matches[1]); + $response = @fread($fp, $matches[1]); else while (!feof($fp)) $response .= fread($fp, 1024); } fclose($fp); + $logger->log('SOAP Response Header : ' . $header, PEAR_LOG_DEBUG); + $logger->log('SOAP Response Body : ' . $response, PEAR_LOG_DEBUG); + if (!preg_match("/^HTTP\/1\\.. 200/i", $header)) { - die("Wrong artifact"); + $logger->log("Wrong Artifact send by " . $_SERVER['REMOTE_ADDR'], PEAR_LOG_ERR); + die("Wrong Artifact"); } $login->processResponseMsg($response); - - $db = &DB::connect($config['dsn']); - - if (DB::isError($db)) - die($db->getMessage()); - + $query = "SELECT user_id FROM nameidentifiers WHERE name_identifier='" . $login->nameIdentifier . "'"; $res =& $db->query($query); + $logger->log("Name Identifier : " . $login->nameIdentifier, PEAR_LOG_DEBUG); + if (DB::isError($res)) - die($res->getMessage()); + { + $logger->log("DB Error :" . $db->getMessage(), PEAR_LOG_CRIT); + $logger->log("DB Error :" . $db->getDebugInfo(), PEAR_LOG_DEBUG); + die($db->getMessage()); + } if ($res->numRows() > 0) { // User already exist in the database $row =& $res->fetchRow(); - $user_id = $row[0]; + $user_id = $row[0]; # Get Identity Dump from the data base $query = "SELECT identity_dump FROM users WHERE user_id='$user_id'"; $res =& $db->query($query); if (DB::isError($db)) - die($db->getMessage()); + { + $logger->log("DB Error :" . $db->getMessage(), PEAR_LOG_CRIT); + $logger->log("DB Error :" . $db->getDebugInfo(), PEAR_LOG_DEBUG); + die($db->getMessage()); + } $row =& $res->fetchRow(); @@ -124,11 +148,13 @@ $session = $login->session; - $_SESSION["nameidentifier"] = $login->nameIdentifier; - $_SESSION["session_dump"] = $session->dump(); - $_SESSION["user_id"] = $user_id; + $_SESSION['nameidentifier'] = $login->nameIdentifier; + $_SESSION['session_dump'] = $session->dump(); + $_SESSION['user_id'] = $user_id; $url = "index.php"; + + $logger->log("New session started for user '$user_id'", PEAR_LOG_INFO); } else { @@ -141,30 +167,48 @@ $session = $login->session; // Insert into users - $identity_dump_quoted = $db->quoteSmart($identity_dump); - $query = "INSERT INTO users (user_id,identity_dump,created) VALUES(nextval('user_id_seq'), $identity_dump_quoted, NOW())"; + $query = "INSERT INTO users (user_id,identity_dump,created) VALUES(nextval('user_id_seq'),"; + $query .= $db->quoteSmart($identity_dump) . ", NOW())"; + $res =& $db->query($query); if (DB::isError($res)) - print $res->getMessage(). "\n"; + { + $logger->log("DB Error :" . $db->getMessage(), PEAR_LOG_CRIT); + $logger->log("DB Error :" . $db->getDebugInfo(), PEAR_LOG_DEBUG); + die($db->getMessage()); + } + // Get UserID $query = "SELECT last_value FROM user_id_seq"; $res =& $db->query($query); if (DB::isError($res)) - print $res->getMessage(). "\n"; + { + $logger->log("DB Error :" . $db->getMessage(), PEAR_LOG_CRIT); + $logger->log("DB Error :" . $db->getDebugInfo(), PEAR_LOG_DEBUG); + die($db->getMessage()); + } $row = $res->fetchRow(); $user_id = $row[0]; + $logger->log("New user($user_id) created", PEAR_LOG_NOTICE); + // Insert into nameidentifiers $query = "INSERT INTO nameidentifiers VALUES('".$login->nameIdentifier."', '$user_id')"; $res =& $db->query($query); if (DB::isError($res)) - print $res->getMessage(). "\n"; + { + $logger->log("DB Error :" . $db->getMessage(), PEAR_LOG_CRIT); + $logger->log("DB Error :" . $db->getDebugInfo(), PEAR_LOG_DEBUG); + die($db->getMessage()); + } + + $_SESSION['nameidentifier'] = $login->nameIdentifier; + $_SESSION['session_dump'] = $session->dump(); + $_SESSION['user_id'] = $user_id; - $_SESSION["nameidentifier"] = $login->nameIdentifier; - $_SESSION["session_dump"] = $session->dump(); - $_SESSION["user_id"] = $user_id; + $logger->log("New session started for user '$user_id', redirect to the registration form", PEAR_LOG_INFO); $url = "register.php"; } @@ -173,14 +217,17 @@ $query = "UPDATE users SET last_login=NOW() WHERE user_id='$user_id'"; $res =& $db->query($query); if (DB::isError($res)) - print $res->getMessage(). "\n"; - - $db->disconnect(); - - lasso_shutdown(); + { + $logger->log("DB Error :" . $db->getMessage(), PEAR_LOG_CRIT); + $logger->log("DB Error :" . $db->getDebugInfo(), PEAR_LOG_DEBUG); + die($db->getMessage()); + } + $logger->log("Update last login for user '$user_id'", PEAR_LOG_INFO); header("Request-URI: $url"); header("Content-Location: $url"); - header("Location: $urln\n\n"); + header("Location: $url\n\n"); + $db->disconnect(); + lasso_shutdown(); exit(); ?> diff --git a/php/Attic/examples/sample-sp/index.php b/php/Attic/examples/sample-sp/index.php index 199e8286..05d16e54 100644 --- a/php/Attic/examples/sample-sp/index.php +++ b/php/Attic/examples/sample-sp/index.php @@ -22,6 +22,9 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + require_once 'HTTP/Session.php'; + require_once 'DB.php'; + if(!extension_loaded('lasso')) { $ret = @dl('lasso.' . PHP_SHLIB_SUFFIX); if ($ret == FALSE) @@ -50,14 +53,17 @@ You can get more informations about Lasso at
$config = unserialize(file_get_contents('config.inc')); - require_once 'DB.php'; - - session_start(); + // connect to the data base + $db = &DB::connect($config['dsn']); + if (DB::isError($db)) + die($db->getMessage()); + + session_start(); - lasso_init(); - + lasso_init(); ?> - + Lasso Service Provider Example @@ -65,19 +71,26 @@ You can get more informations about Lasso at
-

+

Service Provider Administration
Setup
Users Management
+View Online Users + +
View log +

-

+

Serice Provider Fonctionnality - +
- + + + + @@ -85,7 +98,7 @@ You can get more informations about Lasso at
- + @@ -97,8 +110,8 @@ You can get more informations about Lasso at
Single SignOn using an IdPSingle SignOn using an Identity Provider
 
Provider
post | artifactpost | artifact

-

- +

+

Lasso at
getMessage()); - + $query = "SELECT * FROM users WHERE user_id='". $_SESSION["user_id"] ."'"; $res =& $db->query($query); if (DB::isError($res)) - print $res->getMessage(). "\n"; + die($res->getMessage()); list($user_id, $identity_dump, $first_name, $last_name, $last_login, $created) = $res->fetchRow(); - ?> @@ -147,20 +155,16 @@ You can get more informations about Lasso at
disconnect(); } ?>
Status
UserID:
Last Name:
Last Login:

- -
-

Copyright © 2004 Entr'ouvert

- +

Copyright © 2004 Entr'ouvert

- + $db->disconnect(); +?> diff --git a/php/Attic/examples/sample-sp/log_view.php b/php/Attic/examples/sample-sp/log_view.php new file mode 100644 index 00000000..68acc458 --- /dev/null +++ b/php/Attic/examples/sample-sp/log_view.php @@ -0,0 +1,160 @@ + + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + require_once 'HTML/QuickForm.php'; + require_once 'DB.php'; + + $config = unserialize(file_get_contents('config.inc')); + + // connect to the data base + $db = &DB::connect($config['dsn']); + if (DB::isError($db)) + die("Could not connect to the database"); + + if ($config['log_handler'] != 'sql') + die("Unsupported log handler"); + + $number_of_msg = 8; + + // Count log messages + $query = "SELECT COUNT(*) FROM log"; + $res =& $db->query($query); + if (DB::isError($res)) + die($res->getMessage()); + + $row = $res->fetchRow(); + $count = $row[0]; + + $startMsg = ((empty($_GET['startMsg'])) ? 0 : $_GET['startMsg']); + + $query = "SELECT * FROM log ORDER BY id DESC"; + if (!isset($_GET['show_all'])) + $query .= " OFFSET $startMsg LIMIT " . ($startMsg + $number_of_msg); + + + $res =& $db->query($query); + if (DB::isError($res)) + die($res->getMessage()); + + $numRows = $res->numRows(); + +?> + + + + + Lasso Identity Provider Example : View Logs + + +
+ + + + + + + + + + + + + + +numCols(); + $tableinfo = $db->tableInfo($res); + + $desc = array("emergency", "alert", "critical", "error", "warning", "notice", "informational", "debug"); + + while($row = $res->fetchRow()) + { + echo ""; + for ($i = 0; $i < $num_col; $i++) + { + switch ($tableinfo[$i]['name']) + { + case "id": + break; + case "priority": + echo ""; + break; + case "message": + echo ""; + break; + default: + echo ""; + } + } + echo ""; + } + } +?> + + + + + + + + +
Logged events
+ Previous"; + else + echo "Previous" + ?> + | + $number_of_users) && !isset($_GET['show_all'])) + echo "Next"; + else + echo "Next"; + + if (isset($_GET['show_all'])) + echo "| Paginate"; + else + { + for ($i = 0; $i < $count; $i += $number_of_msg) + if ($i == $startMsg) + echo "| " . ( $i / $number_of_msg); + else + echo "| " . ( $i / $number_of_msg) . ""; + if ($count > $number_of_msg) + echo "| Show All"; + } + ?> +
datefilenameprioritymessage
" . $desc[$row[$i]] . "" . $row[$i] . "" . $row[$i] . "
 
+
+

Index +

+
+

Copyright © 2004 Entr'ouvert

+ + + diff --git a/php/Attic/examples/sample-sp/login.php b/php/Attic/examples/sample-sp/login.php index 229aa28a..c857e5cd 100644 --- a/php/Attic/examples/sample-sp/login.php +++ b/php/Attic/examples/sample-sp/login.php @@ -1,6 +1,5 @@ initauthnrequest(lassoHttpMethodRedirect); - - $request = $login->authnRequest; + switch($_GET['profile']) + { + case 'post': + // TODO + break; + case 'artifact': + $login->initauthnrequest(lassoHttpMethodRedirect); + + $request = $login->authnRequest; - $request->isPassive = FALSE; - $request->nameIdPolicy = lassoLibNameIDPolicyTypeFederated; - $request->consent = lassoLibConsentObtained; + $request->isPassive = FALSE; + $request->nameIdPolicy = lassoLibNameIDPolicyTypeFederated; + $request->consent = lassoLibConsentObtained; - $login->buildAuthnRequestMsg($config['providerID']); + $login->buildAuthnRequestMsg($config['providerID']); - $url = $login->msgUrl; + $url = $login->msgUrl; - header("Request-URI: $url"); - header("Content-Location: $url"); - header("Location: $url\r\n\r\n"); - exit(); + header("Request-URI: $url"); + header("Content-Location: $url"); + header("Location: $url\r\n\r\n"); + exit(); + default: + die('Unknown single sign on profile'); + } ?> diff --git a/php/Attic/examples/sample-sp/logout.php b/php/Attic/examples/sample-sp/logout.php index 81937679..68f15fea 100644 --- a/php/Attic/examples/sample-sp/logout.php +++ b/php/Attic/examples/sample-sp/logout.php @@ -69,7 +69,6 @@ $url['path'], $url['host'], $url['port'], strlen($logout->msgBody), $logout->msgBody); - die($soap); # PHP 4.3.0 with OpenSSL support required $fp = fsockopen("ssl://" . $url['host'], $url['port'], $errno, $errstr, 30) or die($errstr ($errno)); diff --git a/php/Attic/examples/sample-sp/metadata_idp1.xml b/php/Attic/examples/sample-sp/metadata_idp1.xml index 3330c73d..5dda1a22 100644 --- a/php/Attic/examples/sample-sp/metadata_idp1.xml +++ b/php/Attic/examples/sample-sp/metadata_idp1.xml @@ -4,16 +4,16 @@ xmlns="urn:liberty:metadata:2003-08"> - https://idp1:1998/singleSignOn + https://idp1:1998/singleSignOn.php http://projectliberty.org/profiles/sso-get - https://idp1:1998/singleLogout + https://idp1:1998/singleLogout.php http://projectliberty.org/profiles/slo-idp-soap - https://idp1:1998/registerNameIdentifier + https://idp1:1998/registerNameIdentifier.php http://projectliberty.org/profiles/rni-sp-http - https://idp1:1998/soapEndpoint + https://idp1:1998/soapEndpoint.php diff --git a/php/Attic/examples/sample-sp/setup.php b/php/Attic/examples/sample-sp/setup.php index eebd81ed..c6c44228 100644 --- a/php/Attic/examples/sample-sp/setup.php +++ b/php/Attic/examples/sample-sp/setup.php @@ -22,8 +22,10 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + require_once 'DB.php'; ?> - + http://lasso.entrouvert.org/

"; exit(); } - } + } - require_once 'DB.php'; # default config if (!file_exists('config.inc')) @@ -46,6 +47,7 @@ $config = array( 'dsn' => "pgsql://sp:sp@localhost/sp", 'server_dump_filename' => "lasso_server_dump.xml", + 'log_handler' => "sql", 'sp-metadata' => $cwd . "/metadata_sp1.xml", 'sp-public_key' => $cwd . "/public-key_sp1.pem", 'sp-private_key' => $cwd . "/private-key-raw_sp1.pem", @@ -140,7 +142,41 @@ die($res->getMessage()); print "OK"; + + print "
Create table 'log' : "; + $query = "DROP TABLE log CASCADE"; + $res =& $db->query($query); + + $query = "CREATE TABLE log ( + id integer primary key, + logtime timestamp, + ident varchar(16), + priority integer, + message text)"; + + $res =& $db->query($query); + if (DB::isError($res)) + die($res->getMessage()); + + print "OK"; + + + print "
Create table 'sessions' : "; + $query = "DROP TABLE sessions CASCADE"; + $res =& $db->query($query); + + $query = "CREATE TABLE sessions ( + id varchar(32) primary key, + expiry integer, + data text + )"; + $res =& $db->query($query); + if (DB::isError($res)) + die($res->getMessage()); + + print "OK"; + $db->disconnect(); $keys = array_keys($config); @@ -151,9 +187,7 @@ { print "
Check file " . $config[$file] . " : "; if (!file_exists($config[$file])) - { die("Failed (file does not exist)"); - } else print "OK"; } @@ -261,6 +295,20 @@ Server XML Dump :' maxlength='100'>  + + Logging + + + Handler : + + +   + + Service Provider diff --git a/php/Attic/examples/sample-sp/view_session.php b/php/Attic/examples/sample-sp/view_session.php new file mode 100644 index 00000000..3a8252b3 --- /dev/null +++ b/php/Attic/examples/sample-sp/view_session.php @@ -0,0 +1,88 @@ + + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + require_once 'DB.php'; + + if (!file_exists('config.inc')) + { +?> +

Service Provider Configuration file is not available
+Please run the setup script :
+Lasso Service Provider Setup
+You can get more informations about Lasso at
+http://lasso.entrouvert.org/

+getMessage()); + + $query = "SELECT * FROM sessions"; + + $res =& $db->query($query); + if (DB::isError($res)) + die($res->getMessage()); + + $numRows = $res->numRows(); +?> + + + +Lasso Service Provider Example : View Online Users + + + + +

+ + + + + + + + + + + + + + + +
Online Users
 
 
+

+ +
+

Index +

+
+

Copyright © 2004 Entr'ouvert

+ + + -- cgit