-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
bd546ef
commit 871f709
Showing
1 changed file
with
73 additions
and
0 deletions.
There are no files selected for viewing
73 changes: 73 additions & 0 deletions
73
src/main/java/gwangjang/server/global/security/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 |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package gwangjang.server.global.security; | ||
|
||
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.config.annotation.web.configuration.WebSecurityCustomizer; | ||
import org.springframework.security.config.http.SessionCreationPolicy; | ||
import org.springframework.security.web.SecurityFilterChain; | ||
import org.springframework.web.cors.CorsConfiguration; | ||
import org.springframework.web.cors.CorsConfigurationSource; | ||
import org.springframework.web.cors.UrlBasedCorsConfigurationSource; | ||
|
||
@Configuration | ||
@EnableWebSecurity | ||
@RequiredArgsConstructor | ||
public class SecurityConfig { | ||
|
||
@Bean | ||
public WebSecurityCustomizer webSecurityCustomizer() { | ||
return (web) -> web.ignoring() | ||
.requestMatchers("/resource/**", "/css/**", "/js/**", "/img/**", "/lib/**"); | ||
}; | ||
// .requestMatchers(new AntPathRequestMatcher( "/**/*.html")); | ||
|
||
|
||
@Bean | ||
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { | ||
|
||
|
||
http | ||
.csrf() | ||
.disable() | ||
.sessionManagement() | ||
.sessionCreationPolicy(SessionCreationPolicy.STATELESS); | ||
|
||
http | ||
.formLogin().disable() //폼 로그인 비활성화 | ||
.httpBasic().disable() // HTTP 기본 인증 비활성화 | ||
.exceptionHandling() //예외 처리 설정 | ||
// .authenticationEntryPoint(jwtAuthenticationEntryPoint) //인증되지 않은 사용자가 보호된 리소스에 액세스 할 때 호출되는 JwtAuthenticationEntryPoint 설정 | ||
.and() | ||
.headers().frameOptions().sameOrigin(); | ||
|
||
|
||
http | ||
.authorizeHttpRequests( | ||
authorize -> authorize | ||
.requestMatchers("/auth/**").permitAll() | ||
.anyRequest().authenticated() | ||
); | ||
|
||
// http .apply(new JwtSecurityConfig(tokenUtil, memberQueryService)); | ||
|
||
return http.build(); | ||
} | ||
|
||
@Bean | ||
public CorsConfigurationSource corsConfigurationSource() { | ||
CorsConfiguration configuration = new CorsConfiguration(); | ||
|
||
configuration.addAllowedOriginPattern("*"); | ||
configuration.addAllowedHeader("*"); | ||
configuration.addAllowedMethod("*"); | ||
configuration.setAllowCredentials(false); | ||
|
||
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); | ||
source.registerCorsConfiguration("/**", configuration); | ||
return source; | ||
} | ||
|
||
} |