OneLogin_Saml2_Utils::generateNameId PHP 메소드

generateNameId() 공개 정적인 메소드

Generates a nameID.
public static generateNameId ( string $value, string $spnq, string $format, string | null $cert = null ) : string
$value string fingerprint
$spnq string SP Name Qualifier
$format string SP Format
$cert string | null IdP Public cert to encrypt the nameID
리턴 string $nameIDElement DOMElement | XMLSec nameID
    public static function generateNameId($value, $spnq, $format, $cert = null)
    {
        $doc = new DOMDocument();
        $nameId = $doc->createElement('saml:NameID');
        if (isset($spnq)) {
            $nameId->setAttribute('SPNameQualifier', $spnq);
        }
        $nameId->setAttribute('Format', $format);
        $nameId->appendChild($doc->createTextNode($value));
        $doc->appendChild($nameId);
        if (!empty($cert)) {
            $seckey = new XMLSecurityKey(XMLSecurityKey::RSA_1_5, array('type' => 'public'));
            $seckey->loadKey($cert);
            $enc = new XMLSecEnc();
            $enc->setNode($nameId);
            $enc->type = XMLSecEnc::Element;
            $symmetricKey = new XMLSecurityKey(XMLSecurityKey::AES128_CBC);
            $symmetricKey->generateSessionKey();
            $enc->encryptKey($seckey, $symmetricKey);
            $encryptedData = $enc->encryptNode($symmetricKey);
            $newdoc = new DOMDocument();
            $encryptedID = $newdoc->createElement('saml:EncryptedID');
            $newdoc->appendChild($encryptedID);
            $encryptedID->appendChild($encryptedID->ownerDocument->importNode($encryptedData, true));
            return $newdoc->saveXML($encryptedID);
        } else {
            return $doc->saveXML($nameId);
        }
    }

Usage Example

예제 #1
0
    /**
     * Constructs the Logout Request 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();
        $nameIdValue = OneLogin_Saml2_Utils::generateUniqueID();
        $issueInstant = OneLogin_Saml2_Utils::parseTime2SAML(time());
        $key = null;
        if (isset($security['nameIdEncrypted']) && $security['nameIdEncrypted']) {
            $key = $idpData['x509cert'];
        }
        $nameId = OneLogin_Saml2_Utils::generateNameId($nameIdValue, $spData['entityId'], $spData['NameIDFormat'], $key);
        $logoutRequest = <<<LOGOUTREQUEST
<samlp:LogoutRequest
    xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol"
    xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion"
    ID="{$id}"
    Version="2.0"
    IssueInstant="{$issueInstant}"
    Destination="{$idpData['singleLogoutService']['url']}">
    <saml:Issuer>{$spData['entityId']}</saml:Issuer>
    {$nameId}
</samlp:LogoutRequest>
LOGOUTREQUEST;
        $this->_logoutRequest = $logoutRequest;
    }
All Usage Examples Of OneLogin_Saml2_Utils::generateNameId