No author
This post's author information has been deleted.
Resolved
Written on
·
1.5K
2
IpAddressFilter에서 authentication.getDetails() 부분에서 최초로 접근할 때는 details가 존재합니다.
이때는 authentication이 AnonymousAuthenticationToken 입니다.
그런데, 이미 인증이 된 후에는 강의에서 만든 AjaxAuthenticationToken이 쓰이는데, 여기서는 getDetails()를 하면 WebAuthenticationDetails가 null이 됩니다.
AjaxAuthenticationToken에서도 details를 사용하려면 어떻게 해야할까요?...
Answer 1
3
네
이 부분은 UsernamePasswordAuthenticationFileter 를 참고하시면 될 것 같습니다.
소스를 보시면
public class UsernamePasswordAuthenticationFilter extends AbstractAuthenticationProcessingFilter {
------ 중략 ----
@Override
public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response)
throws AuthenticationException {
if (this.postOnly && !request.getMethod().equals("POST")) {
throw new AuthenticationServiceException("Authentication method not supported: " + request.getMethod());
}
String username = obtainUsername(request);
username = (username != null) ? username : "";
username = username.trim();
String password = obtainPassword(request);
password = (password != null) ? password : "";
UsernamePasswordAuthenticationToken authRequest = new UsernamePasswordAuthenticationToken(username, password);
// Allow subclasses to set the "details" property
setDetails(request, authRequest);
return this.getAuthenticationManager().authenticate(authRequest);
}
----- 중략 --------
protected void setDetails(HttpServletRequest request, UsernamePasswordAuthenticationToken authRequest) {
authRequest.setDetails(this.authenticationDetailsSource.buildDetails(request));
}
위 소스처럼 필터에서 WebAuthenticationDetails 관련 로직을 추가하시면 됩니다.
이 내용은 강의에도 나와 있으니 참고하시면 됩니다.
즉 UsernamePasswordAuthenticationToken 의 setDetails 메서드에 this.authenticationDetailsSource.buildDetails(request) 의 결과값을 저장하는 것처럼 해당 필터에도 유사한 로직을 추가하시면 됩니다.
참고바랍니다.
예제와 맞지않아 하다가 푹푹 빠지는 함정이 많지만 진짜 공부 잘되고있습니다^^
좋은강의 감사해요