[英]User connected can't access to the page even if he has the expected roles to access to it
[英]Allow access to user in Spring Security if he has both roles
我正在使用Spring Security向我的應用程序的用戶提供訪問權限。 對於單個角色,我使用的是這樣的:
<security:intercept-url pattern="/rest/Admin" access="hasAuthority('Admin')" />
如果他同時具有Admin
和Employee
角色,我想為用戶提供對特定URL的訪問權限,但是我不確定如何執行此操作。
要使用表達式保護單個URL,首先需要將
<http>
元素中的use-expressions
屬性設置為true
。 然后,Spring Security將期望<intercept-url>
元素的access
屬性包含Spring EL表達式。 表達式的計算結果應為布爾值,定義是否應允許訪問。 例如:<http> <intercept-url pattern="/admin*" access="hasRole('admin') and hasIpAddress('192.168.1.0/24')"/> ... </http>
因此,您應該嘗試使用:
<security:intercept-url pattern="/rest/Admin"
access="hasAuthority('Admin') and hasAuthority('Employee')" />
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.