2013-08-22 61 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,雖然這是爲了方法的安全性。