|
View:
New views
2 Messages
—
Rating Filter:
Alert me
|
|
|
Acegi security event, getting URI and IP addressHi guys,
We need to keep a log of when people logged in and from where. I've followed the documentation with some success, but I don't know how to get access to the HttpServletRequest for the URI and IP I'm doing something like this at the moment, but the URI and IP are always blank. onAuthenticationSuccessEvent = { e, appCtx -> def attr = RequestContextHolder?.getRequestAttributes() def uri = "" if (attr?.currentRequest?.request) { uri = attr.currentRequest.request.getRequestURI() if (attr.currentRequest.request.getQueryString()) { uri = uri + "?" + attr.currentRequest.request.getQueryString(); } } def ip = "" if (attr?.currentRequest?.request) { ip = attr.currentRequest.request.getRemoteAddr() } def authentication = e.getAuthentication() def accessLogEvent = new AccessLogEvent() accessLogEvent.actor = authentication.getPrincipal() accessLogEvent.action = "LOGIN" accessLogEvent.uri = uri accessLogEvent.ip = ip accessLogEvent.dateCreated = new Date() accessLogEvent.save() } Any ideas? Thanks, Elias --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
|
Re: Acegi security event, getting URI and IP addressAcegi is implemented as a Filter chain, so it's running before Spring has a
chance to configure the RequestContextHolder. If you log in with a username/password (not a remember-me cookie) after being redirected to the login page (as opposed to going directly to the login page) then the event is AuthenticationSuccessEvent, its Authentication is a UsernamePasswordAuthenticationToken and that has a WebAuthenticationDetails with the remote IP address (but not the requested url): onAuthenticationSuccessEvent = { e, appCtx -> def ip = e.authentication.details.remoteAddress } I'd like to release a small 0.3.1 update soon and could add in some functionality to expose this information. Please write up a new feature request at http://jira.codehaus.org/browse/GRAILSPLUGINS under the Grails-Acegi component. Burt On Friday 16 May 2008 1:27:48 am Elias Lopez wrote: > Hi guys, > > We need to keep a log of when people logged in and from where. I've > followed the documentation with some success, but I don't know how to > get access to the HttpServletRequest for the URI and IP > > I'm doing something like this at the moment, but the URI and IP are > always blank. > > onAuthenticationSuccessEvent = { e, appCtx -> > def attr = RequestContextHolder?.getRequestAttributes() > > def uri = "" > if (attr?.currentRequest?.request) { > uri = attr.currentRequest.request.getRequestURI() > if (attr.currentRequest.request.getQueryString()) { > uri = uri + "?" + > attr.currentRequest.request.getQueryString(); > } > } > > def ip = "" > if (attr?.currentRequest?.request) { > ip = attr.currentRequest.request.getRemoteAddr() > } > > def authentication = e.getAuthentication() > def accessLogEvent = new AccessLogEvent() > accessLogEvent.actor = authentication.getPrincipal() > accessLogEvent.action = "LOGIN" > accessLogEvent.uri = uri > accessLogEvent.ip = ip > accessLogEvent.dateCreated = new Date() > accessLogEvent.save() > } > > Any ideas? > > Thanks, > Elias > > > --------------------------------------------------------------------- > To unsubscribe from this list, please visit: > > http://xircles.codehaus.org/manage_email --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
| Free Forum Powered by Nabble | Forum Help |