protected function validateSubjectConfirmationData(SubjectConfirmationData $subjectConfirmationData) { if ($subjectConfirmationData->getRecipient()) { if (false == Helper::validateWellFormedUriString($subjectConfirmationData->getRecipient())) { throw new LightSamlValidationException('Recipient of SubjectConfirmationData must be a wellformed absolute URI.'); } } if ($subjectConfirmationData->getNotBeforeTimestamp() && $subjectConfirmationData->getNotOnOrAfterTimestamp() && $subjectConfirmationData->getNotBeforeTimestamp() >= $subjectConfirmationData->getNotOnOrAfterTimestamp()) { throw new LightSamlValidationException('SubjectConfirmationData NotBefore MUST be less than NotOnOrAfter'); } }
/** * @param AssertionContext $context * * @return void */ protected function doExecute(AssertionContext $context) { $profileContext = $context->getProfileContext(); $inboundMessage = $profileContext->getInboundContext()->getMessage(); $endpoint = $profileContext->getEndpoint(); $data = new SubjectConfirmationData(); if ($inboundMessage) { $data->setInResponseTo($inboundMessage->getID()); } $data->setAddress($profileContext->getHttpRequest()->getClientIp()); $data->setNotOnOrAfter($this->timeProvider->getTimestamp() + $this->expirationSeconds); $data->setRecipient($endpoint->getLocation()); $subjectConfirmation = new SubjectConfirmation(); $subjectConfirmation->setMethod(SamlConstants::CONFIRMATION_METHOD_BEARER); $subjectConfirmation->setSubjectConfirmationData($data); if (null === $context->getAssertion()->getSubject()) { $context->getAssertion()->setSubject(new Subject()); } $context->getAssertion()->getSubject()->addSubjectConfirmation($subjectConfirmation); }
/** * @expectedException \LightSaml\Error\LightSamlValidationException * @expectedExceptionMessage SubjectConfirmationData NotBefore MUST be less than NotOnOrAfter */ public function test_fails_on_not_on_or_after_less_then_not_before() { $subject = new Subject(); $subjectConfirmationData = new SubjectConfirmationData(); $subjectConfirmationData->setNotOnOrAfter(999)->setNotBefore(1000); $subjectConfirmation = new SubjectConfirmation(); $subjectConfirmation->setMethod(SamlConstants::CONFIRMATION_METHOD_BEARER); $subjectConfirmation->setSubjectConfirmationData($subjectConfirmationData); $subject->addSubjectConfirmation($subjectConfirmation); $validator = new SubjectValidator($this->getNameIdValidatorMock()); $validator->validateSubject($subject); }