[英]Access control to rest services with spring-boot
我對彈簧靴的安全性有所了解。 我使用mongodb,spring-boot-starter-data-rest,spring-boot-starter-security和spring-boot-starter-web。 我使用了諸如REST服務之類的自動expos存儲庫的可能性。 我有兩個存儲庫用戶和客戶。 用戶存儲庫用於帳戶。 像這樣擴展WebSecurityConfigurerAdapter之后:
@Override
protected void configure(HttpSecurity http) throws Exception {
super.configure(http);
http.authorizeRequests()
.antMatchers("/users/**")
.hasRole("ADMIN").antMatchers("/", "/customers")
.hasRole("USER")
.anyRequest().authenticated()
.and()
.formLogin().permitAll();
}
A無法控制具有ADMIN角色的用戶對/ users /頁面的訪問。 訪問服務時我獲得了身份驗證,但是每個用戶(包括每個角色)都可以在任何地方訪問。 應該配置什么?
聽起來您需要研究一下Spring Security的“ 方法安全性表達式”功能。 特別是注釋@PreAuthorize
/ @PostAuthorize
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.