BasicAuthenticationFilter 필터에 대해서 질문드립니다.
909
작성한 질문수 5
@Configuration
@EnableWebSecurity
public class Config extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable()
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and()
.formLogin().disable()
.httpBasic().disable()
.addFilter(new TestFilter(authenticationManager()))
.authorizeRequests()
.mvcMatchers("/").permitAll()
.mvcMatchers("/user").hasRole("USER");
}
}
컨트롤러
@RestController
public class BasicController {
@GetMapping("/")
public String test1() {
return "기본 접근";
}
@GetMapping("/user")
public String test2() {
return "유저 접근";
}
}
필터
public class TestFilter extends BasicAuthenticationFilter {
public TestFilter(AuthenticationManager authenticationManager) {
super(authenticationManager);
}
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException {
System.out.println("인증이 필요한거만 실행");
chain.doFilter(request, response);
}
}
이렇게 간단한 필터 테스트용 프로젝트를 작성했는데. "/" 요청 같이 permitAll() 처리하면 인증이나 인가가 필요 없어서
필터를 타지 않을거라 생각했는데. "인증이 필요한거만 실행" 이 찍히면서 필터를 타는데. 어디가 문제인지 모르겠습니다..
지금 jwt 토큰을 사용해서 프로젝트를 구현 중인데. 필터를 onceperrequestfilter를 상속 받아서 구현해서 로그인이나 토큰 재발급 같은 인증, 인가가 필요 없는 요청도 필터를 타면서 만약에 사용이 불가능한 토큰이 들어 있으면 막혀가지고 BasicAuthenticationFilter를 상속한 필터로 교체 해보려고 하는데.
생각한 것 처럼 동작하지가 않네요 . 단순하게는 필터 시작할 때, 리스트를 만들어서 해당 요청은 넘어가게 해줘도 되겠지만 더 깔끔하게 처리하고 싶어서 문의드립니다.
답변 1
JWT를 구현한 다음 이 API를 호출해서 사용하는 것은 프론트엔드 쪽에서 하는 역할인가요?
0
96
1
Jwt쓰면 스프링시큐리티는 필수적으로 사용해야하나요?
0
401
1
13:23 system.out 출력문이 다르게 나옵니다.
0
130
1
수료증 문의
0
226
2
9분대에 질문이 있습니다 !
0
114
1
password 비교를 하지 않았는데 어떻게 인증이 통과된 건가요?
0
321
1
이전 강의 참고하라는 말씀
0
253
1
강의 실습하다가 막히는 분들 참고(2024년8월 기준)
2
1116
2
구글 소셜 로그인 302
0
200
1
오류 문의 _ org.springframework.orm.jpa.JpaSystemException: could not deserialize
1
584
1
[자바] 시큐리티 Config 참고
13
953
1
이론강의
0
280
1
SpringSecurity JWT 로그인 URL 2개 설정하는 방법
0
487
1
2024.06기준) 최근 SecurityConfig 설정 문의
0
921
3
구글 로그인시 authentication이 null 값이라고 에러가 발생합니다.
0
678
2
특정 url필터 거는 방법 이슈
0
422
1
강사님께서 말씀하시는 시큐리티세션이 SecurityContext인가요?
0
277
1
25강 마지막 테스트에서 오류
1
1044
2
jwt를 저장하는 위치에 궁금한 점이 있습니다.
0
298
1
mustache를 사용하지 않고 thymeleaf를 사용하려고 하는데
0
697
1
세션 인증방식이 REST 원칙에 위배되는 건가요?
0
340
1
jwt와 실제데이터의 관계
1
243
1
jwt 와 세션ID의 관계
1
313
1
SecurityConfig에서 세션 설정, 인가 설정
0
421
1





