@EnableGlobalMethodSecurity与@EnableWebSecurity [英] @EnableGlobalMethodSecurity vs @EnableWebSecurity

查看:409
本文介绍了@EnableGlobalMethodSecurity与@EnableWebSecurity的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Spring 4开发REST API.我想使用Spring Security来保护某些端点,但是根据我所读的内容,可以使用@EnableGlobalMethodSecurity@EnableWebSecurity来完成此操作.不幸的是,我为这些工具找到的文档没有清楚地说明它们的作用(或它们之间的比较).如果我想基于标准关系数据库中声明的数据和关系通过身份验证和授权来保护Spring REST API,那么在Spring 4中推荐的方法是什么?

I am developing a REST API using Spring 4. I would like to secure some of the endpoints using Spring Security, but based on what I've read this can be done with either @EnableGlobalMethodSecurity or @EnableWebSecurity. Unfortunately, the documentation that I have found for these don't clearly explain what they do (or how they compare). If I want to secure a Spring REST API with authentication and authorization based on data and relationships declared in a standard relational database, what is the recommended method for achieving this in Spring 4?

推荐答案

EnableWebSecurity将通过

EnableWebSecurity will provide configuration via HttpSecurity providing the configuration you could find with <http></http> tag in xml configuration, it's allow you to configure your access based on urls patterns, the authentication endpoints, handlers etc...

EnableGlobalMethodSecurity提供方法的AOP安全性,它将启用的一些注释是PreAuthorize PostAuthorize,并且它对 JSR-250 . 配置中还有更多参数可用于你

EnableGlobalMethodSecurity provides AOP security on methods, some of annotation it will enable are PreAuthorize PostAuthorize also it has support for JSR-250. There is also more parameters in configuration for you

为满足您的需求,最好将两者结合在一起.借助REST,您可以仅使用@EnableWebSecurity来实现所需的一切,因为HttpSecurity#antMatchers(HttpMethod,String...)接受对Http方法的控制

For your needs, it's better mix the two. With REST you can achieve all you need only with @EnableWebSecurity, since HttpSecurity#antMatchers(HttpMethod,String...) accepts controls over Http methods

这篇关于@EnableGlobalMethodSecurity与@EnableWebSecurity的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆