我正在使用 Spring 4 开发 REST API。我想使用 Spring Security 来保护一些端点,但根据我所读到的内容,可以使用以下任一方法来完成@EnableGlobalMethodSecurity
or @EnableWebSecurity
。不幸的是,我找到的这些文档并没有清楚地解释它们的作用(或它们如何比较)。如果我想通过基于标准关系数据库中声明的数据和关系的身份验证和授权来保护 Spring REST API,那么在 Spring 4 中实现此目的的推荐方法是什么?
EnableWebSecurity
将通过提供配置Http安全 http://docs.spring.io/spring-security/site/docs/current/reference/htmlsingle/#jc-httpsecurity。这是您可以找到的配置<http></http>
xml 配置中的标记,它允许您根据 url 模式、身份验证端点、处理程序等配置访问...
EnableGlobalMethodSecurity
为方法提供 AOP 安全性。它提供的一些注释是PreAuthorize
, PostAuthorize
。它还支持JSR-250 http://en.wikipedia.org/wiki/JSR_250. 配置中还有更多参数供您选择 http://docs.spring.io/spring-security/site/docs/current/reference/htmlsingle/#method-security-expressions
根据您的需要,最好将两者混合使用。通过 REST,您只需使用即可实现您需要的一切@EnableWebSecurity
since HttpSecurity#antMatchers(HttpMethod,String...)
接受对 Http 方法的控制
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)