• 카테고리

    질문 & 답변
  • 세부 분야

    백엔드

  • 해결 여부

    미해결

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

22.09.16 00:07 작성 조회수 2.39k

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();
}

답변 1

답변을 작성해보세요.

8

김동운님의 프로필

김동운

질문자

2022.09.16

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

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

 

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

thdi4564님의 프로필

thdi4564

2024.02.27

감사합니다!!