ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
attributeserver.php
Go to the documentation of this file.
1 <?php
2 
4 
6 $query = $binding->receive();
7 if (!($query instanceof \SAML2\AttributeQuery)) {
8  throw new SimpleSAML_Error_BadRequest('Invalid message received to AttributeQuery endpoint.');
9 }
10 
11 $idpEntityId = $metadata->getMetaDataCurrentEntityID('saml20-idp-hosted');
12 
13 
14 $spEntityId = $query->getIssuer();
15 if ($spEntityId === NULL) {
16  throw new SimpleSAML_Error_BadRequest('Missing <saml:Issuer> in <samlp:AttributeQuery>.');
17 }
18 
19 $idpMetadata = $metadata->getMetadataConfig($idpEntityId, 'saml20-idp-hosted');
20 $spMetadata = $metadata->getMetaDataConfig($spEntityId, 'saml20-sp-remote');
21 
22 // The endpoint we should deliver the message to
23 $endpoint = $spMetadata->getString('testAttributeEndpoint');
24 
25 // The attributes we will return
26 $attributes = array(
27  'name' => array('value1', 'value2', 'value3'),
28  'test' => array('test'),
29 );
30 
31 /* The name format of the attributes. */
33 
34 
35 /* Determine which attributes we will return. */
36 $returnAttributes = array_keys($query->getAttributes());
37 if (count($returnAttributes) === 0) {
38  SimpleSAML\Logger::debug('No attributes requested - return all attributes.');
40 
41 } elseif ($query->getAttributeNameFormat() !== $attributeNameFormat) {
42  SimpleSAML\Logger::debug('Requested attributes with wrong NameFormat - no attributes returned.');
43  $returnAttributes = array();
44 } else {
45  foreach ($returnAttributes as $name => $values) {
46  if (!array_key_exists($name, $attributes)) {
47  /* We don't have this attribute. */
48  unset($returnAttributes[$name]);
49  continue;
50  }
51 
52  if (count($values) === 0) {
53  /* Return all attributes. */
55  continue;
56  }
57 
58  /* Filter which attribute values we should return. */
59  $returnAttributes[$name] = array_intersect($values, $attributes[$name]);
60  }
61 }
62 
63 
64 /* $returnAttributes contains the attributes we should return. Send them. */
65 $assertion = new \SAML2\Assertion();
66 $assertion->setIssuer($idpEntityId);
67 $assertion->setNameId($query->getNameId());
68 $assertion->setNotBefore(time());
69 $assertion->setNotOnOrAfter(time() + 5*60);
70 $assertion->setValidAudiences(array($spEntityId));
71 $assertion->setAttributes($returnAttributes);
72 $assertion->setAttributeNameFormat($attributeNameFormat);
73 
74 $sc = new \SAML2\XML\saml\SubjectConfirmation();
76 $sc->SubjectConfirmationData = new \SAML2\XML\saml\SubjectConfirmationData();
77 $sc->SubjectConfirmationData->NotOnOrAfter = time() + 5*60;
78 $sc->SubjectConfirmationData->Recipient = $endpoint;
79 $sc->SubjectConfirmationData->InResponseTo = $query->getId();
80 $assertion->setSubjectConfirmation(array($sc));
81 
83 
84 $response = new \SAML2\Response();
85 $response->setRelayState($query->getRelayState());
86 $response->setDestination($endpoint);
87 $response->setIssuer($idpEntityId);
88 $response->setInResponseTo($query->getId());
89 $response->setAssertions(array($assertion));
91 
92 $binding = new \SAML2\HTTPPost();
93 $binding->send($response);
static getMetadataHandler()
This function retrieves the current instance of the metadata handler.
$binding
$endpoint
static debug($string)
Definition: Logger.php:211
$spEntityId
$sc SubjectConfirmationData
static getCurrentBinding()
Guess the current binding.
Definition: Binding.php:62
$values
const CM_BEARER
Bearer subject confirmation method.
Definition: Constants.php:60
$attributeNameFormat
if($spEntityId===NULL) $idpMetadata
$spMetadata
$response
$query
static addSign(SimpleSAML_Configuration $srcMetadata, SimpleSAML_Configuration $dstMetadata, \SAML2\SignedElement $element)
Add signature key and sender certificate to an element (Message or Assertion).
Definition: Message.php:20
const NAMEFORMAT_UNSPECIFIED
The interpretation of the attribute name is left to individual implementations.
Definition: Constants.php:146
if(!($query instanceof \SAML2\AttributeQuery)) $idpEntityId
$returnAttributes
$metadata
$attributes