Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added logging of request and response during SPID login using mySql or SqlServer #142

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/Spid/Saml.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class Saml implements SAMLInterface
public $settings;
private $idps = []; // contains filename -> Idp object array
private $session; // Session object
private $response;

public function __construct(array $settings, $autoconfigure = true)
{
Expand Down Expand Up @@ -207,8 +208,8 @@ public function isAuthenticated() : bool
return false;
}
$idp = $this->loadIdpFromFile($selectedIdp);
$response = new BaseResponse($this);
if (!empty($idp) && !$response->validate($idp->metadata['idpCertValue'])) {
$this->response = new BaseResponse($this);
if (!empty($idp) && !$this->response->validate($idp->metadata['idpCertValue'])) {
return false;
}
if (isset($_SESSION) && isset($_SESSION['inResponseTo'])) {
Expand All @@ -225,6 +226,11 @@ public function isAuthenticated() : bool
return false;
}

public function getResponse()
{
return $this->response;
}

public function logout(int $slo, string $redirectTo = null, $shouldRedirect = true)
{
$args = func_get_args();
Expand Down
14 changes: 10 additions & 4 deletions src/Spid/Saml/Idp.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class Idp implements IdpInterface
public $attrID;
public $level = 1;
public $session;
private $authn;

public function __construct($sp)
{
Expand Down Expand Up @@ -87,11 +88,11 @@ public function authnRequest($ass, $attr, $binding, $level = 1, $redirectTo = nu
$this->attrID = $attr;
$this->level = $level;

$authn = new AuthnRequest($this);
$this->authn = new AuthnRequest($this);
$url = $binding == Settings::BINDING_REDIRECT ?
$authn->redirectUrl($redirectTo) :
$authn->httpPost($redirectTo);
$_SESSION['RequestID'] = $authn->id;
$this->authn->redirectUrl($redirectTo) :
$this->authn->httpPost($redirectTo);
$_SESSION['RequestID'] = $this->authn->id;
$_SESSION['idpName'] = $this->idpFileName;
$_SESSION['idpEntityId'] = $this->metadata['idpEntityId'];
$_SESSION['acsUrl'] = $this->sp->settings['sp_assertionconsumerservice'][$ass];
Expand All @@ -106,6 +107,11 @@ public function authnRequest($ass, $attr, $binding, $level = 1, $redirectTo = nu
exit("");
}

public function getAuthn()
{
return $this->authn;
}

public function logoutRequest(Session $session, $slo, $binding, $redirectTo = null, $shouldRedirect = true) : string
{
$this->session = $session;
Expand Down
9 changes: 9 additions & 0 deletions src/Spid/Saml/In/BaseResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,13 @@ public function validate($cert) : bool
}
return $this->response->validate($this->xml, $hasAssertion);
}

public function getXml()
{
if ($this->xml) {
return $this->xml->getElementsByTagName('Response')->item(0);
} else {
return '';
}
}
}