You are here

class saml_sp_AuthnRequest in SAML Service Provider 7.8

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

Hierarchy

Expanded class hierarchy of saml_sp_AuthnRequest

File

includes/saml_sp.AuthnRequest.inc, line 3

View source
class saml_sp_AuthnRequest extends OneLogin_Saml2_AuthnRequest {

  /**
   * Constructs the AuthnRequest object.
   *
   * @param OneLogin_Saml2_Settings $settings Settings
   */
  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');
    }
  }

  /**
   * Returns deflated, base64 encoded, unsigned AuthnRequest.
   *
   */
  public function getRequest() {
    $deflatedRequest = gzdeflate($this->_authnRequest);
    $base64Request = base64_encode($deflatedRequest);
    return $base64Request;
  }

  /**
   * Returns the AuthNRequest ID.
   *
   * @return string
   */
  public function getId() {
    return $this->_id;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
saml_sp_AuthnRequest::getId public function Returns the AuthNRequest ID.
saml_sp_AuthnRequest::getRequest public function Returns deflated, base64 encoded, unsigned AuthnRequest.
saml_sp_AuthnRequest::__construct public function Constructs the AuthnRequest object.