【发布时间】:2015-02-23 07:46:58
【问题描述】:
我一直在寻找答案,但找不到任何有效的方法
在我的休息服务中,我在 /account/{id}/download 下保留了一些功能,我想在 SecurityConfig java 文件中设置访问角色,只有 ROLE_TOKENSAVED 用户可以访问此 url
当 {id} 可变时,模式应该是什么样子?
我尝试了一些正则表达式模式,但没有达到我想要的效果,以下是我的一些尝试:
1. antMatchers("account/**/download").access(somerolehere)
2. antMatchers("account/\\d/download").access(somerolehere)
3. antMatchers("account/[\\d]/download").access(somerolehere)
提前感谢您的回答:)
编辑:
@Override
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...
}
【问题讨论】:
标签: java regex spring security spring-security