Spring Security Concurrent Session:无法使“max-sessions”字段可配置

时间:2017-09-14 13:32:21

标签: java spring spring-security

我需要在我的Web应用程序中允许并发会话控制,并使可配置字段“max-sessions”。我的配置如下:

<security:session-management>
    <security:concurrency-control max-sessions="${maxConcurrentSessionsCount}" session-registry-ref="sessionRegistry" expired-url="/handleInvalidatedSession.gs4tr"/>
</security:session-management>`

正如您所猜测的,在“services.properties”文件中应该有“maxConcurrentSessionsCount”字段,客户端将根据其意愿设置该字段。 但是我在Intelij得到了下一个警告:

"attribute 'max-sessions' on element 'security:concurrency-control' is not valid with respect to its type, 'positiveInteger'".

我成功配置了许多其他内容,例如“remember-me”中的“token-validity-seconds”和“remember-me-cookie”等。 知道如何解决问题吗?通过互联网搜索几天寻求帮助,但失败了。

编辑: 在“services.properties”中配置: “maxConcurrentSessionsCount = 2”

在启动应用程序时,它会抛出下一个错误:

No, it doesn't. It throws next ERROR on starting app:

017-09-14 15:46:47,724 ERROR [org.gs4tr.projectdirector.service.context.ContextLoaderListener] [localhost-startStop-1] [user:] - org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException:来自类路径资源[org / gs4tr / foundation / modules / webmvc / spring / applicationContext-security-default.xml]的XML文档中的第75行无效;嵌套异常是org.xml.sax.SAXParseException; lineNumber:75; columnNumber:72; cvc-datatype-valid.1.2.1:'$ {maxConcurrentSessionsCount}'不是'integer'的有效值。     在org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:399)     在org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:336)     在org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:304)     在org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:181)     在org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:217)     在org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:188)     在org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:125)     在org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:94)     at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:129)     在org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:537)     在org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:452)     at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403)     在org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)     在org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)     at org.gs4tr.projectdirector.service.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:73)     at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4811)     at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5251)     在org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)

1 个答案:

答案 0 :(得分:0)

这是max-session属性的定义:

<xs:attribute name="max-sessions" type="xs:positiveInteger">
<xs:annotation>
<xs:documentation>
The maximum number of sessions a single authenticated user can have open at the same time. Defaults to "1".
</xs:documentation>
</xs:annotation>
</xs:attribute>

如您所见,该属性的类型为positiveInteger,您不能使用SpEL。

SpEL(例如获取属性值)是一个字符串,在某些情况下,您被允许use SpEL

  

可以使用表达式设置属性或构造函数-arg值,如下所示