2011-12-21 44 views
8

Tôi đã sử dụng bảo mật mùa xuân 3.0.7 và tôi đang thực hiện kiểm soát đồng thời trong dự án của mình. Nhưng nó không hoạt động. Tôi đã sử dụngKiểm soát đồng thời an ninh mùa xuân

<security:session-management> 
      <security:concurrency-control error-if-maximum-exceeded="true" max-sessions="1"/> 
</security:session-management> 

Thậm chí tôi đã thử giải pháp từ spring security reference nhưng nó không hoạt động. Dưới đây là cấu hình nội dung tập tin của tôi:

<session-management session-authentication-strategy-ref="sas"/> 
</http> 

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

<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> 

<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" /> 

Tôi nhận được sau ngoại lệ:

org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Filter beans '<myAuthFilter>' and '<org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter#0>' have the same 'order' value. When using custom filters, please make sure the positions do not conflict with default filters. Alternatively you can disable the default filters by removing the corresponding child elements from <http> and avoiding the use of <http auto-config='true'>. 
Offending resource: class path resource [config/auth.xml] 
    at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:68) 
    at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:85) 
    at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:72) 
    at org.springframework.security.config.http.HttpSecurityBeanDefinitionParser.checkFilterChainOrder(HttpSecurityBeanDefinitionParser.java:196) 
    at org.springframework.security.config.http.HttpSecurityBeanDefinitionParser.parse(HttpSecurityBeanDefinitionParser.java:132) 
    at org.springframework.security.config.SecurityNamespaceHandler.parse(SecurityNamespaceHandler.java:86) 
    at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1338) 
    at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1328) 
    at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:135) 
    at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:93) 
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:493) 
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:390) 

bất cứ ai có thể giúp với câu hỏi này?

+0

Bạn có thể xác định * không hoạt động * không? Tôi có '' một mình và sau khi đăng nhập bằng trình duyệt thứ hai, trình duyệt đầu tiên được đăng xuất. –

+0

trong trường hợp của tôi khi tôi đăng nhập bằng trình duyệt thứ hai mà nó đăng nhập, thậm chí tôi đã thử nghiệm từ trình duyệt thứ ba. –

+0

Thực tế nó sẽ đăng nhập bằng trình duyệt thứ hai. Truy cập tiếp theo từ trình duyệt đầu tiên có hoạt động không? – Raghuram

Trả lời

2

Nếu bạn đã viết UserPrincipalUserPrincipalImpl (thực hiện của riêng bạn), bạn nên ghi đè Object của equals()hashCode() phương pháp.

+0

hi, bạn có thể khai sáng thêm cho chúng tôi về giải pháp này không? Điều gì nếu bạn có một xác thực tùy chỉnh (thực hiện 'AuthenticationProvider'). Cấu hình này có đủ: ' ' – Oneb

1

thêm dòng sau vào web.xml:

<listener> 
    <listener-class> 
     org.springframework.security.web.session.HttpSessionEventPublisher 
    </listener-class> 
    </listener> 
+0

Vâng! Tôi đã thêm nhưng đó là lớp của riêng tôi, mở rộng org.springframework.security.web.session.HttpSessionEventPublisher –

4

Nếu bạn sử dụng các yếu tố concurrency-control namespace, một ConcurrentSessionFilter will be added to the filter chain tự động, do đó bạn không thể sử dụng custom-filter để thêm một ở cùng một vị trí hoặc bạn sẽ nhận được lỗi này.

Vấn đề tương tự sẽ xảy ra nếu bạn sử dụng form-login (hoặc auto-config) và cố thêm UsernamePasswordAuthenticationFilter bằng cách sử dụng custom-filter. Dường như điều đó đang gây ra sự cố cụ thể mà bạn có ở đây (với số đậu của bạn myAuthFilter).

Bạn có thể thêm phần còn lại của cấu hình phần tử http của mình vào câu hỏi để làm rõ hơn khi xung đột đến từ đâu.

1

Tôi có applicationContext-security.xml sau đây và nó hoạt động hoàn hảo

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xmlns:context="http://www.springframework.org/schema/context" 
     xmlns:security="http://www.springframework.org/schema/security" 
     xsi:schemaLocation=" 
     http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd 
     http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd 
     http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.xsd"> 

    <context:component-scan base-package="com.mycompany.test"/> 

    <security:http use-expressions="true"> 
     <security:http-basic/> 
     <security:intercept-url pattern="/**" access="isAuthenticated()" /> 
     <security:session-management> 
      <security:concurrency-control error-if-maximum-exceeded="true" max-sessions="1"/> 
     </security:session-management> 
    </security:http> 


    <security:global-method-security secured-annotations="enabled"/> 

    <security:authentication-manager> 
     <security:authentication-provider> 
      <security:user-service> 
       <security:user name="restuser" password="restuser" authorities="ROLE_RESTCLIENT"/> 
      </security:user-service> 
     </security:authentication-provider> 
    </security:authentication-manager> 

</beans> 

Để kiểm tra nó đúng cách bạn nên làm như sau: mở các trang web trong hai trình duyệt khác nhau và xóa các tập tin cookie. Lần đầu tiên bạn không thể đăng nhập lần thứ 2. Bạn sẽ thấy biểu mẫu xác thực HTTP được trình duyệt hiển thị trong cả hai trường hợp. Nếu bạn không thấy nó có nghĩa là bạn đã được xác thực trong một phiên trước đó, do đó bạn cần phải xóa cookie của bạn. (Để được ở bên an toàn, bạn nên thử nghiệm nó với hai trình duyệt khác nhau nếu không thì cookie MiTH được chia sẻ)

4

Các tài liệu nói:

Thêm hỗ trợ cho điều khiển phiên đồng thời, cho phép giới hạn được đặt trên số lượng phiên hoạt động mà người dùng có thể có. A ConcurrentSessionFilter sẽ được tạo và ConcurrentSessionControlStrategy sẽ được sử dụng với SessionManagementFilter. Nếu một phần tử đăng nhập biểu mẫu đã được khai báo, đối tượng chiến lược cũng sẽ được đưa vào bộ lọc xác thực đã tạo. Ví dụ về SessionRegistry (ví dụ SessionRegistryImpl trừ khi người dùng muốn sử dụng bean tùy chỉnh) sẽ được tạo để sử dụng theo chiến lược.

Vì vậy, bạn không thể sử dụng thẻ bộ lọc tùy chỉnh tại đây. Đó là lý do tại sao nó có thể đưa ra lỗi. Tôi đã lấy nội dung ở trên từ URL này.Check this out:

tham khảo: http://static.springsource.org/spring-security/site/docs/3.1.x/reference/springsecurity-single.html#nsa-concurrency-control

Các vấn đề liên quan