protected function _createBaseResponse(EngineBlock_Saml2_AuthnRequestAnnotationDecorator $request)
 {
     if ($request->getVoContext() && $request->isVoContextExplicit()) {
         $this->setVirtualOrganisationContext($request->getVoContext());
     }
     if ($keyId = $request->getKeyId()) {
         $this->setKeyId($keyId);
     }
     $requestWasUnsolicited = $request->isUnsolicited();
     $response = new SAML2_Response();
     /** @var SAML2_AuthnRequest $request */
     $response->setRelayState($request->getRelayState());
     $response->setId($this->getNewId(IdFrame::ID_USAGE_SAML2_RESPONSE));
     $response->setIssueInstant(time());
     if (!$requestWasUnsolicited) {
         $response->setInResponseTo($request->getId());
     }
     $response->setDestination($request->getIssuer());
     $response->setIssuer($this->getUrl('idpMetadataService', $request->getIssuer(), $request));
     $acs = $this->getRequestAssertionConsumer($request);
     $response->setDestination($acs->location);
     $response->setStatus(array('Code' => SAML2_Const::STATUS_SUCCESS));
     $response = new EngineBlock_Saml2_ResponseAnnotationDecorator($response);
     $response->setDeliverByBinding($acs->binding);
     return $response;
 }
 private static function combine_response(array $values, \SAML2_Response $response = NULL)
 {
     if (!isset($response)) {
         $response = new \SAML2_Response();
     }
     $presented_assertions = $response->getAssertions();
     $assertion = empty($presented_assertions) ? new \SAML2_Assertion() : $presented_assertions[0];
     if (self::original_spid_isset($values)) {
         $response->setInResponseTo($values['InResponseTo']);
     }
     if (array_key_exists('ResponseID', $values)) {
         $response->setId($values['ResponseID']);
     }
     if (array_key_exists('AssertionID', $values)) {
         $assertion->setId($values['AssertionID']);
     }
     if (array_key_exists('Issuer', $values)) {
         $response->setIssuer($values['Issuer']);
         $assertion->setIssuer($values['Issuer']);
     }
     if (array_key_exists('NameID', $values)) {
         $assertion->setNameId(self::build_name_id($values['NameID']));
     }
     $not_on_or_after_time = time();
     if (array_key_exists('AllowedTimeDelta', $values)) {
         $not_on_or_after_time += $values['AllowedTimeDelta'];
         $assertion->setNotBefore(time() - $values['AllowedTimeDelta']);
         $assertion->setNotOnOrAfter($not_on_or_after_time);
     } else {
         $not_on_or_after_time += DEFAULT_RESPONSE_TIME_DELTA;
     }
     if (array_key_exists('Audience', $values)) {
         $assertion->setValidAudiences(array($values['Audience']));
     }
     if (array_key_exists('Attributes', $values)) {
         $assertion->setAttributes($values['Attributes']);
     }
     $assertion->setAuthnInstant(time());
     if (array_key_exists('AuthnContextClassRef', $values)) {
         $assertion->setAuthnContextClassRef($values['AuthnContextClassRef']);
     }
     if (array_key_exists('SessionIndex', $values)) {
         $assertion->setSessionIndex($values['SessionIndex']);
     }
     if (self::original_spid_isset($values) || array_key_exists('Destination', $values)) {
         $original_confirmations = $assertion->getSubjectConfirmation();
         $confirmation = NULL;
         if (empty($original_confirmations)) {
             $confirmation = new \SAML2_XML_saml_SubjectConfirmation();
             $confirmation->Method = SAML_CONFIGURATION_METHOD;
         } else {
             $confirmation = $original_confirmations[0];
         }
         $original_data = $confirmation->SubjectConfirmationData;
         $data = NULL;
         if (empty($original_data)) {
             $data = new \SAML2_XML_saml_SubjectConfirmationData();
             $data->NotOnOrAfter = $not_on_or_after_time;
         } else {
             $data = $original_data;
             if (empty($data->NotOnOrAfter)) {
                 $data->NotOnOrAfter = $not_on_or_after_time;
             }
         }
         if (array_key_exists('Destination', $values)) {
             $data->Recipient = $values['Destination'];
         }
         if (self::original_spid_isset($values)) {
             $data->InResponseTo = $values['InResponseTo'];
         }
         $confirmation->SubjectConfirmationData = $data;
         $assertion->setSubjectConfirmation(array($confirmation));
     }
     if (array_key_exists('Destination', $values)) {
         $response->setDestination($values['Destination']);
     }
     if (self::need_sign($values)) {
         if (array_key_exists('SHA256KeyFile', $values)) {
             $ekey = new \XMLSecurityKey(\XMLSecurityKey::RSA_SHA256, array('type' => 'private'));
             $ekey->loadKey($values['SHA256KeyFile'], true);
             if (self::need_sign_attributes($values)) {
                 $assertion->setSignatureKey($ekey);
             }
             if (self::need_sign_message($values)) {
                 $response->setSignatureKey($ekey);
             }
         }
         if (array_key_exists('SHA256CertFile', $values)) {
             $certifictaes = array(file_get_contents($values['SHA256CertFile']));
             if (self::need_sign_attributes($values)) {
                 $assertion->setCertificates($certifictaes);
             }
             if (self::need_sign_message($values)) {
                 $response->setCertificates($certifictaes);
             }
         }
     }
     $response->setAssertions(array($assertion));
     return $response;
 }