You are here

public function saml_sp_AuthnRequest::__construct in SAML Service Provider 7.8

Same name and namespace in other branches
  1. 7.2 includes/saml_sp.AuthnRequest.inc \saml_sp_AuthnRequest::__construct()

Constructs the AuthnRequest object.

Parameters

OneLogin_Saml2_Settings $settings Settings:

File

includes/saml_sp.AuthnRequest.inc, line 10

Class

saml_sp_AuthnRequest

Code

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');
  }
}