Skip to content

Latest commit

 

History

History
64 lines (44 loc) · 1.21 KB

保护方法调用.md

File metadata and controls

64 lines (44 loc) · 1.21 KB

使用注解保护方法

  • 配置
@Configuration
@EnableGlobalMethodSecurity(securedEnabled = true)
class Config1 extends GlobalMethodSecurityConfiguration{

}

@Secured

@Secured("ROLE_ADMIN")
    @RequestMapping("/home")
    @ResponseBody
    public String home(){
        return "home";
    }

使用表达式保护方法

  • 启用相关配置支持

    @EnableGlobalMethodSecurity(prePostEnabled = true)
  • 相关注解

    • @PreAuthorize :在方法调用前进行验证
    • @PostAuthorize:在方法调用后进行验证
    • @PreFilter :调用前对参数进行过滤
    • @PostFilter :调用后对返回结果进行过滤
@PreAuthorize("#id == 10")
public void invoke(Integer id){

}

定义许可计算器

  • 实现该接口
public interface PermissionEvaluator extends AopInfrastructureBean {

    boolean hasPermission(Authentication authentication, Object targetDomainObject,
            Object permission);

    boolean hasPermission(Authentication authentication, Serializable targetId,
            String targetType, Object permission);
}
  • 注册到Spring Security 中

批注 2019-06-22 153017