<commit_before><?php
/*
 * This file is part of the SamlBundle.
 *
 * (c) <NAME> <<EMAIL>>
 *
 */
namespace PDias\SamlBundle\DependencyInjection\Security\Factory;

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\DefinitionDecorator;
use Symfony\Component\Config\Definition\Builder\NodeDefinition;

use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\SecurityFactoryInterface;
//use PDias\SamlBundle\Exception\InvalidConfigurationException;

/**
 * @author: <NAME> <<EMAIL>>
 */
class SamlFactory implements SecurityFactoryInterface
{
    public function create(ContainerBuilder $container, $id, $config, $userProvider, $defaultEntryPoint)
    {
        //Provider
        $providerId = 'security.authentication.provider.saml.'.$id;
        $container
            ->setDefinition($providerId, new DefinitionDecorator('saml.security.authentication.provider'))
            ->replaceArgument(0, new Reference($userProvider));

        //Listener
        $listenerId = 'security.authentication.listener.saml.'.$id;
        $listener = $container->setDefinition($listenerId, new DefinitionDecorator('saml.security.authentication.listener'));
		
        $logoutListener = $container->getDefinition('security.logout_listener.'.$id);

        $samlListenerId = 'security.logout.handler.saml';
        $samlListener = $container->setDefinition($samlListenerId, new DefinitionDecorator('saml.security.http.logout'));

        $logoutListener->addMethodCall('addHandler', array(new Reference($samlListenerId)));
        
        return array($providerId, $listenerId, $defaultEntryPoint);
    }

    public function getPosition()
    {
        return 'pre_auth';
    }

    public function getKey()
    {
        return 'saml';
    }

    public function addConfiguration(NodeDefinition $node){ }
}
<commit_msg>Extends AbstractFactory<commit_after><?php
/*
 * This file is part of the SamlBundle.
 *
 * (c) <NAME> <<EMAIL>>
 *
 */
namespace PDias\SamlBundle\DependencyInjection\Security\Factory;

use Symfony\Component\DependencyInjection\ContainerBuilder,
    Symfony\Component\DependencyInjection\Reference,
    Symfony\Component\DependencyInjection\DefinitionDecorator,
    Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\AbstractFactory;

/**
 * @author: <NAME> <<EMAIL>>
 */
class SamlFactory extends AbstractFactory
{
    public function __construct() 
    { 
        $this->addOption('create_user_if_not_exists', false); 
    } 
    
    public function getPosition()
    {
        return 'pre_auth';
    }

    public function getKey()
    {
        return 'saml';
    }
    
    protected function getListenerId() {
        return 'saml.security.authentication.listener';
    }

    protected function createAuthProvider(ContainerBuilder $container, $id, $config, $userProviderId) {
        $authProviderId = 'security.authentication.provider.saml.'.$id;
        $definition =$container
            ->setDefinition($authProviderId, new DefinitionDecorator('saml.security.authentication.provider'))
            ->replaceArgument(0, new Reference($userProviderId));
        
        // with user provider 
        if (isset($config['provider'])) { 
            $definition 
                ->addArgument(new Reference($userProviderId)) 
                ->addArgument(new Reference('security.user_checker')) 
                ->addArgument($config['create_user_if_not_exists']) 
            ; 
        } 

        return $authProviderId;
    }

    protected function createListener($container, $id, $config, $userProvider)
    {
        $listenerId = $this->getListenerId();
        $listener = new DefinitionDecorator($listenerId);
        $listenerId .= '.'.$id;
        $container->setDefinition($listenerId, $listener);
		
        //Logout listener
        $logoutListener = $container->getDefinition('security.logout_listener.'.$id);
        $samlListenerId = 'security.logout.handler.saml';
        
        //Add logout handler
        $container->setDefinition($samlListenerId, new DefinitionDecorator('saml.security.http.logout'));
        $logoutListener->addMethodCall('addHandler', array(new Reference($samlListenerId)));

        return $listenerId;
    }
    
}

{'fraction_non_alphanumeric': 0.12074159907300117, 'fraction_numerical': 0.0004634994206257242, 'mean_word_length': 3.386178861788618, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 32, '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': '930395', 'n_tokens_mistral': 1184, 'n_tokens_neox': 1155, 'n_words': 194}