[토막글] HttpSecurity vs WebSecurity

구황작물·2023년 1월 9일
0

Security

목록 보기
10/10

httpSecurity : SecurityFilterChain 구성에 쓰인다. 보안 처리시 사용된다.

@Bean
    public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
        http
                .csrf().disable()
                .headers().frameOptions().disable()
                .and()
                .authorizeRequests()
                .antMatchers("/css/**","/images/**","/js/**","/h2/**").permitAll()
                .antMatchers("/api/team/list/**").permitAll()
                .antMatchers("/api/**").hasRole(Role.USER.name())
                .anyRequest().authenticated()
                .and().logout()
                .logoutSuccessUrl("/api/team/list?page=1&size=10")
                .and()
                .oauth2Login()
                .userInfoEndpoint()
                .userService(customOAuth2UsersService)
                .and()
                .successHandler(authenticationSuccessHandler)
                .defaultSuccessUrl("/api/team/list?page=1&size=10");
        return http.build();
    }

종종 우리가 하나의 SecurityFilterChain 말고 여러 SecurityFilterChain에 조건을 걸고 싶다면 WebSecurity를 사용한다고 한다. 보안 예외 처리(정적 리소스, HTML)로 사용된다.

@Bean
    public WebSecurityCustomizer webSecurityCustomizer() {
        return (web) -> web.ignoring().antMatchers("/h2/**", "/favicon.ico");
    }
profile
그냥 개발 좋아하는 덩이뿌리식물

0개의 댓글

관련 채용 정보