<commit_before>package org.carlspring.strongbox.config;

import javax.annotation.PostConstruct;

import org.carlspring.strongbox.security.authentication.CustomAnonymousAuthenticationFilter;
import org.carlspring.strongbox.security.authentication.Http401AuthenticationEntryPoint;
import org.carlspring.strongbox.security.authentication.JWTAuthenticationFilter;
import org.carlspring.strongbox.security.authentication.JWtAuthenticationProvider;
import org.carlspring.strongbox.users.security.AuthorizationConfigProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import org.springframework.security.authentication.AuthenticationProvider;
import org.springframework.security.authentication.dao.DaoAuthenticationProvider;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.method.configuration.GlobalMethodSecurityConfiguration;
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.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.web.authentication.AnonymousAuthenticationFilter;
import org.springframework.security.web.authentication.www.BasicAuthenticationFilter;
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;

@Configuration
@EnableWebSecurity
public class SecurityConfig
        extends WebSecurityConfigurerAdapter
{

    /**
     * This Configuration enables @PreAuthorize annotations
     * 
     * @author <NAME>
     *
     */
    @Configuration
    @EnableGlobalMethodSecurity(prePostEnabled = true)
    public static class MethodSecurityConfig extends GlobalMethodSecurityConfiguration
    {

    }

    @Autowired
    public void configureGlobal(AuthenticationManagerBuilder auth,
                                @Qualifier("userDetailsAuthenticationProvider") AuthenticationProvider userDetailsAuthenticationProvider,
                                @Qualifier("jwtAuthenticationProvider") AuthenticationProvider jwtAuthenticationProvider)
    {
        auth.authenticationProvider(userDetailsAuthenticationProvider)
            .authenticationProvider(jwtAuthenticationProvider)
            .eraseCredentials(false);

    }

    /**
     * This configuration specifies BasicAuthentication rules. Such authentication triggered first and only for concrete
     * set of URL patterns. All the other authentication configured in {@link JwtSecurityConfig}
     *
     * @author <NAME>
     */
    @Configuration
    @Order(1)
    public static class BasicSecurityConfig
            extends WebSecurityConfigurerAdapter
    {

        @Override
        protected void configure(HttpSecurity http)
                throws Exception
        {
            http.sessionManagement()
                .sessionCreationPolicy(SessionCreationPolicy.STATELESS)
                .and()
                .requestMatchers()
                .antMatchers("/users/user/authenticate", "/storages/**/*")
                .and()
                .authorizeRequests()
                .anyRequest()
                .authenticated()
                .and()
                .httpBasic()<commit_msg>SB-515: Fix for Integrtion tests2<commit_after>package org.carlspring.strongbox.config;

import javax.annotation.PostConstruct;

import org.carlspring.strongbox.security.authentication.CustomAnonymousAuthenticationFilter;
import org.carlspring.strongbox.security.authentication.Http401AuthenticationEntryPoint;
import org.carlspring.strongbox.security.authentication.JWTAuthenticationFilter;
import org.carlspring.strongbox.security.authentication.JWtAuthenticationProvider;
import org.carlspring.strongbox.users.security.AuthorizationConfigProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import org.springframework.security.authentication.AuthenticationProvider;
import org.springframework.security.authentication.dao.DaoAuthenticationProvider;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.method.configuration.GlobalMethodSecurityConfiguration;
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.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.web.authentication.AnonymousAuthenticationFilter;
import org.springframework.security.web.authentication.www.BasicAuthenticationFilter;
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;

@Configuration
@EnableWebSecurity
public class SecurityConfig
        extends WebSecurityConfigurerAdapter
{

    /**
     * This Configuration enables @PreAuthorize annotations
     * 
     * @author <NAME>
     *
     */
    @Configuration
    @EnableGlobalMethodSecurity(prePostEnabled = true)
    public static class MethodSecurityConfig extends GlobalMethodSecurityConfiguration
    {

    }

    @Autowired
    public void configureGlobal(AuthenticationManagerBuilder auth,
                                @Qualifier("userDetailsAuthenticationProvider") AuthenticationProvider userDetailsAuthenticationProvider,
                                @Qualifier("jwtAuthenticationProvider") AuthenticationProvider jwtAuthenticationProvider)
    {
        auth.authenticationProvider(userDetailsAuthenticationProvider)
            .authenticationProvider(jwtAuthenticationProvider)
            .eraseCredentials(false);

    }

    /**
     * This configuration specifies BasicAuthentication rules. Such authentication triggered first and only for concrete
     * set of URL patterns. All the other authentication configured in {@link JwtSecurityConfig}
     *
     * @author <NAME>
     */
    @Configuration
    @Order(1)
    public static class BasicSecurityConfig
            extends WebSecurityConfigurerAdapter
    {

        @Override
        protected void configure(HttpSecurity http)
                throws Exception
        {
            http.sessionManagement()
                .sessionCreationPolicy(SessionCreationPolicy.STATELESS)
                .and()
                .requestMatchers()
                .antMatchers("/users/user/authenticate", "/storages/**/*", "/trash/**/*")
                .and()
                .authorizeRequests()
                .anyRequest()
                .authenticated()
                .and()
                .httpBasic()
{'fraction_non_alphanumeric': 0.07524676323548263, 'fraction_numerical': 0.0015382643250865273, 'mean_word_length': 4.02059202059202, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '5567178', 'n_tokens_mistral': 1771, 'n_tokens_neox': 1735, 'n_words': 290}