package org.laladev.moneyjinn.server.jwt;

import javax.inject.Inject;

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.configuration.AuthenticationConfiguration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.web.SecurityFilterChain;

@Configuration
public class SecurityConfig {
	@Inject
	JwtTokenProvider jwtTokenProvider;

	@Bean
	public AuthenticationManager authenticationManager(final AuthenticationConfiguration authenticationConfiguration)
			throws Exception {
		return authenticationConfiguration.getAuthenticationManager();
	}

	@Bean
	public PasswordEncoder getPasswordEncoder() {
		return new BCryptPasswordEncoder();
	}

	@Bean
	public SecurityFilterChain securityFilterChain(final HttpSecurity http) throws Exception {
		//@formatter:off
        http
            .httpBasic().disable()
            .csrf().disable()
            .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
            .and()
                .authorizeRequests()
                .antMatchers("/moneyflow/server/user/login").permitAll()
                .antMatchers("/moneyflow/server/user/test").authenticated()
                .antMatchers("/moneyflow/server/report/getAvailableMonth**").authenticated()
                .antMatchers("/**").permitAll()
                .anyRequest().authenticated()
            .and()
            .apply(new JwtConfigurer(this.jwtTokenProvider));
        //@formatter:on
		return http.build();
	}
}
@@ -170,32 +170,76 @@
 .Configuration;%0A
+import org.springframework.http.HttpMethod;%0A
 import org.sprin
@@ -1504,16 +1504,100 @@
 uests()%0A
+                .antMatchers(HttpMethod.OPTIONS,%22/moneyflow/server/**%22).permitAll()%0A
         
@@ -1729,32 +1729,123 @@
 authenticated()%0A
+                .antMatchers(%22/moneyflow/server/report/getAvailableMonth%22).authenticated()%0A
                 

permit all OPTIONS