簡體   English   中英

如果他同時擁有兩個角色,則允許在Spring Security中訪問用戶

[英]Allow access to user in Spring Security if he has both roles

我正在使用Spring Security向我的應用程序的用戶提供訪問權限。 對於單個角色,我使用的是這樣的:

<security:intercept-url pattern="/rest/Admin" access="hasAuthority('Admin')" />

如果他同時具有AdminEmployee角色,我想為用戶提供對特定URL的訪問權限,但是我不確定如何執行此操作。

根據Spring Security Reference

要使用表達式保護單個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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM