namespace MiniOrange\IDPSaml\Controller\Actions;
use DOMElement;
use DOMDocument;
use MiniOrange\IDPSaml\Helper\IDPUtility;
use MiniOrange\IDPSaml\Helper\Saml2\SAML2Utilities;
class MiniOrangeAuthnRequest
{
private $nameIdPolicy;
private $forceAuthn;
private $isPassive;
private $RequesterID = array();
private $assertionConsumerServiceURL;
private $protocolBinding;
private $requestedAuthnContext;
private $namespaceURI;
private $destination;
private $issuer;
private $version;
private $issueInstant;
private $requestID;
protected $attributeConsumingServiceIndex;
public function __construct(DOMElement $ov = null)
{
$this->nameIdPolicy = array();
$this->forceAuthn = FALSE;
$this->isPassive = FALSE;
if (!($ov === NULL)) {
goto sA;
}
return;
sA:
$this->forceAuthn = SAML2Utilities::parseBoolean($ov, "ForceAuthn", FALSE);
$this->isPassive = SAML2Utilities::parseBoolean($ov, "IsPassive", FALSE);
if (!$ov->hasAttribute("AssertionConsumerServiceURL")) {
goto Bf;
}
$this->assertionConsumerServiceURL = $ov->getAttribute("AssertionConsumerServiceURL");
Bf:
if (!$ov->hasAttribute("ProtocolBinding")) {
goto Y0;
}
$this->protocolBinding = $ov->getAttribute("ProtocolBinding");
Y0:
if (!$ov->hasAttribute("AttributeConsumingServiceIndex")) {
goto SO;
}
$this->attributeConsumingServiceIndex = (int) $ov->getAttribute("AttributeConsumingServiceIndex");
SO:
if (!$ov->hasAttribute("AssertionConsumerServiceIndex")) {
goto b_;
}
$this->assertionConsumerServiceIndex = (int) $ov->getAttribute("AssertionConsumerServiceIndex");
b_:
if (!$ov->hasAttribute("Destination")) {
goto nk;
}
$this->destination = $ov->getAttribute("Destination");
nk:
if (!isset($ov->namespaceURI)) {
goto eO;
}
$this->namespaceURI = $ov->namespaceURI;
eO:
if (!$ov->hasAttribute("Version")) {
goto YX;
}
$this->version = $ov->getAttribute("Version");
YX:
if (!$ov->hasAttribute("IssueInstant")) {
goto Cn;
}
$this->issueInstant = $ov->getAttribute("IssueInstant");
Cn:
if (!$ov->hasAttribute("ID")) {
goto q1;
}
$this->requestID = $ov->getAttribute("ID");
q1:
$this->parseNameIdPolicy($ov);
$this->parseIssuer($ov);
$this->parseRequestedAuthnContext($ov);
$this->parseScoping($ov);
}
public function getVersion()
{
return $this->version;
}
public function getRequestID()
{
return $this->requestID;
}
public function getIssueInstant()
{
return $this->issueInstant;
}
public function getDestination()
{
return $this->destination;
}
public function getIssuer()
{
return $this->issuer;
}
public function getAssertionConsumerServiceURL()
{
return $this->assertionConsumerServiceURL;
}
protected function parseIssuer(DOMElement $ov)
{
$cZ = SAML2Utilities::xpQuery($ov, "./saml_assertion:Issuer");
if (!empty($cZ)) {
goto lk;
}
throw new Exception("Missing <saml:Issuer> in assertion.");
lk:
$this->issuer = trim($cZ[0]->textContent);
}
protected function parseNameIdPolicy(DOMElement $ov)
{
$pg = SAML2Utilities::xpQuery($ov, "./saml_protocol:NameIDPolicy");
if (!empty($pg)) {
goto tM;
}
return;
tM:
$pg = $pg[0];
if (!$pg->hasAttribute("Format")) {
goto oY;
}
$this->nameIdPolicy["Format"] = $pg->getAttribute("Format");
oY:
if (!$pg->hasAttribute("SPNameQualifier")) {
goto JX;
}
$this->nameIdPolicy["SPNameQualifier"] = $pg->getAttribute("SPNameQualifier");
JX:
if (!$pg->hasAttribute("AllowCreate")) {
goto FQ;
}
$this->nameIdPolicy["AllowCreate"] = SAML2Utilities::parseBoolean($pg, "AllowCreate", false);
FQ:
}
protected function parseRequestedAuthnContext(DOMElement $ov)
{
$Ys = SAML2Utilities::xpQuery($ov, "./saml_protocol:RequestedAuthnContext");
if (!empty($Ys)) {
goto UM;
}
return;
UM:
$Ys = $Ys[0];
$Ea = array("AuthnContextClassRef" => array(), "Comparison" => "exact");
$FS = SAML2Utilities::xpQuery($Ys, "./saml_assertion:AuthnContextClassRef");
foreach ($FS as $gS) {
$Ea["AuthnContextClassRef"][] = trim($gS->textContent);
TT:
}
Xt:
if (!$Ys->hasAttribute("Comparison")) {
goto YH;
}
$Ea["Comparison"] = $Ys->getAttribute("Comparison");
YH:
$this->requestedAuthnContext = $Ea;
}
protected function parseScoping(DOMElement $ov)
{
$h1 = SAML2Utilities::xpQuery($ov, "./saml_protocol:Scoping");
if (!empty($h1)) {
goto zN;
}
return;
zN:
$h1 = $h1[0];
if (!$h1->hasAttribute("ProxyCount")) {
goto wq;
}
$this->ProxyCount = (int) $h1->getAttribute("ProxyCount");
wq:
$oZ = SAML2Utilities::xpQuery($h1, "./saml_protocol:IDPList/saml_protocol:IDPEntry");
foreach ($oZ as $pP) {
if ($pP->hasAttribute("ProviderID")) {
goto h2;
}
throw new Exception("Could not get ProviderID from Scoping/IDPEntry element in AuthnRequest object");
h2:
$this->IDPList[] = $pP->getAttribute("ProviderID");
Y2:
}
ve:
$gi = SAML2Utilities::xpQuery($h1, "./saml_protocol:RequesterID");
foreach ($gi as $ZS) {
$this->RequesterID[] = trim($ZS->textContent);
mA:
}
C7:
}
}
© 2023 Quttera Ltd. All rights reserved.