在Wicket 6.7.0中使用Spring Security进行并发控制配置 [英] Concurrency Control configurarion using Spring Security in Wicket 6.7.0

查看:101
本文介绍了在Wicket 6.7.0中使用Spring Security进行并发控制配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我按照下面的示例将弹簧安全装置集成到检票口中. https://github.com/thombergs/wicket-spring-security-example

I followed the below example to integrated the spring security in wicket. https://github.com/thombergs/wicket-spring-security-example.

我更改了spring-security.xml文件以配置并发控制,如下所示.

I changed spring-security.xml file to configure the concurrency control as follows.

 <beans:beans xmlns="http://www.springframework.org/schema/security"
xmlns:beans="http://www.springframework.org/schema/beans" xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd 
                    http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.1.xsd
                    http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.1.xsd">

<http use-expressions="true" create-session="never" auto-config="true">

    <!-- <custom-filter position="CONCURRENT_SESSION_FILTER" ref="concurrencyFilter" 
        /> -->
    <!-- <custom-filter position="FORM_LOGIN_FILTER" ref="myAuthFilter" /> -->

    <intercept-url pattern="/" access="permitAll"
        requires-channel="https" />
    <intercept-url pattern="/home" access="permitAll"
        requires-channel="https" />
    <intercept-url pattern="/login" access="permitAll"
        requires-channel="https" />
    <intercept-url pattern="/**/*.png" access="permitAll"
        requires-channel="https" />
    <intercept-url pattern="/**/*.css" access="permitAll"
        requires-channel="https" />
    <intercept-url pattern="/secure/extreme/**" access="hasRole('supervisor')"
        requires-channel="https" />
    <intercept-url pattern="/secure/**" access="isAuthenticated()"
        requires-channel="https" />
    <!-- <intercept-url pattern="/**" access="permitAll" requires-channel="https" 
        /> -->
    <!-- the login page is a wicket page mounted in WicketApplication.init() -->

    <form-login login-page="/login" default-target-url='/home'
        always-use-default-target='true' />

    <session-management>
        <concurrency-control max-sessions="1" 
            session-registry-alias="authenticationManager" expired-url="/login"
            error-if-maximum-exceeded="true" session-registry-ref="sessionRegistry" />
    </session-management>

    <!-- <session-management session-authentication-error-url="/login">   <concurrency-control max-sessions="1" error-if-maximum-exceeded="true" /> </session-management> -->
    <!-- <session-management invalid-session-url="/login" /> -->

</http>

<!-- <beans:bean id="myAuthFilter" class="org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter"> 
    <beans:property name="sessionAuthenticationStrategy" ref="sas" />     <beans:property name="authenticationManager" ref="authenticationManager" /> </beans:bean> -->

<authentication-manager alias="authenticationManager">
    <authentication-provider>
        <user-service>
            <user name="rod" password="koala" authorities="supervisor, teller, user" />
            <user name="dianne" password="emu" authorities="teller, user" />
            <user name="scott" password="wombat" authorities="user" />
            <user name="peter" password="opal" authorities="user" />
        </user-service>
    </authentication-provider>
</authentication-manager>

<beans:bean id="concurrencyFilter"
    class="org.springframework.security.web.session.ConcurrentSessionFilter">
    <beans:property name="sessionRegistry" ref="sessionRegistry" />
    <beans:property name="expiredUrl" value="/login" />
</beans:bean>

<!-- <beans:bean id="sas" class="org.springframework.security.web.authentication.session.ConcurrentSessionControlStrategy"> 
    <beans:constructor-arg name="sessionRegistry" ref="sessionRegistry" />  <beans:property name="maximumSessions" value="1" /> </beans:bean> -->

<beans:bean id="sessionRegistry"
    class="org.springframework.security.core.session.SessionRegistryImpl" autowire="default" />

<!-- This filter is responsible for storing the SecurityContextHolder between 
    requests. Also see SecureWebSession.authenticate(). -->
<beans:bean id="securityContextPersistenceFilter"       class="org.springframework.security.web.context.SecurityContextPersistenceFilter" />

</beans:beans>

web.xml文件:

web.xml file :

    <?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">

<display-name>wicket-spring-security-example</display-name>

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
        classpath:spring-security.xml
    </param-value>
</context-param>
<listener>
<listener-  class>org.springframework.web.context.ContextLoaderListener</listener- class>
</listener>
<listener>
    <listener-class>
      org.springframework.security.web.session.HttpSessionEventPublisher
    </listener-class>
</listener>
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>

<filter>
    <filter-name>wicket.wicket-spring-security-example</filter-name>
    <filter-class>org.apache.wicket.protocol.http.WicketFilter</filter-class>
    <init-param>
        <param-name>applicationClassName</param-name>
        <param-value>org.wickedsource.WicketApplication</param-value>
    </init-param>
</filter>

<filter-mapping>
    <filter-name>springSecurityFilterChain</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

<filter-mapping>
    <filter-name>wicket.wicket-spring-security-example</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

<session-config>
    <session-timeout>1</session-timeout>
</session-config>
</web-app>

我的问题:

1)并发控制不适用于上述配置.我可以登录多个浏览器.

1) Concurrency control is not working with the above configuration. I am able to login multiple browsers.

2)每个用户单次登录(我的意思是,如果同一用户('x')再次登录,则用户'x'已登录.在此,我想使先前登录的会话无效).我怎么能做到这一点.

2) Single sign-in per user(I mean, the user 'x' is logged in, if the same user('x') logged in again. Here I want invalidate the previously logged in session). How can I achieve this.

推荐答案

1)由于示例中的会话管理是由Wicket而非Spring Security处理的,因此它可能不起作用,因此您必须找到一种启用方法在Wicket中.

1) It probably doesn't work since the Session Management in the example is handled by Wicket and not by Spring Security, so you must find a way to enable this in Wicket.

2)Wicket会话类具有方法replaceSession(),可用于在登录时创建新会话.试试这个.

2) The Wicket Session class has the method replaceSession() that you can use to create a new session on login. Try this.

这篇关于在Wicket 6.7.0中使用Spring Security进行并发控制配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆