saml_sp.AuthnRequest.inc in SAML Service Provider 7.8
File
includes/saml_sp.AuthnRequest.inc
View source
<?php
class saml_sp_AuthnRequest extends OneLogin_Saml2_AuthnRequest {
public function __construct(OneLogin_Saml2_Settings $settings) {
$this->_settings = $settings;
$spData = $this->_settings
->getSPData();
$idpData = $this->_settings
->getIdPData();
$security = $this->_settings
->getSecurityData();
$id = OneLogin_Saml2_Utils::generateUniqueID();
$issueInstant = OneLogin_Saml2_Utils::parseTime2SAML(time());
$nameIDPolicyFormat = $spData['NameIDFormat'];
if (isset($security['wantNameIdEncrypted']) && $security['wantNameIdEncrypted']) {
$nameIDPolicyFormat = OneLogin_Saml2_Constants::NAMEID_ENCRYPTED;
}
$providerNameStr = '';
$organizationData = $settings
->getOrganization();
if (!empty($organizationData)) {
$langs = array_keys($organizationData);
if (in_array('en-US', $langs)) {
$lang = 'en-US';
}
else {
$lang = $langs[0];
}
if (isset($organizationData[$lang]['displayname']) && !empty($organizationData[$lang]['displayname'])) {
$providerNameStr = <<<PROVIDERNAME
ProviderName="{<span class="php-variable">$organizationData</span>[<span class="php-variable">$lang</span>][<span class="php-string">'displayname'</span>]}"
PROVIDERNAME;
}
}
$request = <<<AUTHNREQUEST
<samlp:AuthnRequest
xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol"
xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion"
ID="{<span class="php-variable">$id</span>}"
Version="2.0"
{<span class="php-variable">$providerNameStr</span>}
IssueInstant="{<span class="php-variable">$issueInstant</span>}"
Destination="{<span class="php-variable">$idpData</span>[<span class="php-string">'singleSignOnService'</span>][<span class="php-string">'url'</span>]}"
ProtocolBinding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST"
AssertionConsumerServiceURL="{<span class="php-variable">$spData</span>[<span class="php-string">'assertionConsumerService'</span>][<span class="php-string">'url'</span>]}">
<saml:Issuer>{<span class="php-variable">$spData</span>[<span class="php-string">'entityId'</span>]}</saml:Issuer>
<samlp:NameIDPolicy
Format="{<span class="php-variable">$nameIDPolicyFormat</span>}"
AllowCreate="true" />
<samlp:RequestedAuthnContext Comparison="exact">
<saml:AuthnContextClassRef>{<span class="php-variable">$idpData</span>[<span class="php-string">'AuthnContextClassRef'</span>]}</saml:AuthnContextClassRef>
</samlp:RequestedAuthnContext>
</samlp:AuthnRequest>
AUTHNREQUEST;
$this->_id = $id;
$this->_authnRequest = $request;
if (variable_get('saml_sp__debug', FALSE) && module_exists('devel')) {
dpm($this->_authnRequest, 'samlp:AuthnRequest');
}
}
public function getRequest() {
$deflatedRequest = gzdeflate($this->_authnRequest);
$base64Request = base64_encode($deflatedRequest);
return $base64Request;
}
public function getId() {
return $this->_id;
}
}