java antmatchers,antMatchers春季安全格局多变的URL的用户ID

您需要使用正则表达式指定路径变量:

{spring:[a-z]+} matches the regexp [a-z]+ as a path variable named "spring"

如果不这样做,你可能会暴露其他途径。例如:

http .authorizeRequests() .antMatchers(HttpMethod.GET, "https://stackoverflow.com/users/{^[\\d]$}").authenticated() .antMatchers("https://stackoverflow.com/users/**").hasAuthority("admin")

,并在UserController的这些方法:

@ResponseBody

@RequestMapping(value = "https://stackoverflow.com/users/{userId}", method = RequestMethod.GET)

public User getUser(@PathVariable("userId") Object id) {

return userService.getUserById(userId);

}

@ResponseBody

@RequestMapping(value = "https://stackoverflow.com/users/roles", method = RequestMethod.GET)

public List getAllRoles() {

return userService.getAllRoles();

}

因为你没有指定路径变量,userId,用户将能够做的“/用户的GET请求/角色“而不具有管理权限。即使需要管理员授权,其他期货路线(如“/用户/测试”)也将被公开。为了防止这种情况:

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

如果你的路径变量的名称是“帐户ID”

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值