<commit_before>package org.pac4j.core.client;

import org.pac4j.async.core.profile.definition.ProfileDefinitionAware;
import org.pac4j.core.context.WebContextBase;
import org.pac4j.core.credentials.Credentials;
import org.pac4j.core.profile.CommonProfile;
import org.pac4j.core.util.CommonHelper;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * Common base client for both async and sync clients, the sync/async base clients should inherit from
 * Type parameters are as follows:-
 * C = credentials implementor
 * U = profile implementor
 * WC = web context implementor (typically WebContext or AsyncWebContext)
 * AG = authorization generator implementor (typically AuthorizationGenerator or AsyncAuthorizationGenerator)
 */
public abstract class CommonBaseClient<C extends Credentials, U extends CommonProfile, WC extends WebContextBase<?>, AG>
        extends ProfileDefinitionAware <U>{

    private String name;
    protected List<AG> authorizationGenerators = new ArrayList<>();

    public void setName(final String name) {
        this.name = name;
    }

    public String getName() {
        if (CommonHelper.isBlank(this.name)) {
            return this.getClass().getSimpleName();
        }
        return this.name;
    }

    /**
     * Notify of the web session renewal.
     *
     * @param oldSessionId the old session identifier
     * @param context the web context
     */
    public void notifySessionRenewal(final String oldSessionId, final WC context) { }

    public List<AG> getAuthorizationGenerators() {
        return this.authorizationGenerators;
    }

    public void setAuthorizationGenerators(final List<AG> authorizationGenerators) {
        CommonHelper.assertNotNull("authorizationGenerators", authorizationGenerators);
        this.authorizationGenerators = authorizationGenerators;
    }

    public void setAuthorizationGenerators(final AG... authorizationGenerators) {
        CommonHelper.assertNotNull("authorizationGenerators", authorizationGenerators);
        this.authorizationGenerators = Arrays.asList(authorizationGenerators);
    }

    /**
     * Add an authorization generator.
     *
     * @param authorizationGenerator an authorizations generator
     */
    public void setAuthorizationGenerator(final AG authorizationGenerator) {
        addAuthorizationGenerator(authorizationGenerator);
    }

    public void addAuthorizationGenerator(final AG authorizationGenerator) {
        CommonHelper.assertNotNull("authorizationGenerator", authorizationGenerator);
        this.authorizationGenerators.add(authorizationGenerator);
    }

    public void addAuthorizationGenerators(final List<AG> authorizationGenerators) {
        CommonHelper.assertNotNull("authorizationGenerators", authorizationGenerators);
        this.authorizationGenerators.addAll(authorizationGenerators);
    }

    @Override
    public String toString() {
        return CommonHelper.toString(this.getClass(), "name", getName(),
                "authorizationGenerators", authorizationGenerators);
    }

}<commit_msg>pac4j-async-138 Add async-friendly CredentialsExtractor definition to CommonBaseClient<commit_after>package org.pac4j.core.client;

import org.pac4j.async.core.profile.definition.ProfileDefinitionAware;
import org.pac4j.core.context.WebContextBase;
import org.pac4j.core.credentials.Credentials;
import org.pac4j.core.credentials.extractor.CredentialsExtractor;
import org.pac4j.core.profile.CommonProfile;
import org.pac4j.core.util.CommonHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * Common base client for both async and sync clients, the sync/async base clients should inherit from
 * Type parameters are as follows:-
 * C = credentials implementor
 * U = profile implementor
 * WC = web context implementor (typically WebContext or AsyncWebContext)
 * AG = authorization generator implementor (typically AuthorizationGenerator or AsyncAuthorizationGenerator)
 */
public abstract class CommonBaseClient<C extends Credentials, U extends CommonProfile, WC extends WebContextBase<?>, AG>
        extends ProfileDefinitionAware <U>{

    private static final Logger logger = LoggerFactory.getLogger(CommonBaseClient.class);

    private String name;
    protected List<AG> authorizationGenerators = new ArrayList<>();
    private CredentialsExtractor<C, WC> credentialsExtractor;

    public void setName(final String name) {
        this.name = name;
    }

    public String getName() {
        if (CommonHelper.isBlank(this.name)) {
            return this.getClass().getSimpleName();
        }
        return this.name;
    }

    /**
     * Notify of the web session renewal.
     *
     * @param oldSessionId the old session identifier
     * @param context the web context
     */
    public void notifySessionRenewal(final String oldSessionId, final WC context) { }

    public List<AG> getAuthorizationGenerators() {
        return this.authorizationGenerators;
    }

    public void setAuthorizationGenerators(final List<AG> authorizationGenerators) {
        CommonHelper.assertNotNull("authorizationGenerators", authorizationGenerators);
        this.authorizationGenerators = authorizationGenerators;
    }

    public void setAuthorizationGenerators(final AG... authorizationGenerators) {
        CommonHelper.assertNotNull("authorizationGenerators", authorizationGenerators);
        this.authorizationGenerators = Arrays.asList(authorizationGenerators);
    }

    /**
     * Add an authorization generator.
     *
     * @param authorizationGenerator an authorizations generator
     */
    public void setAuthorizationGenerator(final AG authorizationGenerator) {
        addAuthorizationGenerator(authorizationGenerator);
    }

    public void addAuthorizationGenerator(final AG authorizationGenerator) {
        CommonHelper.assertNotNull("authorizationGenerator", authorizationGenerator);
        this.authorizationGenerators.add(authorizationGenerator);
    }

    public void addAuthorizationGenerators(final List<AG> authorizationGenerators) {
        CommonHelper.assertNotNull("authorizationGenerators", authorizationGenerators);
        this.authorizationGenerators.addAll(authorizationGenerators);
    }

    public CredentialsExtractor<C, WC> getCredentialsExtractor() {
        return credentialsExtractor;
    }

    protected void defaultCredentialsExtractor(final CredentialsExtractor<C, WC> credentialsExtractor) {
        if (this.credentialsExtractor == null) {
            this.credentialsExtractor = credentialsExtractor;
        }
    }

    public void setCredentialsExtractor(final CredentialsExtractor<C, WC> credentialsExtractor) {
        this.credentialsExtractor = credentialsExtractor;
    }

    @Override
    public String toString() {
        return CommonHelper.toString(this.getClass(), "name", getName(),
                "authorizationGenerators", authorizationGenerators);
    }

}
{'fraction_non_alphanumeric': 0.07944191343963554, 'fraction_numerical': 0.00270501138952164, 'mean_word_length': 4.014275517487509, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, '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': '5327597', 'n_tokens_mistral': 1795, 'n_tokens_neox': 1736, 'n_words': 427}