<commit_before>package org.jasig.cas.config;

import org.pac4j.cas.client.CasClient;
import org.pac4j.core.config.Config;
import org.pac4j.http.client.direct.DirectBasicAuthClient;
import org.pac4j.http.client.direct.DirectFormClient;
import org.pac4j.http.credentials.authenticator.UsernamePasswordAuthenticator;
import org.pac4j.springframework.web.RequiresAuthenticationInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.view.JstlView;

/**
 * This this {@link OAuthConfiguration}.
 *
 * @author <NAME>
 * @since 4.3.0
 */
@Configuration("oauthConfiguration")
public class OAuthConfiguration {

    /**
     * The Oauth client authenticator.
     */
    @Autowired
    @Qualifier("oAuthUserAuthenticator")
    private UsernamePasswordAuthenticator oAuthClientAuthenticator;

    /**
     * The Cas login url.
     */
    @Value("${server.prefix:http://localhost:8080/cas}/login")
    private String casLoginUrl;

    /**
     * The Callback url.
     */
    @Value("${server.prefix:http://localhost:8080/cas}/oauth2.0/callbackAuthorize")
    private String callbackUrl;

    /**
     * Oauth confirm view jstl view.
     *
     * @return the jstl view
     */
    @Bean(name = "oauthConfirmView")
    public JstlView oauthConfirmView() {
        return new JstlView("/WEB-INF/view/jsp/protocol/oauth/confirm.jsp");
    }

    /**
     * Oauth sec config config.
     *
     * @return the config
     */
    @Bean(name = "oauthSecConfig")
    public Config oauthSecConfig() {
        final CasClient oauthCasClient = new CasClient(this.casLoginUrl);
        oauthCasClient.setName("CasOAuthClient");

        final DirectBasicAuthClient basicAuthClient = new DirectBasicAuthClient(this.oAuthClientAuthenticator);
        basicAuthClient.setName("clientBasicAuth");

        final DirectFormClient directFormClient = new DirectFormClient(this.oAuthClientAuthenticator);
        directFormClient.setName("clientForm");
        directFormClient.setUsernameParameter("client_id");
        directFormClient.setPasswordParameter("<PASSWORD>");

        final DirectFormClient userFormClient = new DirectFormClient(this.oAuthClientAuthenticator);
        userFormClient.setName("userForm");

        return new Config(this.callbackUrl, oauthCasClient, basicAuthClient, directFormClient, userFormClient);
    }

    /**
     * Requires authentication authorize interceptor requires authentication interceptor.
     *
     * @return the requires authentication interceptor
     */
    @Bean(name = "requiresAuthenticationAuthorizeInterceptor")
    public RequiresAuthenticationInterceptor requiresAuthenticationAuthorizeInterceptor() {
        return new RequiresAuthenticationInterceptor(oauthSecConfig(), "CasOAuthClient");
    }

    /**
     * Requires authentication access token interceptor requires authentication interceptor.<commit_msg>fixed oauth test cases<commit_after>package org.jasig.cas.config;

import org.pac4j.cas.client.CasClient;
import org.pac4j.core.config.Config;
import org.pac4j.http.client.direct.DirectBasicAuthClient;
import org.pac4j.http.client.direct.DirectFormClient;
import org.pac4j.http.credentials.authenticator.UsernamePasswordAuthenticator;
import org.pac4j.springframework.web.RequiresAuthenticationInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.view.JstlView;

/**
 * This this {@link OAuthConfiguration}.
 *
 * @author <NAME>
 * @since 4.3.0
 */
@Configuration("oauthConfiguration")
public class OAuthConfiguration {

    /**
     * The Oauth client authenticator.
     */
    @Autowired
    @Qualifier("oAuthUserAuthenticator")
    private UsernamePasswordAuthenticator oAuthUserAuthenticator;

    @Autowired
    @Qualifier("oAuthClientAuthenticator")
    private UsernamePasswordAuthenticator oAuthClientAuthenticator;


    /**
     * The Cas login url.
     */
    @Value("${server.prefix:http://localhost:8080/cas}/login")
    private String casLoginUrl;

    /**
     * The Callback url.
     */
    @Value("${server.prefix:http://localhost:8080/cas}/oauth2.0/callbackAuthorize")
    private String callbackUrl;

    /**
     * Oauth confirm view jstl view.
     *
     * @return the jstl view
     */
    @Bean(name = "oauthConfirmView")
    public JstlView oauthConfirmView() {
        return new JstlView("/WEB-INF/view/jsp/protocol/oauth/confirm.jsp");
    }

    /**
     * Oauth sec config config.
     *
     * @return the config
     */
    @Bean(name = "oauthSecConfig")
    public Config oauthSecConfig() {
        final CasClient oauthCasClient = new CasClient(this.casLoginUrl);
        oauthCasClient.setName("CasOAuthClient");

        final DirectBasicAuthClient basicAuthClient = new DirectBasicAuthClient(this.oAuthClientAuthenticator);
        basicAuthClient.setName("clientBasicAuth");

        final DirectFormClient directFormClient = new DirectFormClient(this.oAuthClientAuthenticator);
        directFormClient.setName("clientForm");
        directFormClient.setUsernameParameter("client_id");
        directFormClient.setPasswordParameter("<PASSWORD>");

        final DirectFormClient userFormClient = new DirectFormClient(this.oAuthUserAuthenticator);
        userFormClient.setName("userForm");

        return new Config(this.callbackUrl, oauthCasClient, basicAuthClient, directFormClient, userFormClient);
    }

    /**
     * Requires authentication authorize interceptor requires authentication interceptor.
     *
     * @return the requires authentication interceptor
     */
    @Bean(name = "requiresAuthenticationAuthorizeInterceptor")
    public RequiresAuthenticationInterceptor requiresAuthenticationAuthorizeInterceptor() {
        return new RequiresAuthenticationInterceptor(oauthSecConfig(), "CasOAuthClient");
    }

    /**
     * Requires authentication access token interceptor requires authentication interceptor.
{'fraction_non_alphanumeric': 0.09942250663336975, 'fraction_numerical': 0.005931012954580927, 'mean_word_length': 4.065612648221344, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '6747416', 'n_tokens_mistral': 1793, 'n_tokens_neox': 1732, 'n_words': 313}