Hi Brian,

This should work:

<bean id="securityManager" ....>
    <!-- this property will automatically enable 'native' sessions and the
      native session manager: -->
    <property name="sessionMode" value="native"/>
    <!-- this property will set the SessionListeners on the newly created
          native session manager (I think Spring allows this type of
          nested property navigation): -->
    <property name="sessionManager.sessionListeners">
        <list>
            <!-- Add your SessionListener beans here: -->
        </list>
    </property>
    ....
</bean>

The 'trick' to having this work is that when you call 'setSessionMode'
to 'native', that will trigger logic to automatically substitute the
web-default ServletContainerSessionManager with the native
DefaultWebSessionManager.

You have to set the 'sessionMode' property first in order to ensure
the substitution occurs.

This is a bit hacky as far as I'm concerned, and this should really be
cleaned up with a Builder that can do this logic in a more
deterministic manner.  If you don't like the 'set this property before
the other one otherwise it will break' approach, you can use a more
explicit assignment - it's just more verbose (but safer):

<bean id="securityManager"
class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
    <property name="sessionManager">
        <bean class="org.apache.shiro.web.session.mgt.DefaultWebSessionManager">
            <property name="sessionListeners">
                <list>
                    <!-- SessionListener beans here: -->
                </list>
            </property>
        </bean>
    </property>
    <property name="realm" ref="myRealm"/>
    ...
</bean>

HTH!

Best,

-- 
Les Hazlewood
Founder, Katasoft, Inc.
Application Security Products & Professional Apache Shiro Support and Training:
http://www.katasoft.com

On Sun, Nov 7, 2010 at 2:18 PM, zooxmusic <[email protected]> wrote:
>
> What is the recommended way to add a session listener in a spring application
> and configuration?
>
> I've found a few posts but they are all out of date with the information yet
> only a few months old. The sessionListeners are on
> AbstractNativeSessionManager not DefaultWebSecurityManager or the other
> classes that were in the posts I've read.
>
> I would prefer to add the listener through the applicationContext if
> possible but the ini would be just fine if you can tell me how to cast in
> that format because I obviously get a classCastException if I do what the
> post said because  setSessionListeners are on the
> AbstractNativeSessionManager and not DefaultWebSecurityManger
>
>
>
> --
> View this message in context: 
> http://shiro-user.582556.n2.nabble.com/SessionListeners-with-Spring-and-a-Swing-Desktop-tp5715272p5715272.html
> Sent from the Shiro User mailing list archive at Nabble.com.
>

Reply via email to