• 카테고리

    질문 & 답변
  • 세부 분야

    백엔드

  • 해결 여부

    미해결

createSuccessAuthentication

22.01.04 17:43 작성 조회수 104

0

createSuccessAuthentication에서 권한 정보까지 조회해서 토큰에 저장하신다고 하셨는데 여기서 권한이란게 서비스로직에서의 권한, 즉 member, admin 이런 권한이 아닌거 같은데 여기서 말하는 권한이 어떤것에 대한 권한인건가요??

답변 1

답변을 작성해보세요.

1

네 

스프링 시큐리티에서 권한은 GrantedAuthority 타입으로 생성된 권한을 의미합니다.

그리고 GrantedAuthority 의 구현체인 SimpleGrantedAuthority 에 ROLE_USER, ROLE_ADMIN 과 같은 권한 값을 저장해서 사용합니다.

Authentication 이 속성을 보시면 Collection<? extends GrantedAuthority> getAuthorities() 가 있는데 스프링 시큐리티에서는 사용자의 권한을 체크할 때 위의 속성을 참조해서 처리하게 됩니다.

그래서 createSuccessAuthentication 에서는 사용자 정보인 User 객체와 더불어 콜렉션으로 생성된 권한정보를 Authentication 에 저장하게 되는데 이 권한정보를 Collection<GrantedAuthority> 으로 생성해서 저장한다는 의미라 보시면 됩니다.

일반적으로

new UsernamePasswordAuthenticationToken(accountContext.getAccount(), null, accountContext.getAuthorities());

와 같이 구문을 작성하게 됩니다.

마지막에 있는 부분이 권한정보입니다.