- 配置
@Configuration
@EnableGlobalMethodSecurity(securedEnabled = true)
class Config1 extends GlobalMethodSecurityConfiguration{
}
@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 中