public static function createFrom(SAML2_Assertion $assertion, AttributeDictionary $attributeDictionary) { $attributeSet = new AttributeSet(); foreach ($assertion->getAttributes() as $urn => $attributeValue) { $attribute = new Attribute($attributeDictionary->getAttributeDefinitionByUrn($urn), $attributeValue); $attributeSet->initializeWith($attribute); } return $attributeSet; }
/** * @param ConsentList $consentList * @param AttributeSetInterface $attributeSet * @return SpecifiedConsentList * @SuppressWarnings(PHPMD.NPathComplexity) Build and mapping logic causes complexity */ public function applyAttributeReleasePolicies(ConsentList $consentList, AttributeSetInterface $attributeSet) { $entityIds = $consentList->map(function (Consent $consent) { return $consent->getServiceProvider()->getEntity()->getEntityId()->getEntityId(); }); $mappedAttributes = []; foreach ($attributeSet as $attribute) { $mace = $attribute->getAttributeDefinition()->getUrnMace(); $oid = $attribute->getAttributeDefinition()->getUrnOid(); if ($mace !== null) { $mappedAttributes[$mace] = $attribute->getValue(); } if ($oid !== null) { $mappedAttributes[$oid] = $attribute->getValue(); } } $data = ['entityIds' => $entityIds, 'attributes' => !empty($mappedAttributes) ? $mappedAttributes : new stdClass()]; $response = $this->jsonApiClient->post($data, '/arp'); $specifiedConsents = $consentList->map(function (Consent $consent) use($response) { $entityId = $consent->getServiceProvider()->getEntity()->getEntityId()->getEntityId(); if (!isset($response[$entityId])) { throw new InvalidResponseException(sprintf('EntityID "%s" was not found in the ARP response (entityIDs: %s)', $entityId, join(', ', array_keys($response)))); } $attributes = []; foreach ($response[$entityId] as $attributeName => $attributeValue) { try { $attributeDefinition = $this->attributeDictionary->getAttributeDefinitionByUrn($attributeName); } catch (UnknownUrnException $exception) { $attributeDefinition = new AttributeDefinition($attributeName, $attributeName, $attributeName); } $attribute = new Attribute($attributeDefinition, $attributeValue); if (!in_array($attribute, $attributes)) { $attributes[] = $attribute; } } return SpecifiedConsent::specifies($consent, AttributeSetWithFallbacks::create($attributes)); }); return SpecifiedConsentList::createWith($specifiedConsents); }
public static function createFrom(SAML2_Assertion $assertion, AttributeDictionary $attributeDictionary) { $attributeSet = new AttributeSetWithFallbacks(); foreach ($assertion->getAttributes() as $urn => $attributeValue) { try { $attributeDefinition = $attributeDictionary->getAttributeDefinitionByUrn($urn); } catch (UnknownUrnException $exception) { $attributeDefinition = new AttributeDefinition($urn, $urn, $urn); } $attributeSet->initializeWith(new Attribute($attributeDefinition, $attributeValue)); } return $attributeSet; }