- spring security에서 hasRole() 사용 시 발생
- 오류내용 :
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.servlet.Filter]: Factory method 'springSecurityFilterChain' threw exception; nested exception is java.lang.IllegalArgumentException: role should not start with 'ROLE_' since it is automatically inserted. Got 'ROLE_USER'
원인
- hasRole() 내부 :
rolePrefix는 자동으로 ROLE_ 이라는 prefix를 붙여주기 때문에 ROLE_ 이라는 prefix를 제외한 권한을 적으라는 것.
해결 방법
ROLE_ 은 자동생성되기 때문에 prefix의 ROLE_ 을 쓰지않아도 된다.
.antMatchers("/secTest").hasRole("USER") 로 수정한다.