전코드
@Override public void configure(WebSecurity web) { web.ignoring().antMatchers( GET, this.security .getAllows() .getGet() .toArray(String[]::new) ); web.ignoring().antMatchers( POST, this.security .getAllows() .getPost() .toArray(String[]::new) ); }
현재코드
@Override protected void configure(HttpSecurity http) throws Exception { http.authorizeRequests() .antMatchers("/users/me").hasAnyRole("USER") .antMatchers("/expulsion").hasAnyRole("ADMIN") .mvcMatchers(HttpMethod.GET, this.security.getAllows().getGet().toArray(String[]::new)) .permitAll() .mvcMatchers(HttpMethod.POST, this.security.getAllows().getPost().toArray(String[]::new)) .permitAll() .anyRequest().fullyAuthenticated() }
WebSecurity
쪽에 ignoring을 통해서 설정을 한다면 Request 요청이 왔을 때 아예 필터에 걸리지 않는다. 따라서 토큰 필터에 걸리지 않기 때문에 옵셔널 처리가 불가능하다.httpSecurity
에 permitAll로 ignoring 한다면, 등록되어 있는 Filter를 다 확인하고 FilterSecurityInterceptor에서 AccessDecisionManager를 통해 Authority 를 확인 후 통과하게 된다. 따라서 토큰 옵셔널 처리가 가능하다.