本文整理汇总了PHP中SAML2_Utils类的典型用法代码示例。如果您正苦于以下问题:PHP SAML2_Utils类的具体用法?PHP SAML2_Utils怎么用?PHP SAML2_Utils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SAML2_Utils类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: testMarshallingOfSimpleRequest
public function testMarshallingOfSimpleRequest()
{
$document = new DOMDocument();
$document->loadXML(<<<AUTHNREQUEST
<samlp:AuthnRequest
xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol"
xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion"
ID="_306f8ec5b618f361c70b6ffb1480eade"
Version="2.0"
IssueInstant="2004-12-05T09:21:59Z"
Destination="https://idp.example.org/SAML2/SSO/Artifact"
ProtocolBinding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Artifact"
AssertionConsumerServiceURL="https://sp.example.com/SAML2/SSO/Artifact">
<saml:Issuer>https://sp.example.com/SAML2</saml:Issuer>
</samlp:AuthnRequest>
AUTHNREQUEST
);
$authnRequest = new SAML2_AuthnRequest($document->documentElement);
$expectedIssueInstant = SAML2_Utils::xsDateTimeToTimestamp('2004-12-05T09:21:59Z');
$this->assertEquals($expectedIssueInstant, $authnRequest->getIssueInstant());
$this->assertEquals('https://idp.example.org/SAML2/SSO/Artifact', $authnRequest->getDestination());
$this->assertEquals('urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Artifact', $authnRequest->getProtocolBinding());
$this->assertEquals('https://sp.example.com/SAML2/SSO/Artifact', $authnRequest->getAssertionConsumerServiceURL());
$this->assertEquals('https://sp.example.com/SAML2', $authnRequest->getIssuer());
}
开发者ID:pankajguru,项目名称:saml2,代码行数:25,代码来源:AuthnRequestTest.php
示例2: testMarshalling
public function testMarshalling()
{
$indexedEndpointType = new SAML2_XML_md_IndexedEndpointType();
$indexedEndpointType->Binding = 'TestBinding';
$indexedEndpointType->Location = 'TestLocation';
$indexedEndpointType->index = 42;
$indexedEndpointType->isDefault = FALSE;
$document = SAML2_DOMDocumentFactory::fromString('<root />');
$indexedEndpointTypeElement = $indexedEndpointType->toXML($document->firstChild, 'md:Test');
$indexedEndpointElements = SAML2_Utils::xpQuery($indexedEndpointTypeElement, '/root/saml_metadata:Test');
$this->assertCount(1, $indexedEndpointElements);
$indexedEndpointElement = $indexedEndpointElements[0];
$this->assertEquals('TestBinding', $indexedEndpointElement->getAttribute('Binding'));
$this->assertEquals('TestLocation', $indexedEndpointElement->getAttribute('Location'));
$this->assertEquals('42', $indexedEndpointElement->getAttribute('index'));
$this->assertEquals('false', $indexedEndpointElement->getAttribute('isDefault'));
$indexedEndpointType->isDefault = TRUE;
$document->loadXML('<root />');
$indexedEndpointTypeElement = $indexedEndpointType->toXML($document->firstChild, 'md:Test');
$indexedEndpointTypeElement = SAML2_Utils::xpQuery($indexedEndpointTypeElement, '/root/saml_metadata:Test');
$this->assertCount(1, $indexedEndpointTypeElement);
$this->assertEquals('true', $indexedEndpointTypeElement[0]->getAttribute('isDefault'));
$indexedEndpointType->isDefault = NULL;
$document->loadXML('<root />');
$indexedEndpointTypeElement = $indexedEndpointType->toXML($document->firstChild, 'md:Test');
$indexedEndpointTypeElement = SAML2_Utils::xpQuery($indexedEndpointTypeElement, '/root/saml_metadata:Test');
$this->assertCount(1, $indexedEndpointTypeElement);
$this->assertTrue(!$indexedEndpointTypeElement[0]->hasAttribute('isDefault'));
}
开发者ID:Shalmezad,项目名称:saml2,代码行数:29,代码来源:IndexedEndpointTypeTest.php
示例3: __construct
/**
* Constructor for SAML 2 response messages.
*
* @param string $tagName The tag name of the root element.
* @param DOMElement|NULL $xml The input message.
*/
protected function __construct($tagName, DOMElement $xml = NULL)
{
parent::__construct($tagName, $xml);
$this->status = array('Code' => SAML2_Const::STATUS_SUCCESS, 'SubCode' => NULL, 'Message' => NULL);
if ($xml === NULL) {
return;
}
if ($xml->hasAttribute('InResponseTo')) {
$this->inResponseTo = $xml->getAttribute('InResponseTo');
}
$status = SAML2_Utils::xpQuery($xml, './saml_protocol:Status');
if (empty($status)) {
throw new Exception('Missing status code on response.');
}
$status = $status[0];
$statusCode = SAML2_Utils::xpQuery($status, './saml_protocol:StatusCode');
if (empty($statusCode)) {
throw new Exception('Missing status code in status element.');
}
$statusCode = $statusCode[0];
$this->status['Code'] = $statusCode->getAttribute('Value');
$subCode = SAML2_Utils::xpQuery($statusCode, './saml_protocol:StatusCode');
if (!empty($subCode)) {
$this->status['SubCode'] = $subCode[0]->getAttribute('Value');
}
$message = SAML2_Utils::xpQuery($status, './saml_protocol:StatusMessage');
if (!empty($message)) {
$this->status['Message'] = trim($message[0]->textContent);
}
}
开发者ID:hukumonline,项目名称:yii,代码行数:36,代码来源:StatusResponse.php
示例4: __construct
/**
* Initialize an EntitiesDescriptor.
*
* @param DOMElement|NULL $xml The XML element we should load.
*/
public function __construct(DOMElement $xml = NULL)
{
parent::__construct($xml);
if ($xml === NULL) {
return;
}
if ($xml->hasAttribute('ID')) {
$this->ID = $xml->getAttribute('ID');
}
if ($xml->hasAttribute('validUntil')) {
$this->validUntil = SAML2_Utils::xsDateTimeToTimestamp($xml->getAttribute('validUntil'));
}
if ($xml->hasAttribute('cacheDuration')) {
$this->cacheDuration = $xml->getAttribute('cacheDuration');
}
if ($xml->hasAttribute('Name')) {
$this->Name = $xml->getAttribute('Name');
}
$this->Extensions = SAML2_XML_md_Extensions::getList($xml);
foreach (SAML2_Utils::xpQuery($xml, './saml_metadata:EntityDescriptor|./saml_metadata:EntitiesDescriptor') as $node) {
if ($node->localName === 'EntityDescriptor') {
$this->children[] = new SAML2_XML_md_EntityDescriptor($node);
} else {
$this->children[] = new SAML2_XML_md_EntitiesDescriptor($node);
}
}
}
开发者ID:shirlei,项目名称:simplesaml,代码行数:32,代码来源:EntitiesDescriptor.php
示例5: testUnmarshalling
public function testUnmarshalling()
{
$mdNamespace = SAML2_Const::NS_MD;
$document = SAML2_DOMDocumentFactory::fromString(<<<XML
<md:Test xmlns:md="{$mdNamespace}" Binding="urn:something" Location="https://whatever/" xmlns:test="urn:test" test:attr="value" />
XML
);
$endpointType = new SAML2_XML_md_EndpointType($document->firstChild);
$this->assertEquals(TRUE, $endpointType->hasAttributeNS('urn:test', 'attr'));
$this->assertEquals('value', $endpointType->getAttributeNS('urn:test', 'attr'));
$this->assertEquals(FALSE, $endpointType->hasAttributeNS('urn:test', 'invalid'));
$this->assertEquals('', $endpointType->getAttributeNS('urn:test', 'invalid'));
$endpointType->removeAttributeNS('urn:test', 'attr');
$this->assertEquals(FALSE, $endpointType->hasAttributeNS('urn:test', 'attr'));
$this->assertEquals('', $endpointType->getAttributeNS('urn:test', 'attr'));
$endpointType->setAttributeNS('urn:test2', 'test2:attr2', 'value2');
$this->assertEquals('value2', $endpointType->getAttributeNS('urn:test2', 'attr2'));
$document->loadXML('<root />');
$endpointTypeElement = $endpointType->toXML($document->firstChild, 'md:Test');
$endpointTypeElements = SAML2_Utils::xpQuery($endpointTypeElement, '/root/saml_metadata:Test');
$this->assertCount(1, $endpointTypeElements);
$endpointTypeElement = $endpointTypeElements[0];
$this->assertEquals('value2', $endpointTypeElement->getAttributeNS('urn:test2', 'attr2'));
$this->assertEquals(FALSE, $endpointTypeElement->hasAttributeNS('urn:test', 'attr'));
}
开发者ID:Shalmezad,项目名称:saml2,代码行数:25,代码来源:EndpointTypeTest.php
示例6: testMarshalling
public function testMarshalling()
{
$attributeQuery = new SAML2_AttributeQuery();
$attributeQuery->setNameID(array('Value' => 'NameIDValue'));
$attributeQuery->setAttributes(array('test1' => array('test1_attrv1', 'test1_attrv2'), 'test2' => array('test2_attrv1', 'test2_attrv2', 'test2_attrv3'), 'test3' => array()));
$attributeQueryElement = $attributeQuery->toUnsignedXML();
// Test Attribute Names
$attributes = SAML2_Utils::xpQuery($attributeQueryElement, './saml_assertion:Attribute');
$this->assertCount(3, $attributes);
$this->assertEquals('test1', $attributes[0]->getAttribute('Name'));
$this->assertEquals('test2', $attributes[1]->getAttribute('Name'));
$this->assertEquals('test3', $attributes[2]->getAttribute('Name'));
// Test Attribute Values for Attribute 1
$av1 = SAML2_Utils::xpQuery($attributes[0], './saml_assertion:AttributeValue');
$this->assertCount(2, $av1);
$this->assertEquals('test1_attrv1', $av1[0]->textContent);
$this->assertEquals('test1_attrv2', $av1[1]->textContent);
// Test Attribute Values for Attribute 2
$av2 = SAML2_Utils::xpQuery($attributes[1], './saml_assertion:AttributeValue');
$this->assertCount(3, $av2);
$this->assertEquals('test2_attrv1', $av2[0]->textContent);
$this->assertEquals('test2_attrv2', $av2[1]->textContent);
$this->assertEquals('test2_attrv3', $av2[2]->textContent);
// Test Attribute Values for Attribute 3
$av3 = SAML2_Utils::xpQuery($attributes[2], './saml_assertion:AttributeValue');
$this->assertCount(0, $av3);
}
开发者ID:Stony-Brook-University,项目名称:doitsbu,代码行数:27,代码来源:AttributeQueryTest.php
示例7: toXML
/**
* Append this attribute value to an element.
*
* @param DOMElement $parent The element we should append this attribute value to.
* @return DOMElement The generated AttributeValue element.
*/
public function toXML(DOMElement $parent)
{
assert('$this->element instanceof DOMElement');
assert('$this->element->namespaceURI === SAML2_Const::NS_SAML && $this->element->localName === "AttributeValue"');
$v = SAML2_Utils::copyElement($this->element, $parent);
return $v;
}
开发者ID:shirlei,项目名称:simplesaml,代码行数:13,代码来源:AttributeValue.php
示例8: getList
/**
* Get a list of Extensions in the given element.
*
* @param DOMElement $parent The element that may contain the samlp:Extensions element.
* @return array Array of extensions.
*/
public static function getList(DOMElement $parent)
{
$ret = array();
foreach (SAML2_Utils::xpQuery($parent, './saml_protocol:Extensions/*') as $node) {
$ret[] = new SAML2_XML_Chunk($node);
}
return $ret;
}
开发者ID:emma5021,项目名称:toba,代码行数:14,代码来源:Extensions.php
示例9: __construct
public function __construct(DOMElement $xml = NULL)
{
parent::__construct('ArtifactResolve', $xml);
if (!is_null($xml)) {
$results = SAML2_Utils::xpQuery($xml, './saml_protocol:Artifact');
$this->artifact = $results[0]->textContent;
}
}
开发者ID:emma5021,项目名称:toba,代码行数:8,代码来源:ArtifactResolve.php
示例10: toXML
/**
* Convert this AdditionalMetadataLocation to XML.
*
* @param DOMElement $parent The element we should append to.
* @return DOMElement This AdditionalMetadataLocation-element.
*/
public function toXML(DOMElement $parent)
{
assert('is_string($this->namespace)');
assert('is_string($this->location)');
$e = SAML2_Utils::addString($parent, SAML2_Const::NS_MD, 'md:AdditionalMetadataLocation', $this->location);
$e->setAttribute('namespace', $this->namespace);
return $e;
}
开发者ID:danielkjfrog,项目名称:docker,代码行数:14,代码来源:AdditionalMetadataLocation.php
示例11: __construct
/**
* Create a Scope.
*
* @param DOMElement|NULL $xml The XML element we should load.
*/
public function __construct(DOMElement $xml = NULL)
{
if ($xml === NULL) {
return;
}
$this->scope = $xml->textContent;
$this->regexp = SAML2_Utils::parseBoolean($xml, 'regexp', NULL);
}
开发者ID:emma5021,项目名称:toba,代码行数:13,代码来源:Scope.php
示例12: __construct
/**
* Initialize an RequestedAttribute.
*
* @param DOMElement|NULL $xml The XML element we should load.
*/
public function __construct(DOMElement $xml = NULL)
{
parent::__construct($xml);
if ($xml === NULL) {
return;
}
$this->isRequired = SAML2_Utils::parseBoolean($xml, 'isRequired', NULL);
}
开发者ID:danielkjfrog,项目名称:docker,代码行数:13,代码来源:RequestedAttribute.php
示例13: testExtractLocalizedString
/**
* Test retrieval of a localized string for a given node.
*/
public function testExtractLocalizedString()
{
$document = new DOMDocument();
$document->loadXML('<root xmlns="' . SAML2_Const::NS_MD . '">' . '<somenode xml:lang="en">value (en)</somenode>' . '<somenode xml:lang="no">value (no)</somenode>' . '</root>');
$localizedStringValues = SAML2_Utils::extractLocalizedStrings($document->firstChild, SAML2_Const::NS_MD, 'somenode');
$this->assertTrue(count($localizedStringValues) === 2);
$this->assertEquals('value (en)', $localizedStringValues["en"]);
$this->assertEquals('value (no)', $localizedStringValues["no"]);
}
开发者ID:shirlei,项目名称:simplesaml,代码行数:12,代码来源:UtilsTest.php
示例14: testXsDateTimeToTimestamp
/**
* Test xsDateTime format validity
*
* @dataProvider xsDateTimes
*/
public function testXsDateTimeToTimestamp($shouldPass, $time, $expectedTs = null)
{
try {
$ts = SAML2_Utils::xsDateTimeToTimestamp($time);
$this->assertTrue($shouldPass);
$this->assertEquals($expectedTs, $ts);
} catch (Exception $e) {
$this->assertFalse($shouldPass);
}
}
开发者ID:Shalmezad,项目名称:saml2,代码行数:15,代码来源:UtilsTest.php
示例15: load_saml_response
/**
* @param string $saml_response Base64 Encoded SAML
*
* @throws Exception When no assertions are found or signature in invalid
*/
public function load_saml_response($saml_response)
{
$response_element = SAML2_DOMDocumentFactory::fromString(base64_decode($saml_response))->documentElement;
$signature_info = SAML2_Utils::validateElement($response_element);
SAML2_Utils::validateSignature($signature_info, $this->security_key);
$response = SAML2_StatusResponse::fromXML($response_element);
$this->destination = $response->getDestination();
$assertions = $response->getAssertions();
$this->assertions = $assertions;
}
开发者ID:aenglander,项目名称:launchkey-wordpress,代码行数:15,代码来源:class-launchkey-wp-saml2-response-service.php
示例16: receive
/**
* Receive a SAML 2 message sent using the HTTP-Artifact binding.
*
* Throws an exception if it is unable receive the message.
*
* @return SAML2_Message The received message.
* @throws Exception
*/
public function receive()
{
if (array_key_exists('SAMLart', $_REQUEST)) {
$artifact = base64_decode($_REQUEST['SAMLart']);
$endpointIndex = bin2hex(substr($artifact, 2, 2));
$sourceId = bin2hex(substr($artifact, 4, 20));
} else {
throw new Exception('Missing SAMLArt parameter.');
}
$metadataHandler = SimpleSAML_Metadata_MetaDataStorageHandler::getMetadataHandler();
$idpMetadata = $metadataHandler->getMetaDataConfigForSha1($sourceId, 'saml20-idp-remote');
if ($idpMetadata === NULL) {
throw new Exception('No metadata found for remote provider with SHA1 ID: ' . var_export($sourceId, TRUE));
}
$endpoint = NULL;
foreach ($idpMetadata->getEndpoints('ArtifactResolutionService') as $ep) {
if ($ep['index'] === hexdec($endpointIndex)) {
$endpoint = $ep;
break;
}
}
if ($endpoint === NULL) {
throw new Exception('No ArtifactResolutionService with the correct index.');
}
SAML2_Utils::getContainer()->getLogger()->debug("ArtifactResolutionService endpoint being used is := " . $endpoint['Location']);
//Construct the ArtifactResolve Request
$ar = new SAML2_ArtifactResolve();
/* Set the request attributes */
$ar->setIssuer($this->spMetadata->getString('entityid'));
$ar->setArtifact($_REQUEST['SAMLart']);
$ar->setDestination($endpoint['Location']);
require_once realpath(__DIR__ . '/../../../simplesamlphp/modules/saml/lib/Message.php');
/* Sign the request */
sspmod_saml_Message::addSign($this->spMetadata, $idpMetadata, $ar);
// Shoaib - moved from the SOAPClient.
$soap = new SAML2_SOAPClient();
// Send message through SoapClient
/** @var SAML2_ArtifactResponse $artifactResponse */
$artifactResponse = $soap->send($ar, $this->spMetadata);
if (!$artifactResponse->isSuccess()) {
return false;
}
$xml = $artifactResponse->getAny();
if ($xml === NULL) {
/* Empty ArtifactResponse - possibly because of Artifact replay? */
return NULL;
}
$samlResponse = SAML2_Message::fromXML($xml);
$samlResponse->addValidator(array(get_class($this), 'validateSignature'), $artifactResponse);
if (isset($_REQUEST['RelayState'])) {
$samlResponse->setRelayState($_REQUEST['RelayState']);
}
return $samlResponse;
}
开发者ID:dutchbridge,项目名称:saml2,代码行数:62,代码来源:HTTPArtifact.php
示例17: receive
/**
* Receive a SAML 2 message sent using the HTTP-POST binding.
*
* Throws an exception if it is unable receive the message.
*
* @return SAML2_Message The received message.
*/
public function receive()
{
$postText = file_get_contents('php://input');
if (empty($postText)) {
throw new SimpleSAML_Error_BadRequest('Invalid message received to AssertionConsumerService endpoint.');
}
$document = new DOMDocument();
$document->loadXML($postText);
$xml = $document->firstChild;
$results = SAML2_Utils::xpQuery($xml, '/soap-env:Envelope/soap-env:Body/*[1]');
return SAML2_Message::fromXML($results[0]);
}
开发者ID:filonuse,项目名称:fedlab,代码行数:19,代码来源:SOAP.php
示例18: receive
/**
* Receive a SAML 2 message sent using the HTTP-POST binding.
*
* Throws an exception if it is unable receive the message.
*
* @return SAML2_Message The received message.
* @throws Exception
*/
public function receive()
{
$postText = file_get_contents('php://input');
if (empty($postText)) {
throw new Exception('Invalid message received to AssertionConsumerService endpoint.');
}
$document = SAML2_DOMDocumentFactory::fromString($postText);
$xml = $document->firstChild;
SAML2_Utils::getContainer()->debugMessage($xml, 'in');
$results = SAML2_Utils::xpQuery($xml, '/soap-env:Envelope/soap-env:Body/*[1]');
return SAML2_Message::fromXML($results[0]);
}
开发者ID:Shalmezad,项目名称:saml2,代码行数:20,代码来源:SOAP.php
示例19: testMarshalling
public function testMarshalling()
{
$response = new SAML2_Response();
$response->setConsent(SAML2_Const::CONSENT_EXPLICIT);
$response->setIssuer('SomeIssuer');
$responseElement = $response->toUnsignedXML();
$this->assertTrue($responseElement->hasAttribute('Consent'));
$this->assertEquals($responseElement->getAttribute('Consent'), SAML2_Const::CONSENT_EXPLICIT);
$issuerElements = SAML2_Utils::xpQuery($responseElement, './saml_assertion:Issuer');
$this->assertCount(1, $issuerElements);
$this->assertEquals('SomeIssuer', $issuerElements[0]->textContent);
}
开发者ID:shirlei,项目名称:simplesaml,代码行数:12,代码来源:ResponseTest.php
示例20: __construct
/**
* Initialize an IndexedEndpointType.
*
* @param DOMElement|NULL $xml The XML element we should load.
*/
public function __construct(DOMElement $xml = NULL)
{
parent::__construct($xml);
if ($xml === NULL) {
return;
}
if (!$xml->hasAttribute('index')) {
throw new Exception('Missing index on ' . $xml->tagName);
}
$this->index = (int) $xml->getAttribute('index');
$this->isDefault = SAML2_Utils::parseBoolean($xml, 'isDefault', NULL);
}
开发者ID:emma5021,项目名称:toba,代码行数:17,代码来源:IndexedEndpointType.php
注:本文中的SAML2_Utils类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论