I'm pretty sure you cannot get the Request from the servlet context.
The recommended way to get hold of the current user authentication
details is to use the:
org.acegisecurity.context.SecurityContextHolder
I think there is a util called SecurityUtil in appfuse (if not create
one :-) ) to get the current logged in user with out importing acegi
code. What isn't in there is the remote IP address, that can only
really be got from the http Request.
You have two options really:
1. implement a new AuthenicationToken that holds on to the IP address
that the created the authenication (not this may or may not be the IP
address of the current request)
2. create a filter to populate your own ThreadLocal variable wih the
IP address that you can retrieve at the bottom of the stack. On the
don't use ThreadLocal thing...I think that should really be taken as:
use TheadLocal with care and always know when you will be clearing the
information.
Hope this helps.
Gareth
On 4 Feb 2008, at 07:23, [EMAIL PROTECTED] wrote:
Rob - thanks! I'm most of the way there now.
Here's what I ended up with:
<!-- Bean to catch successful login event and make user and
originating
location info available. -->
<bean id="auditInfoListenerBean"
class="org.appfuse.model.hibernate.AuditInfoListener">
</bean>
<!-- Entity Interceptor bean - sets audit fields for each persistent
object -->
<bean id="entityInterceptor"
class="org.appfuse.model.hibernate.AuditInterceptor">
<property name="auditInfoListener" ref="auditInfoListenerBean"/>
</bean>
<!-- Hibernate SessionFactory -->
<bean id="sessionFactory"
class
=
"org
.springframework
.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="entityInterceptor" ref="entityInterceptor"/>
<property name="dataSource" ref="dataSource"/>
<property name="configLocation"
value="classpath:hibernate.cfg.xml"/>
<property name="hibernateProperties">
<value>
hibernate.dialect=${hibernate.dialect}
hibernate.query.substitutions=true 'Y', false 'N'
hibernate.cache.use_second_level_cache=true
hibernate.cache.provider_class=org.hibernate.cache.EhCacheProvider
</value>
<!-- Turn batching off for better error messages under
PostgreSQL -->
<!-- hibernate.jdbc.batch_size=0 -->
</property>
</bean>
My AuditInfoListener class implements the ServletContextAware and
ApplicationEvent interfaces and they are catching the successful
login event
and grabbing the ServletContext just fine. I kept this separate from
the
AuditInterceptor. For testing and non-webapp stuff, I'm hoping to just
switch in a different bean that will provide the user and IP address
(or
equivalent) to the AuditInterceptor.
Question:
But I'm not sure how to get either the session or request from the
ServletContext object - it does not list those properties - unless
its just
too late and I'm not looking carefully.
Thank you again - Richard
--
View this message in context:
http://www.nabble.com/How-to-get-authentication-info-into-a-Spring-bean---Hibernate-interceptor-tp15247474s2369p15263231.html
Sent from the AppFuse - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]