Skip to content
Snippets Groups Projects
Commit e407ec9f authored by Andreas Åkre Solberg's avatar Andreas Åkre Solberg
Browse files

The session class now takes the nameid as an array with value and format,...

The session class now takes the nameid as an array with value and format, instead of two separate methods. this resulted in changes in several files.

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@218 44740490-163a-0410-bde0-09ae8108e29a
parent 8fcaa27a
No related branches found
No related tags found
No related merge requests found
......@@ -50,7 +50,6 @@ class SimpleSAML_Session {
private $sessionindex = null;
private $nameid = null;
private $nameidformat = null;
private $sp_at_idpsessions = array();
......@@ -295,13 +294,6 @@ class SimpleSAML_Session {
public function getNameID() {
return $this->nameid;
}
public function setNameIDformat($nameidformat) {
$this->dirty = true;
$this->nameidformat = $nameidformat;
}
public function getNameIDformat() {
return $this->nameidformat;
}
public function setAuthenticated($auth, $authority = null) {
if ($auth === false) $this->dirty = false;
......@@ -381,7 +373,6 @@ class SimpleSAML_Session {
$this->sessionindex = null;
$this->nameid = null;
$this->nameidformat = null;
$this->sp_at_idpsessions = array();
}
......
......@@ -138,28 +138,19 @@ class SimpleSAML_XML_SAML20_AuthnResponse extends SimpleSAML_XML_AuthnResponse {
public function createSession() {
SimpleSAML_Session::init(true, 'saml2');
$session = SimpleSAML_Session::getInstance();
$session->setAttributes($this->getAttributes());
$nameid = $this->getNameID();
$session->setNameID($nameid['NameID']);
$session->setNameIDFormat($nameid['Format']);
$session->setNameID($this->getNameID());
$session->setSessionIndex($this->getSessionIndex());
$session->setIdP($this->getIssuer());
/*
$nameID["NameID"] = $node->nodeValue;
$nameID["NameQualifier"] = $node->getAttribute('NameQualifier');
$nameID["SPNameQualifier"] = $node->getAttribute('SPNameQualifier');
*/
return $session;
}
//TODO
// TODO: Not tested, but neigther is it used.
function getSessionIndex() {
$token = $this->getDOM();
if ($token instanceof DOMDocument) {
......@@ -307,13 +298,12 @@ class SimpleSAML_XML_SAML20_AuthnResponse extends SimpleSAML_XML_AuthnResponse {
$nodelist = $xPath->query($query);
if ($node = $nodelist->item(0)) {
$nameID["NameID"] = $node->nodeValue;
$nameID["value"] = $node->nodeValue;
//$nameID["NameQualifier"] = $node->getAttribute('NameQualifier');
//$nameID["SPNameQualifier"] = $node->getAttribute('SPNameQualifier');
$nameID["Format"] = $node->getAttribute('Format');
}
}
//echo '<pre>'; print_r($nameID); echo '</pre>';
return $nameID;
}
......@@ -347,14 +337,32 @@ class SimpleSAML_XML_SAML20_AuthnResponse extends SimpleSAML_XML_AuthnResponse {
}
// Not updated for response. from request.
/**
* This function generates an AuthenticationResponse
*
* @param $idpentityid entityid of IdP
* @param $spentityid entityid of SP
* @param $inresponseto the ID of the request, that these message is an response to.
* @param $nameid the NameID of the user (an array)
* @param $attributes A two level array of multivalued attributes, where the first level
* index is the attribute name.
*
* @return AuthenticationResponse as string
*/
public function generate($idpentityid, $spentityid, $inresponseto, $nameid, $attributes) {
//echo 'idp:' . $idpentityid . ' sp:' . $spentityid .' inresponseto:' . $inresponseto . ' namid:' . $nameid;
/**
* Retrieving metadata for the two specific entity IDs.
*/
$idpmd = $this->metadata->getMetaData($idpentityid, 'saml20-idp-hosted');
$spmd = $this->metadata->getMetaData($spentityid, 'saml20-sp-remote');
$issuer = $idpentityid;
$destination = $spmd['AssertionConsumerService'];
/**
* Generating IDs and timestamps.
*/
$id = self::generateID();
$issueInstant = self::generateIssueInstant();
$assertionExpire = self::generateIssueInstant(60 * 5); # 5 minutes
......@@ -362,32 +370,34 @@ class SimpleSAML_XML_SAML20_AuthnResponse extends SimpleSAML_XML_AuthnResponse {
$assertionid = self::generateID();
$sessionindex = self::generateID();
$issuer = $idpentityid;
$assertionConsumerServiceURL = $spmd['AssertionConsumerService'];
$destination = $spmd['AssertionConsumerService'];
/**
* Handling attributes.
*/
$base64 = isset($spmd['base64attributes']) ? $spmd['base64attributes'] : false;
$encodedattributes = '';
foreach ($attributes AS $name => $values) {
$encodedattributes .= self::enc_attribute($name, $values, $base64);
}
$attributestatement = '<saml:AttributeStatement>' . $encodedattributes . '</saml:AttributeStatement>';
if (!$spmd['simplesaml.attributes'])
$attributestatement = '';
$namid = null;
/**
* Handling NameID
*/
$nameid = null;
if ($spmd['NameIDFormat'] == self::EMAIL) {
$nameid = $this->generateNameID($spmd['NameIDFormat'], $attributes[$spmd['simplesaml.nameidattribute']][0]);
} else {
$nameid = $this->generateNameID($spmd['NameIDFormat'], self::generateID());
}
/**
* Generating the response.
*/
$authnResponse = '<samlp:Response
xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol"
xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion"
......@@ -427,11 +437,6 @@ class SimpleSAML_XML_SAML20_AuthnResponse extends SimpleSAML_XML_AuthnResponse {
</samlp:Response>
';
//echo $authnResponse;
// echo $authnResponse; exit(0);
return $authnResponse;
}
......
......@@ -110,7 +110,7 @@ class SimpleSAML_XML_SAML20_LogoutRequest {
public function generate($issuer, $receiver, $nameid, $nameidformat, $sessionindex, $mode) {
public function generate($issuer, $receiver, $nameid, $sessionindex, $mode) {
if (!in_array($mode, array('SP', 'IdP'))) {
throw new Exception('mode parameter of generate() must be either SP or IdP');
......@@ -151,8 +151,8 @@ class SimpleSAML_XML_SAML20_LogoutRequest {
"xmlns:saml=\"urn:oasis:names:tc:SAML:2.0:assertion\" " .
// "NameQualifier=\"" . $nameId["NameQualifier"] . "\" " .
// "SPNameQualifier=\"" . $nameId["SPNameQualifier"] . "\" " .
"Format=\"" . htmlspecialchars($nameidformat) . "\">" .
htmlspecialchars($nameid) .
"Format=\"" . htmlspecialchars($nameid['Format']) . "\">" .
htmlspecialchars($nameid['value']) .
"</saml:NameID>" .
"<samlp:SessionIndex " .
"xmlns:samlp=\"urn:oasis:names:tc:SAML:2.0:protocol\">" .
......
......@@ -15,7 +15,6 @@ require_once('xmlseclibs.php');
* @author Andreas kre Solberg, UNINETT AS. <andreas.solberg@uninett.no>
* @package simpleSAMLphp
* @version $Id$
* @abstract
*/
class SimpleSAML_XML_Shib13_AuthnResponse extends SimpleSAML_XML_AuthnResponse {
......@@ -100,8 +99,7 @@ class SimpleSAML_XML_Shib13_AuthnResponse extends SimpleSAML_XML_AuthnResponse {
$nameid = $this->getNameID();
$session->setNameID($nameid['NameID']);
$session->setNameIDFormat($nameid['Format']);
$session->setNameID($nameid);
$session->setSessionIndex($this->getSessionIndex());
/*
$nameID["NameID"] = $node->nodeValue;
......@@ -254,8 +252,7 @@ class SimpleSAML_XML_Shib13_AuthnResponse extends SimpleSAML_XML_AuthnResponse {
}
public function getNameID() {
$token = $this->getDOM();
$nameID = array();
if ($token instanceof DOMDocument) {
......@@ -266,9 +263,9 @@ class SimpleSAML_XML_Shib13_AuthnResponse extends SimpleSAML_XML_AuthnResponse {
$query = '/mysamlp:Response/mysaml:Assertion/mysaml:AuthenticationStatement/mysaml:Subject/mysaml:NameIdentifier';
$nodelist = $xPath->query($query);
if ($node = $nodelist->item(0)) {
$nameID["NameID"] = $node->nodeValue;
$nameID["value"] = $node->nodeValue;
$nameID["Format"] = $node->getAttribute('Format');
$nameID["NameQualifier"] = $node->getAttribute('NameQualifier');
//$nameID["NameQualifier"] = $node->getAttribute('NameQualifier');
}
}
return $nameID;
......
......@@ -57,8 +57,9 @@ if (isset($_POST['password'])) {
$session->setAuthenticated(true, 'login-admin');
$session->setAttributes($attributes);
$session->setNameID(SimpleSAML_Utilities::generateID());
$session->setNameIDFormat('urn:oasis:names:tc:SAML:2.0:nameid-format:transient');
$session->setNameID(array(
'value' => SimpleSAML_Utilities::generateID(),
'Format' => 'urn:oasis:names:tc:SAML:2.0:nameid-format:transient'));
$logger->log(LOG_NOTICE, $session->getTrackID(), 'AUTH', 'admin', 'OK', $username, $username . ' successfully authenticated');
......
......@@ -87,7 +87,11 @@ if($session == NULL) {
* configuration.
*/
$session->setAuthenticated(true, 'login-auto');
$session->setAttributes($attributes);
$session->setNameID(array(
'value' => SimpleSAML_Utilities::generateID(),
'Format' => 'urn:oasis:names:tc:SAML:2.0:nameid-format:transient'));
/* Return the user to the page set in the RelayState parameter. */
$returnto = $_REQUEST['RelayState'];
......
......@@ -84,8 +84,9 @@ if (isset($_POST['username'])) {
$session->setAuthenticated(true, 'login-ldapmulti');
$session->setAttributes($attributes);
$session->setNameID(SimpleSAML_Utilities::generateID());
$session->setNameIDFormat('urn:oasis:names:tc:SAML:2.0:nameid-format:transient');
$session->setNameID(array(
'value' => SimpleSAML_Utilities::generateID(),
'Format' => 'urn:oasis:names:tc:SAML:2.0:nameid-format:transient'));
$returnto = $_REQUEST['RelayState'];
SimpleSAML_Utilities::redirect($returnto);
......
......@@ -79,7 +79,11 @@ if (isset($_POST['username'])) {
$logger->log(LOG_NOTICE, $session->getTrackID(), 'AUTH', 'radius', 'OK', $_POST['username'], $_POST['username'] . ' successfully authenticated');
$session->setAuthenticated(true, 'login-radius');
$session->setAttributes($attributes);
$session->setNameID(array(
'value' => SimpleSAML_Utilities::generateID(),
'Format' => 'urn:oasis:names:tc:SAML:2.0:nameid-format:transient'));
$returnto = $_REQUEST['RelayState'];
SimpleSAML_Utilities::redirect($returnto);
......
......@@ -140,8 +140,9 @@ if (isset($_POST['username'])) {
$session->setAttributes($attributes);
$session->setNameID(SimpleSAML_Utilities::generateID());
$session->setNameIDFormat('urn:oasis:names:tc:SAML:2.0:nameid-format:transient');
$session->setNameID(array(
'value' => SimpleSAML_Utilities::generateID(),
'Format' => 'urn:oasis:names:tc:SAML:2.0:nameid-format:transient'));
$logger->log(LOG_NOTICE, $session->getTrackID(), 'AUTH', 'ldap', 'OK', $username, $username . ' successfully authenticated');
......
......@@ -170,7 +170,7 @@ if ($spentityid) {
$lr = new SimpleSAML_XML_SAML20_LogoutRequest($config, $metadata);
// ($issuer, $receiver, $nameid, $nameidformat, $sessionindex, $mode) {
$req = $lr->generate($idpentityid, $spentityid, $session->getNameID(), $session->getNameIDFormat(), $session->getSessionIndex(), 'IdP');
$req = $lr->generate($idpentityid, $spentityid, $session->getNameID(), $session->getSessionIndex(), 'IdP');
$httpredirect = new SimpleSAML_Bindings_SAML20_HTTPRedirect($config, $metadata);
......
......@@ -32,8 +32,8 @@ if (isset($session) ) {
try {
$lr = new SimpleSAML_XML_SAML20_LogoutRequest($config, $metadata);
// ($issuer, $receiver, $nameid, $nameidformat, $sessionindex, $mode) {
$req = $lr->generate($spentityid, $idpentityid, $session->getNameID(), $session->getNameIDFormat(), $session->getSessionIndex(), 'SP');
// ($issuer, $receiver, $nameid, $sessionindex, $mode) {
$req = $lr->generate($spentityid, $idpentityid, $session->getNameID(), $session->getSessionIndex(), 'SP');
$httpredirect = new SimpleSAML_Bindings_SAML20_HTTPRedirect($config, $metadata);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment