<commit_before><?php
/**
 * SURFconext EngineBlock
 *
 * LICENSE
 *
 * Copyright 2011 SURFnet bv, The Netherlands
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and limitations under the License.
 *
 * @category  SURFconext EngineBlock
 * @package
 * @copyright Copyright © 2010-2011 SURFnet SURFnet bv, The Netherlands (http://www.surfnet.nl)
 * @license   http://www.apache.org/licenses/LICENSE-2.0  Apache License 2.0
 */

/**
 * Attribute / NameId / Response manipulation / mangling
 */
class EngineBlock_Corto_Filter_Command_RunAttributeManipulations extends EngineBlock_Corto_Filter_Command_Abstract
{
    const TYPE_SP  = 'sp';
    const TYPE_IDP = 'idp';

    private $_type;

    function __construct($type = '')
    {
        assert('in_array($type, array(self::TYPE_SP, self::TYPE_IDP, ""))');
        $this->_type = $type;
    }

    public function getResponse()
    {
        return $this->_response;
    }

    /**
     * This command may modify the response attributes
     *
     * @return array
     */
    public function getResponseAttributes()
    {
        return $this->_responseAttributes;
    }

    public function execute()
    {
        $this->_response['__']['IntendedNameId'] = $this->_collabPersonId;

        $entityId = $this->_type === self::TYPE_IDP ? $this->_response['saml:Issuer']['__v'] : $this->_request['saml:Issuer']['__v'];

        // Try entity specific file based manipulation from Service Registry
        $manipulator = new EngineBlock_Attributes_Manipulator_ServiceRegistry($this->_type);
        $manipulated = $manipulator->manipulate(
            $entityId,
            $this->_response['__']['IntendedNameId'],
            $this->_responseAttributes,
            $this->_response
        );
        if ($manipulated) {
            return true;
        }

        // Legacy: Try file-based general manipulation for all entities of this type
        $manipulator = new EngineBlock_Attributes_Manipulator_File($this->_type);
        $manipulator->manipulate(
            '',
            $this->_response['__']['IntendedNameId'],
            $this->_responseAttributes,
            $this->_response
        );

        // Legacy: Try entity specific file based manipulation
        $manipulator = new EngineBlock_Attributes_Manipulator_File($this->_type);
        $manipulated = $manipulator->manipulate(
            $entityId,
            $this->_response['__']['IntendedNameId'],
            $this->_responseAttributes,
            $this->_response
        );
        if ($manipulated) {
            return true;
        }

        if ($this->_type !== self::TYPE_SP) {
            return false;
        }
        // Legacy legacy: We can have attribute manipulations which were not prefixed with 'sp/'
<commit_msg>BACKLOG-675: Don't even try to execute IdP manipulations for IdPs<commit_after><?php
/**
 * SURFconext EngineBlock
 *
 * LICENSE
 *
 * Copyright 2011 SURFnet bv, The Netherlands
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and limitations under the License.
 *
 * @category  SURFconext EngineBlock
 * @package
 * @copyright Copyright © 2010-2011 SURFnet SURFnet bv, The Netherlands (http://www.surfnet.nl)
 * @license   http://www.apache.org/licenses/LICENSE-2.0  Apache License 2.0
 */

/**
 * Attribute / NameId / Response manipulation / mangling
 */
class EngineBlock_Corto_Filter_Command_RunAttributeManipulations extends EngineBlock_Corto_Filter_Command_Abstract
{
    const TYPE_SP  = 'sp';
    const TYPE_IDP = 'idp';

    private $_type;

    function __construct($type = '')
    {
        assert('in_array($type, array(self::TYPE_SP, self::TYPE_IDP, ""))');
        $this->_type = $type;
    }

    public function getResponse()
    {
        return $this->_response;
    }

    /**
     * This command may modify the response attributes
     *
     * @return array
     */
    public function getResponseAttributes()
    {
        return $this->_responseAttributes;
    }

    public function execute()
    {
        $this->_response['__']['IntendedNameId'] = $this->_collabPersonId;

        $entityId = ($this->_type === self::TYPE_IDP) ?
            $this->_response['saml:Issuer']['__v'] :
            $this->_request['saml:Issuer']['__v'];

        // Try entity specific file based manipulation from Service Registry
        $manipulator = new EngineBlock_Attributes_Manipulator_ServiceRegistry($this->_type);
        $manipulated = $manipulator->manipulate(
            $entityId,
            $this->_response['__']['IntendedNameId'],
            $this->_responseAttributes,
            $this->_response
        );
        if ($manipulated) {
            return true;
        }

        // IdP Manipulations can only come from the Service Registry,
        // but for SP manipulations we still support file based manipulations.
        if ($this->_type !== self::TYPE_SP) {
            return false;
        }

        // Legacy: Try file-based general manipulation for all entities of this type
        $manipulator = new EngineBlock_Attributes_Manipulator_File($this->_type);
        $manipulator->manipulate(
            '',
            $this->_response['__']['IntendedNameId'],
            $this->_responseAttributes,
            $this->_response
        );

        // Legacy: Try entity specific file based manipulation
        $manipulator = new EngineBlock_Attributes_Manipulator_File($this->_type);
        $manipulated = $manipulator->manipulate(
            $entityId,
            $this->_response['__']['IntendedNameId'],
            $this->_responseAttributes,
            $this->_response
        );
        if ($manipulated) {
            return true;
        }

        // Legacy legacy: We can have attribute manipulations which were not prefixed with 'sp/'

{'fraction_non_alphanumeric': 0.11016696481812761, 'fraction_numerical': 0.00641025641025641, 'mean_word_length': 2.6304112554112553, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 51, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, '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': '1891653', 'n_tokens_mistral': 1860, 'n_tokens_neox': 1783, 'n_words': 504}