sách gpt4 ăn đã đi

java - 具有可变 URL 用户 ID 的 antMatchers Spring Security 模式

In lại Tác giả: IT Lão Cao 更新时间:2023-10-28 13:47:29 26 4
mua khóa gpt4 giày nike

我一直在寻找答案,但找不到任何有效的方法

在我的休息服务中,我在/account/{id}/download 下保留了一些功能,并且我想在 SecurityConfig java 文件中设置访问角色,只有 ROLE_TOKENSAVED 用户才能访问此网址

当 {id} 可变时,模式应该是什么样子?

我尝试了一些正则表达式模式,但没有达到我想要的效果,以下是我的一些尝试:

1. antMatchers("account/**/download").access(somerolehere)
2. antMatchers("account/\\d/download").access(somerolehere)
3. antMatchers("account/[\\d]/download").access(somerolehere)

提前感谢您的回答:)

biên tập:

    @Ghi đè
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/admin**").access("hasRole('ROLE_ADMIN')")
.antMatchers("/account*//**").access("hasRole('ROLE_USER') or hasRole('ROLE_ADMIN')")
.antMatchers("/account/\\d+/download").access("hasRole('ROLE_TOKENSAVED')")
.antMatchers("/user**").permitAll()
//othercode...
}

câu trả lời hay nhất

这对我有用:

antMatchers("/account/{\\d+}/download").access("hasAnyAuthority('ROLE_TOKENSAVED')")

注意表示 ID 的路径变量周围的花括号。

关于java - 具有可变 URL 用户 ID 的 antMatchers Spring Security 模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27649649/

26 4 0
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress