Skip to content

Commit

Permalink
feat : security config add
Browse files Browse the repository at this point in the history
  • Loading branch information
seungueonn committed Nov 1, 2023
1 parent bd546ef commit 871f709
Showing 1 changed file with 73 additions and 0 deletions.
73 changes: 73 additions & 0 deletions src/main/java/gwangjang/server/global/security/SecurityConfig.java
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;
}

}

0 comments on commit 871f709

Please sign in to comment.