Authentication의 details 에 대해 질문 있습니다.
1639
작성자 없음
작성한 질문수 0
IpAddressFilter에서 authentication.getDetails() 부분에서 최초로 접근할 때는 details가 존재합니다.
이때는 authentication이 AnonymousAuthenticationToken 입니다.
그런데, 이미 인증이 된 후에는 강의에서 만든 AjaxAuthenticationToken이 쓰이는데, 여기서는 getDetails()를 하면 WebAuthenticationDetails가 null이 됩니다.
AjaxAuthenticationToken에서도 details를 사용하려면 어떻게 해야할까요?...
답변 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) 의 결과값을 저장하는 것처럼 해당 필터에도 유사한 로직을 추가하시면 됩니다.
참고바랍니다.
시큐리티 공부 버전 질문
0
188
1
[해결 방법] MethodSecurityConfig.customMethodSecurityMetadataSource() 호출하지 않는 이슈
0
196
1
AbstractSecurityInterceptor.class.beforeInvocation()를 2번 실행하는 경우
0
185
1
강의 코드가 왜이렇게 뒤죽박죽인가요...
0
270
1
메인 페이지로 접속해도 login url로 리다이렉트가 되지 않습니다..
0
247
1
파라미터값이 넘어가지 않습니다 ....
0
381
1
security filterChain 설정 질문이 있습니다.
0
336
1
소스 부분 질문 드립니다.
0
211
2
섹션4 7번 강의 문제가 있는거 같네요.
0
351
2
파일이 수시로 이름이 바껴있네요 ㄷㄷ
0
308
1
HttpSessionSecurityContextRepository를 사용안하는 문제
0
563
2
error , exception 이 잘 안됩니다.
0
288
2
thymeleaf tag 질문합니다.
0
200
2
버전업하면서 deprecated된 것들이 너무많아요
0
482
1
spring security 패치 관련
0
442
1
모바일을 사용할때 토큰말고 세션
0
863
2
DB 연동한 인가 부분에 대한 질문입니다!
0
267
1
Ajax방식도 똑같이 Session방식을 사용하는건가요?
0
311
1
Config 파일 생성 시 질문이 있습니다.
0
233
1
강사님 몇일동안 구글 검색만 100개 했는데도 이유를 모르겠습니다..
1
440
2
403 에러 뜹니다.
0
817
2
login_proc의 존재에 대한 간략한 설명입니다
0
279
1
top.html에 로그인 링크를 만들어서 로그인을 해봤습니다
0
289
2
안녕하세요. DB에 저장될 때 이해 안 가는 값이 있어서 질문드립니다!
0
193
1





