Spring Security에서 client의 ip address를..

2,559 views
Skip to first unread message

미랭군

unread,
May 18, 2011, 1:18:28 AM5/18/11
to Korea Spring User Group
안녕하세여. 한동안 눈팅하다가 또 이렇게 질문 올립니다.

로그인시에 로그를 남기려고 하는데

제목과 같이 스프링 시큐리티에서

접속자의 ip address를 알아낼 수 있는 방법이 없을까요?

보통 로그인 컨트롤러를 구현할 땐 그냥

request.getRemoteAddr()

을 통해서 ip를 가져왔었는데 스프링에선..어케 가져와야할지 모르겠네여..

선영욱

unread,
May 18, 2011, 1:32:22 AM5/18/11
to ks...@googlegroups.com
 
Spring Security 클래스 중에서 AbstractProcessingFilter.java에서 로그인 인증이  성공한 경우 successfulAuthentication 메소드를 호출하는데요.
 
해당 메소드의 파라메터 중에 HttpServletRequest이 있습니다.
 
그럼 AOP로 해당 클래스의 메소드에 대해서 처리하는 클래스를 하나 만드시고 설정을 하셔서 로그인시 로깅을 하는 처리하는 로직을 넣으면 될 것 같습니다.

혹시 다른 방법이 있으신 분들도 공유 부탁드립니다.
2011년 5월 18일 오후 2:18, 미랭군 <devz...@gmail.com>님의 말:

--
Google 그룹스 'Korea Spring User Group' 그룹에 가입했으므로 본 메일이 전송되었습니다.
이 그룹에 게시하려면 ks...@googlegroups.com(으)로 이메일을 보내세요.
그룹에서 탈퇴하려면 ksug+uns...@googlegroups.com로 이메일을 보내주세요.
더 많은 옵션을 보려면 http://groups.google.com/group/ksug?hl=ko에서 그룹을 방문하세요.


Andrew,Ahn

unread,
May 18, 2011, 8:56:50 PM5/18/11
to ks...@googlegroups.com
WebAuthenticationDetails webAuthenticationDetails =
((WebAuthenticationDetails)authentication.getDetails());
webAuthenticationDetails.getRemoteAddress();

http://static.springsource.org/spring-security/site/docs/3.0.x/apidocs/org/springframework/security/web/authentication/WebAuthenticationDetails.html

내부적으로 request에서 가져오는 거라서... 그냥 우아한 방법이 아닐까 싶네요.


2011/5/18 미랭군 <devz...@gmail.com>:

> --
> Google 그룹스 'Korea Spring User Group' 그룹에 가입했으므로 본 메일이 전송되었습니다.
> 이 그룹에 게시하려면 ks...@googlegroups.com(으)로 이메일을 보내세요.
> 그룹에서 탈퇴하려면 ksug+uns...@googlegroups.com로 이메일을 보내주세요.
> 더 많은 옵션을 보려면 http://groups.google.com/group/ksug?hl=ko에서 그룹을 방문하세요.
>
>

--
/**
* Life is too short, Code is too long.
* I am a coder who dreams the programmer.
*
* +author Andrew <rats...@gmail.com>
* +homepage http://xinublog.tistory.com
* +twitter @ratsbomb
*/

선영욱

unread,
May 18, 2011, 9:40:52 PM5/18/11
to ks...@googlegroups.com
제가 사용해봤던 버전은 2.5였는데 말씀해주신 곳으로 찾아가보니 없는 패키지 구조에 없는 클래스더라구요.
 
3.0에서 생긴 기능같은데 이런 부분들이 2.5에 비해서 좋아진거 같네요. ^^

2011년 5월 19일 오전 9:56, Andrew,Ahn <rats...@gmail.com>님의 말:
Reply all
Reply to author
Forward
0 new messages