<commit_before><?php
/**
 * NOTE: use for testing only!
 *
 * @todo write test
 */
class EngineBlock_Saml_ResponseFactory
{
    /**
     * @todo make this generic
     *
     * @param SAML2_AuthnRequest $authnRequest
     * @return SAML2_Response
     */
    public function create(
        SAML2_AuthnRequest $authnRequest
    )
    {
        $sspIdpConfig = array();
        $sspIdpConfig['privatekey'] = ENGINEBLOCK_FOLDER_APPLICATION . 'modules/DummyIdp/keys/private_key.pem';
        $sspIdpConfig['certData'] = file_get_contents(ENGINEBLOCK_FOLDER_APPLICATION . 'modules/DummyIdp/keys/certificate.crt');
        $idpMetadata = new SimpleSAML_Configuration($sspIdpConfig, null);

        $spMetadata = new SimpleSAML_Configuration(array(), null);

        $issuer = $_SERVER['SCRIPT_URI'];

        /* $returnAttributes contains the attributes we should return. Send them. */
        $assertion = new SAML2_Assertion();
        $assertion->setIssuer($issuer);
        // @todo get this from constant
        $assertion->setNameId(array(
            'Value' => 'johndoe',
            'Format' => "urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified"
        ));
        $assertion->setNotBefore(time());
        $assertion->setNotOnOrAfter(time() + 5*60);
        // Valid audiences is not required so disabled for now
        // $assertion->setValidAudiences(array($authnRequest->getIssuer()));

        // Add a few required attributes
        $returnAttributes = array(
            'urn:mace:dir:attribute-def:uid' => array('johndoe'),
            'urn:mace:terena.org:attribute-def:schacHomeOrganization' => array('example.com'),
        );
        $assertion->setAttributes($returnAttributes);
        $assertion->setAttributeNameFormat(SAML2_Const::NAMEFORMAT_UNSPECIFIED);
        $assertion->setAuthnContext(' urn:oasis:names:tc:SAML:2.0:ac:classes:Password');

        $subjectConfirmation = new SAML2_XML_saml_SubjectConfirmation();
        $subjectConfirmation->Method = SAML2_Const::CM_BEARER;
        $subjectConfirmation->SubjectConfirmationData = new SAML2_XML_saml_SubjectConfirmationData();
        $subjectConfirmation->SubjectConfirmationData->NotOnOrAfter = time() + 5*60;
        $subjectConfirmation->SubjectConfirmationData->Recipient = $authnRequest->getAssertionConsumerServiceURL();
        $subjectConfirmation->SubjectConfirmationData->InResponseTo = $authnRequest->getId();
        $assertion->setSubjectConfirmation(array($subjectConfirmation));
        sspmod_saml_Message::addSign($idpMetadata, $spMetadata, $assertion);

        $response = new SAML2_Response();<commit_msg>BACKLOG-1048 Replaced hardcoded default values with constants<commit_after><?php
/**
 * NOTE: use for testing only!
 *
 * @todo write test
 */
class EngineBlock_Saml_ResponseFactory
{
    /**
     * @todo make this generic
     *
     * @param SAML2_AuthnRequest $authnRequest
     * @return SAML2_Response
     */
    public function create(
        SAML2_AuthnRequest $authnRequest
    )
    {
        $sspIdpConfig = array();
        $sspIdpConfig['privatekey'] = ENGINEBLOCK_FOLDER_APPLICATION . 'modules/DummyIdp/keys/private_key.pem';
        $sspIdpConfig['certData'] = file_get_contents(ENGINEBLOCK_FOLDER_APPLICATION . 'modules/DummyIdp/keys/certificate.crt');
        $idpMetadata = new SimpleSAML_Configuration($sspIdpConfig, null);

        $spMetadata = new SimpleSAML_Configuration(array(), null);

        $issuer = $_SERVER['SCRIPT_URI'];

        /* $returnAttributes contains the attributes we should return. Send them. */
        $assertion = new SAML2_Assertion();
        $assertion->setIssuer($issuer);
        // @todo get this from constant
        $assertion->setNameId(array(
            'Value' => 'johndoe',
            'Format' => self::NAMEID_UNSPECIFIED
        ));
        $assertion->setNotBefore(time());
        $assertion->setNotOnOrAfter(time() + 5*60);
        // Valid audiences is not required so disabled for now
        // $assertion->setValidAudiences(array($authnRequest->getIssuer()));

        // Add a few required attributes
        $returnAttributes = array(
            'urn:mace:dir:attribute-def:uid' => array('johndoe'),
            'urn:mace:terena.org:attribute-def:schacHomeOrganization' => array('example.com'),
        );
        $assertion->setAttributes($returnAttributes);
        $assertion->setAttributeNameFormat(SAML2_Const::NAMEFORMAT_UNSPECIFIED);
        $assertion->setAuthnContext(SAML2_Const::AC_PASSWORD);

        $subjectConfirmation = new SAML2_XML_saml_SubjectConfirmation();
        $subjectConfirmation->Method = SAML2_Const::CM_BEARER;
        $subjectConfirmation->SubjectConfirmationData = new SAML2_XML_saml_SubjectConfirmationData();
        $subjectConfirmation->SubjectConfirmationData->NotOnOrAfter = time() + 5*60;
        $subjectConfirmation->SubjectConfirmationData->Recipient = $authnRequest->getAssertionConsumerServiceURL();
        $subjectConfirmation->SubjectConfirmationData->InResponseTo = $authnRequest->getId();
        $assertion->setSubjectConfirmation(array($subjectConfirmation));
        sspmod_saml_Message::addSign($idpMetadata, $spMetadata, $assertion);

        $response = new SAML2_Response();
{'fraction_non_alphanumeric': 0.12171746214299406, 'fraction_numerical': 0.007475560667050029, 'mean_word_length': 3.57719298245614, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 51, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3510690', 'n_tokens_mistral': 1614, 'n_tokens_neox': 1550, 'n_words': 236}