-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
51 additions
and
23 deletions.
There are no files selected for viewing
48 changes: 29 additions & 19 deletions
48
src/main/java/org/team10/washcode/config/SecurityConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,51 @@ | ||
package org.team10.washcode.config; | ||
|
||
import lombok.AllArgsConstructor; | ||
import jakarta.servlet.ServletException; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.security.config.annotation.web.builders.HttpSecurity; | ||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; | ||
import org.springframework.security.core.userdetails.UserDetailsService; | ||
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer; | ||
import org.springframework.security.config.annotation.web.configurers.HeadersConfigurer; | ||
import org.springframework.security.core.Authentication; | ||
import org.springframework.security.web.SecurityFilterChain; | ||
import org.springframework.security.web.authentication.AuthenticationSuccessHandler; | ||
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; | ||
import org.team10.washcode.jwt.CustomUserDetails; | ||
import org.team10.washcode.jwt.JwtAuthenticationFilter; | ||
import org.team10.washcode.jwt.JwtProvider; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
@Configuration | ||
@EnableWebSecurity | ||
@RequiredArgsConstructor | ||
public class SecurityConfig { | ||
private final UserDetailsService userDetailsService; | ||
|
||
private final JwtProvider jwtProvider; | ||
|
||
@Bean | ||
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception{ | ||
http | ||
.csrf().disable() | ||
.cors().and() // CORS 설정 추가 | ||
.authorizeHttpRequests(auth -> auth | ||
// .requestMatchers("/api/**").permitAll() | ||
// .requestMatchers("/swagger-ui/**").permitAll() | ||
// .requestMatchers("/v3/api-docs/**").permitAll() | ||
// .requestMatchers("/").permitAll() | ||
// .anyRequest().authenticated() | ||
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { | ||
return | ||
http | ||
.csrf(AbstractHttpConfigurer::disable) | ||
.formLogin(AbstractHttpConfigurer::disable) | ||
.httpBasic(AbstractHttpConfigurer::disable) | ||
.cors(AbstractHttpConfigurer::disable) | ||
.headers(header -> header.frameOptions(HeadersConfigurer.FrameOptionsConfig::disable)) | ||
.authorizeHttpRequests((auth) -> auth | ||
.requestMatchers("/WEB-INF/view/**","/upload/**","/error","/swagger-ui/**", "/v3/api-docs/**").permitAll() | ||
.requestMatchers("/","/register","/api/user/login","/login").permitAll() | ||
.requestMatchers("/main").permitAll() | ||
.requestMatchers("/api/user/address").permitAll() | ||
.dispatcherTypeMatchers(jakarta.servlet.DispatcherType.FORWARD).permitAll() | ||
.dispatcherTypeMatchers(jakarta.servlet.DispatcherType.INCLUDE).permitAll() | ||
.anyRequest().permitAll() | ||
) | ||
.addFilterBefore(new JwtAuthenticationFilter(jwtProvider), UsernamePasswordAuthenticationFilter.class); | ||
|
||
return http.build(); | ||
|
||
) | ||
//.addFilterBefore(new JwtAuthenticationFilter(jwtProvider), UsernamePasswordAuthenticationFilter.class) | ||
.build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters