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.有什么想法吗?

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

来自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/

点赞