스프링시큐리티 설정값 의미

cotchan·2021년 9월 23일
0
  • 개인 공부 목적으로 작성한 글입니다.
  • 아래 출처를 참고하여 작성하였습니다.
  • 계속 내용을 추가할 예정입니다.

antMatchers

  • 특정 리소스에 대해서 권한을 설정합니다.
 .antMatchers("/login**", "/web-resources/**", "/actuator/**")

//Sample

@EnableWebSecurity
public class BrmsWebSecurityConfiguration extends WebSecurityConfigurerAdapter {
    @Override
    public void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests()
                .antMatchers("/login**", "/web-resources/**", "/actuator/**").permitAll()
                .antMatchers("/admin/**").hasAnyRole("ADMIN")
                .antMatchers("/order/**").hasAnyRole("USER")
                .anyRequest().authenticated();
    }
}    

permitAll

  • antMatchers로 설정한 리소스의 접근을 인증절차 없이 허용한다는 뜻입니다.
.antMatchers("/login**", "/web-resources/**", "/actuator/**").permitAll() 

authorizeRequests

  • 시큐리티 처리에 HttpServletRequest를 이용한다는 것을 의미합니다.
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests()
                .antMatchers("/guest/**").permitAll()
                .antMatchers("/manager/**").hasRole("MANAGER")
                .antMatchers("/admin/**").hasRole("ADMIN");

        http.formLogin();
        http.exceptionHandling().accessDeniedPage("/accessDenied");
        http.logout().logoutUrl("/logout").invalidateHttpSession(true);

    }
}

anyRequest

  • 모든 리소스를 의미하며 접근허용 리소스 및 인증 후 특정 레벨의 권한을 가진 사용자만 접근가능한 리소스를 설정한 후에 사용합니다.
  • 그 외 나머지 리소스들에 대한 접근 허용 수준을 결정할 때 사용합니다.
    • 아래 코드는 그 외 나머지 리소스들은 무조건 인증을 완료해야 접근이 가능하다는 의미입니다.
.anyRequest().authenticated()

addFilterAt

  • 지정된 필터의 순서에 커스텀 필터가 추가됩니다.

profile
https://github.com/cotchan

0개의 댓글