var customUser = new CustomUser();
customUser.displayName = claim.get("displayName").toString();
var authToken = new UsernamePasswordAuthenticationToken(
customUser,
null
);
authToken.setDetails(new WebAuthenticationDetailsSource().buildDetails(request));
SecurityContextHolder.getContext().setAuthentication(authToken);
filterChain.doFilter(request, response);
이런식으로 작성했더니 컨트롤러 Authentication auth 의 값이 null로 들어옵니다.
SecurityContextHolder.getContext().getAuthentication() 를 로그로 확인해본결과
[Principal=com.study.apple.shop.member.CustomUser [Username=123, Password=[PROTECTED], Enabled=true, AccountNonExpired=true, CredentialsNonExpired=true, AccountNonLocked=true, Granted Authorities=[ROLE_USER]],
Credentials=[PROTECTED], Authenticated=false, Granted Authorities=[]]
값들은 잘 들어와있는데
Authenticated=false 로 인증이 완료되지않았다고 뜨네요
UsernamePasswordAuthenticationToken authToken = new UsernamePasswordAuthenticationToken(
// 유저네임, 패스워드
customUser,
null,
authorities
);
이런식으로
UsernamePasswordAuthenticationToken 매개변수에 권한들을 추가했더니
Authenticated=true 인증되더니 컨트롤러에서
Authentication auth 값이 잘 들어와 해결은 되었습니다.
그런데 제가 어디를 놓쳤기에 인증이 안되었던 걸까요...
스프링 스타터 io 로 스프링시큐리티를 추가했는데
단순한 시큐리티 버전차이일까요?