Spring Security - 外化“需求渠道”的价值

时间:2012-08-29 13:22:28

标签: spring spring-security

我需要在Spring Security文件中支持HTTP和HTTPS,并在运行时动态切换。

所以我试图创建属性文件,其中包含任何/ http / https,但不会解析XML配置。

Spring Security配置:

<sec:http entry-point-ref="portalEntryPoint">
    <sec:anonymous />
    <sec:intercept-url pattern = "/portal" access="IS_AUTHENTICATED_ANONYMOUSLY"
            requires-channel="${user-security.login.channel}" />
    <!-- rest omitted -->
</sec:http>

属性文件:

user-security.login.channel=https

我收到以下错误:

Caused by: org.xml.sax.SAXParseException: cvc-enumeration-valid: Value '${user-security.login.channel}' is not facet-valid with respect to enumeration '[http, https, any]'. It must be a value from the enumeration.

我正在使用Spring 3和Spring Security 2.有什么想法吗?

2 个答案:

答案 0 :(得分:1)

这在Spring Security 2中是不可能的,您必须使用Spring Security 3.0 +

在Spring Security 3.0发布之前修复了有关此支持的an issue

答案 1 :(得分:1)

如果绝对必须使用配置文件来配置门户入口点。显然这意味着你的弹簧配置中有很多复制和粘贴....

来自springsource文档的示例:

<bean id="transferService" class="com.bank.service.internal.DefaultTransferService">
    <constructor-arg ref="accountRepository"/>
    <constructor-arg ref="feePolicy"/>
</bean>

<bean id="accountRepository" class="com.bank.repository.internal.JdbcAccountRepository">
    <constructor-arg ref="dataSource"/>
</bean>

<bean id="feePolicy" class="com.bank.service.internal.ZeroFeePolicy"/>

<beans profile="dev">
    <jdbc:embedded-database id="dataSource">
        <jdbc:script location="classpath:com/bank/config/sql/schema.sql"/>
        <jdbc:script location="classpath:com/bank/config/sql/test-data.sql"/>
    </jdbc:embedded-database>
</beans>

<beans profile="production">
    <jee:jndi-lookup id="dataSource" jndi-name="java:comp/env/jdbc/datasource"/>
</beans>

链接http://blog.springsource.com/2011/02/14/spring-3-1-m1-introducing-profile/