인프런 영문 브랜드 로고
인프런 영문 브랜드 로고

Inflearn Community Q&A

gauri7891's profile image
gauri7891

asked

Spring Security

2) Static resource management - WebIgnore settings

SecurityFilterChain 으로 하시는 분들께 제코드 공유해요!

Written on

·

2.7K

6

혹시 더 나은 방식이 있다면 같이 공유해요!! 다들 화이팅하세요!

@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {

    http
            .authorizeRequests()
            .antMatchers("/").permitAll()
            .antMatchers(
                    "/css/**",
                    "/js/**",
                    "/images/**",
                    "/webjars/**",
                    "/favicon.*",
                    "/*/icon-*"
            ).permitAll()
            .antMatchers("/mypage").hasRole("USER")
            .antMatchers("/message").hasRole("MANAGER")
            .antMatchers("/config").hasRole("ADMIN")
            .anyRequest().authenticated();

    http
            .formLogin();

    return http.build();
}
Spring Securityjavaspring-boot

Answer 1

8

gauri7891님의 프로필 이미지
gauri7891
Questioner

추가로 Bean등록 방식도 공유합니다.

@Bean
public WebSecurityCustomizer webSecurityCustomizer() {
    return (web) -> web.ignoring().requestMatchers(PathRequest.toStaticResources().atCommonLocations());
}

 

참조 : https://codejava.net/frameworks/spring-boot/fix-websecurityconfigureradapter-deprecated

감사합니다!!

 

gauri7891's profile image
gauri7891

asked

Ask a question