Notice
Recent Posts
Recent Comments
Link
나의 GitHub Contribution 그래프
Loading data ...
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
Tags
more
Archives
Today
Total
관리 메뉴

Code in Life

[spring security] REST json HTTP 403 본문

에러 및 이슈

[spring security] REST json HTTP 403

퓨끼 2020. 12. 25. 14:03

Swagger-ui로 테스트
postman으로 테스트(Swagger-ui가 문제인건가 해서..)

환경 : Windows10 Pro

에러 : 

**Status:
403: Forbidden**


Server: Apache-Coyote/1.1
X-Content-Type-Options: nosniff
X-Xss-Protection: 1; mode=block

Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Expires: 0
X-Frame-Options: DENY

원인 : Spring Security 사용시 권한이 필요한 페이지에 권한이 없는 유저가 접근할 경우 Forbidden error를 발생

 

WebSecurityConfigurerAdapter를 상속받는 Config클래스에서 configure(HttpSecurity http) 메소드를 확인해보자.

필자의 경우 anyRequest().hasRole("USER") 부분을 설정해놓고 테스트한 컨트롤러에는 jwt토큰을 클라이언트로부터 받지 않은상태에서 발생한 것이였다. 따라서 당장의 토큰인증없이 컨트롤러 작동여부만 확인하려면 이 부분을 주석처리해주고 테스트해보면 된다.

주석처리 후 확인결과 클라이언트로부터 JSON data를 제대로 전송됨.

Comments