2013-08-22 127 views
0

我想使用弹簧安全的spring bean来确定是否应该显示一个页面。下面是我希望做什么psudocode例如:春季安全使用Bean访问配置属性

<security:http use-expressions="true"> 
    <security:intercept-url pattern="/devlogin.html" access="someBean.isNotProduction()" /> 
</security:http> 

我知道的是,上述不工作,但希望它起到的是我正在寻找一个例子。我不想只告诉Spring“允许访问这样和那样的角色”,而是“如果你在测试系统上运行,允许访问”。我运气好还有一些这样的解决方案存在,还是这不是我所期望的Spring Security? (也许我甚至会听到有人说有这样一个页面是一个很大的安全禁忌,我可以批评它。)

+0

这可以帮助http://stackoverflow.com/questions/14141834/custom-securityexpressionroot-method-with-spring-security-3-1-3 – coder

回答

0

开发(或测试)特定的代码/页面在生产在我的书中总是一种不可行的,但正如我所说的那样,我的书:)。

访问属性被解析并可能包含SpEL expressions。您发布的示例代码几乎是正确的,只是用@前缀应该使其工作

security:http use-expressions="true"> 
    <security:intercept-url pattern="/devlogin.html" access="@someBean.isNotProduction()" /> 
</security:http> 

这应该在春季安全版本3.0和后续工作英寸

可能的related answer,虽然这是为了方法的安全性。