<commit_before><?php

/*
 * This file is part of the Active Collab Authentication project.
 *
 * (c) A51 doo <<EMAIL>>. All rights reserved.
 */

namespace ActiveCollab\Authentication\Authorizer;

use ActiveCollab\Authentication\AuthenticatedUser\RepositoryInterface;
use ActiveCollab\Authentication\Exception\UserNotFoundException;
use LightSaml\ClaimTypes;
use LightSaml\Model\Context\DeserializationContext;
use LightSaml\Model\Protocol\Response;

/**
 * @package ActiveCollab\Authentication\Authorizer
 */
class SamlAuthorizer implements AuthorizerInterface
{
    /**
     * @var RepositoryInterface
     */
    private $user_repository;

    /**
     * @param RepositoryInterface $user_repository
     */
    public function __construct(RepositoryInterface $user_repository)
    {
        $this->user_repository = $user_repository;
    }

    /**
     * {@inheritdoc}
     */
    public function verifyCredentials(array $payload)
    {
        $deserialization_context = new DeserializationContext();
        $deserialization_context->getDocument()->loadXML(base64_decode($payload['SAMLResponse']));

        $saml_response = new Response();
        $saml_response->deserialize($deserialization_context->getDocument()->firstChild, $deserialization_context);

        $username = null;

        foreach ($saml_response->getAllAssertions() as $assertion) {
            foreach ($assertion->getAllAttributeStatements() as $statement) {
                $username = $statement->getFirstAttributeByName(ClaimTypes::EMAIL_ADDRESS);
            }
        }

        $user = $this->user_repository->findByUsername($username);

        if (!$user) {
            throw new UserNotFoundException();
        }

        return $user;
    }

    /**
     * {@inheritdoc}
     */
    public function onLogin(array $payload)
    {<commit_msg>Fix accessing attribute value<commit_after><?php

/*
 * This file is part of the Active Collab Authentication project.
 *
 * (c) A51 doo <<EMAIL>>. All rights reserved.
 */

namespace ActiveCollab\Authentication\Authorizer;

use ActiveCollab\Authentication\AuthenticatedUser\RepositoryInterface;
use ActiveCollab\Authentication\Exception\UserNotFoundException;
use LightSaml\ClaimTypes;
use LightSaml\Model\Context\DeserializationContext;
use LightSaml\Model\Protocol\Response;

/**
 * @package ActiveCollab\Authentication\Authorizer
 */
class SamlAuthorizer implements AuthorizerInterface
{
    /**
     * @var RepositoryInterface
     */
    private $user_repository;

    /**
     * @param RepositoryInterface $user_repository
     */
    public function __construct(RepositoryInterface $user_repository)
    {
        $this->user_repository = $user_repository;
    }

    /**
     * {@inheritdoc}
     */
    public function verifyCredentials(array $payload)
    {
        $deserialization_context = new DeserializationContext();
        $deserialization_context->getDocument()->loadXML(base64_decode($payload['SAMLResponse']));

        $saml_response = new Response();
        $saml_response->deserialize($deserialization_context->getDocument()->firstChild, $deserialization_context);

        $username = null;

        foreach ($saml_response->getAllAssertions() as $assertion) {
            foreach ($assertion->getAllAttributeStatements() as $statement) {
                $username = $statement->getFirstAttributeByName(ClaimTypes::EMAIL_ADDRESS);
            }
        }

        $user = $this->user_repository->findByUsername($username->getFirstAttributeValue());

        if (!$user) {
            throw new UserNotFoundException();
        }

        return $user;
    }

    /**
     * {@inheritdoc}
     */
    public function onLogin(array $payload)
    {
{'fraction_non_alphanumeric': 0.11129119394921665, 'fraction_numerical': 0.0021609940572663426, 'mean_word_length': 3.3008130081300813, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 30, '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': '4991029', 'n_tokens_mistral': 1004, 'n_tokens_neox': 986, 'n_words': 181}