1package com.student_loan.config;
5import org.springframework.context.annotation.Bean;
6import org.springframework.context.annotation.Configuration;
7import org.springframework.context.annotation.Profile;
8import org.springframework.security.config.annotation.web.builders.HttpSecurity;
9import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
10import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
11import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
12import org.springframework.security.web.SecurityFilterChain;
13import org.springframework.web.cors.CorsConfiguration;
14import org.springframework.web.cors.CorsConfigurationSource;
15import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
17import com.student_loan.security.JwtFilter;
18import com.student_loan.security.JwtUtil;
25 private final JwtUtil jwtUtil;
28 this.jwtUtil = jwtUtil;
33 return new BCryptPasswordEncoder();
38 CorsConfiguration cfg =
new CorsConfiguration();
39 cfg.setAllowedOrigins(List.of(
"http://localhost:3000"));
40 cfg.setAllowedMethods(List.of(
"GET",
"POST",
"PUT",
"DELETE",
"OPTIONS"));
41 cfg.setAllowedHeaders(List.of(
"Authorization",
"Content-Type"));
42 cfg.setAllowCredentials(
true);
44 UrlBasedCorsConfigurationSource source =
new UrlBasedCorsConfigurationSource();
45 source.registerCorsConfiguration(
"/**", cfg);
54 .authorizeHttpRequests(auth -> auth
63 .anyRequest().authenticated()
66 new JwtFilter(jwtUtil),
67 UsernamePasswordAuthenticationFilter.class
BCryptPasswordEncoder bCryptPasswordEncoder()
SecurityFilterChain securityFilterChain(HttpSecurity http)
SecurityConfig(JwtUtil jwtUtil)
CorsConfigurationSource corsConfigurationSource()