Spring Security - 权限注解

开启:

@EnableGlobalMethodSecurity(securedEnabled = true)

注解

使用场景:控制类中的方法上

作用:有该角色或权限时,可以执行 否则不能执行 会抛出异常

 

角色:@Secured({"ROLE_role1","ROLE_role2"}) 

权限:@PreAuthorize("hasAuthority('admin')" or "hasAnyAuthority('admin,root')")

 

@PostAuthorize("hasAuthority('admin\')" or "hasAnyAuthority('admin,root')") 方法执行之后执行,方法会执行但是不会返回数据给前端

还要设置一下开启

@EnableGlobalMethodSecurity(securedEnabled = true,prePostEnabled = true)

 

posted on 2022-06-11 22:11  每天积极向上  阅读(510)  评论(0编辑  收藏  举报

导航