<commit_before>package com.intive.patronage.toz.tokens.auth;

import com.intive.patronage.toz.config.ApiUrl;
import com.intive.patronage.toz.tokens.auth.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;

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

@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
class WebSecurityConfig extends WebSecurityConfigurerAdapter {

    private static final String REST_ENTRY_POINT = "/**";
    private static final String ADMIN_ENTRY_POINT = "/admin/**";

    private final SuperAdminAuthenticationProvider superAdminAuthenticationProvider;
    private final JwtAuthenticationProvider jwtAuthenticationProvider;

    @Autowired
    public WebSecurityConfig(SuperAdminAuthenticationProvider superAdminAuthenticationProvider, JwtAuthenticationProvider jwtAuthenticationProvider) {
        this.superAdminAuthenticationProvider = superAdminAuthenticationProvider;
        this.jwtAuthenticationProvider = jwtAuthenticationProvider;
    }

    private TokenAuthenticationFilter getAuthenticationFilter() throws Exception {
        final List<String> pathsToSkip = Arrays.asList(ApiUrl.ACQUIRE_TOKEN_PATH, ADMIN_ENTRY_POINT);
        final AuthenticationRequestMatcher matcher = new AuthenticationRequestMatcher(pathsToSkip);
        final TokenAuthenticationFilter filter =
                new TokenAuthenticationFilter(new TokenAuthenticationFailureHandler(), matcher);
        filter.setAuthenticationManager(authenticationManager());

        return filter;
    }

    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth.authenticationProvider(superAdminAuthenticationProvider);
        auth.authenticationProvider(jwtAuthenticationProvider);
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.csrf().disable()
                .exceptionHandling().authenticationEntryPoint(new UnauthorizedEntryPoint())
                .and().sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
                .and().authorizeRequests().antMatchers(ApiUrl.ACQUIRE_TOKEN_PATH).permitAll()
                .and().authorizeRequests().antMatchers(REST_ENTRY_POINT).authenticated()
                .and().authorizeRequests().antMatchers(ADMIN_ENTRY_POINT).authenticated()
                .and().httpBasic()
                .and().headers().frameOptions().disable()
                .and().addFilterBefore(getAuthenticationFilter(), UsernamePasswordAuthenticationFilter.class);
    }
}
<commit_msg>disables creating default basic auth user (#71)<commit_after>package com.intive.patronage.toz.tokens.auth;

import com.intive.patronage.toz.config.ApiUrl;
import com.intive.patronage.toz.tokens.auth.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;

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

@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
class WebSecurityConfig extends WebSecurityConfigurerAdapter {

    private static final String REST_ENTRY_POINT = "/**";
    private static final String ADMIN_ENTRY_POINT = "/admin/**";

    private final SuperAdminAuthenticationProvider superAdminAuthenticationProvider;
    private final JwtAuthenticationProvider jwtAuthenticationProvider;

    @Autowired
    public WebSecurityConfig(SuperAdminAuthenticationProvider superAdminAuthenticationProvider, JwtAuthenticationProvider jwtAuthenticationProvider) {
        this.superAdminAuthenticationProvider = superAdminAuthenticationProvider;
        this.jwtAuthenticationProvider = jwtAuthenticationProvider;
    }

    private TokenAuthenticationFilter getAuthenticationFilter() throws Exception {
        final List<String> pathsToSkip = Arrays.asList(ApiUrl.ACQUIRE_TOKEN_PATH, ADMIN_ENTRY_POINT);
        final AuthenticationRequestMatcher matcher = new AuthenticationRequestMatcher(pathsToSkip);
        final TokenAuthenticationFilter filter =
                new TokenAuthenticationFilter(new TokenAuthenticationFailureHandler(), matcher);
        filter.setAuthenticationManager(authenticationManager());

        return filter;
    }

    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth.authenticationProvider(superAdminAuthenticationProvider);
        auth.authenticationProvider(jwtAuthenticationProvider);
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.csrf().disable()
                .exceptionHandling().authenticationEntryPoint(new UnauthorizedEntryPoint())
                .and().sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
                .and().authorizeRequests().antMatchers(ApiUrl.ACQUIRE_TOKEN_PATH).permitAll()
                .and().authorizeRequests().antMatchers(REST_ENTRY_POINT).authenticated()
                .and().authorizeRequests().antMatchers(ADMIN_ENTRY_POINT).authenticated()
                .and().httpBasic()
                .and().headers().frameOptions().disable()
                .and().addFilterBefore(getAuthenticationFilter(), UsernamePasswordAuthenticationFilter.class);
    }

    @Bean
    public AuthenticationManager authenticationManagerBean() throws Exception {
        return super.authenticationManagerBean();
    }
}

{'fraction_non_alphanumeric': 0.08085784668888567, 'fraction_numerical': 0.0002898130705694827, 'mean_word_length': 5.059701492537314, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '4443540', 'n_tokens_mistral': 1599, 'n_tokens_neox': 1566, 'n_words': 252}