3. 접근 제한 설정

책의 3. 접근 제한 설정의 내용

SecurityConfig.java

<@Configuration
@EnableWebSecurity
@Slf4j
public class SecurityConfig {

	@Bean
	public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
		log.info("security config...");
		
		//URI 패턴으로 접근 제한을 설정한다.
		http.authorizeHttpRequests((authorize) -> authorize
				.requestMatchers("/board/list")
				.permitAll());
		http.authorizeHttpRequests((authorize) -> authorize
				.requestMatchers("/board/register")
				.hasRole("MEMBER"));
		http.authorizeHttpRequests((authorize) -> authorize
				.requestMatchers("/notice/list")
				.permitAll());
		http.authorizeHttpRequests((authorize) -> authorize
				.requestMatchers("/notice/register")
				.hasRole("ADMIN"));
		
		http.formLogin();
		
		return http.build();
		
	}
}
반응형

'스프링 시큐리티 > 책 내용 정리' 카테고리의 다른 글

6. 사용자 정의 접근 거부 처리자  (0) 2023.04.30
5. 접근 거부 처리  (0) 2023.04.22
4. 로그인 처리  (0) 2023.04.16
2. 스프링 시큐리티 설정  (0) 2023.04.16
1. 책 내용 정리  (0) 2023.04.16

댓글()