Closed cm325 closed 10 years ago
Glad you like this events mini-framework. And thanks for reporting the desired use case. I don't think it's currently possible to get access to HttpServletRequest instance inside the event listeners, but will definitely look into implementing some solution that does.
Best, D.
Hi, Thanks for the quick response, so ok, that's too bad. Do you have any thoughts on how one might get started on this, if I were to take this up? Thanks-
OK, here's how you can easily get access to the client IP address from inside any listener implementation. If you use the Inspektr
auditing library (the standard one that comes with CAS server), there is a ClientInfo
object that is bound to the current request thread and hence available to any objects within that thread of execution via a ThreadLocal wrapper called ClientInfoHolder
.
To configure it, one needs to have an Inspektr
library on the classpath, and add the following filter definition to the web.xml
:
<filter>
<filter-name>CAS Client Info Logging Filter</filter-name>
<filter-class>com.github.inspektr.common.web.ClientInfoThreadLocalFilter</filter-class></filter>
<filter-mapping>
<filter-name>CAS Client Info Logging Filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
and then access the ClientInfo
object from anywhere within that thread of execution via a static accessor like so: ClientInfoHolder.getClientInfo()
Here's the example of accessing client IP address from CAS event listener implementation:
Hope this helps.
Cheers, D.
Closing for now as there has not been any activity on this issue for a while and there is a way to get at the client IP address from any stack frame within a current thread of execution using the ThreadLocal wrapper from Inspektr library as described above.
I implemented the cas server events as outlined here:
https://github.com/Unicon/cas-addons/wiki/CAS-server-events
And it's working great for capturing and storing cas login events and information from the principal object (and even the currently active theme). However I'd also like to be able to record the ip address of the request, is there some way to do this from inside this set of pointcuts? Thanks!