Spring Security:Java Config:如何添加方法类型?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18399433/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Spring Security: Java Config: How to add the method type?
提问by DaUser
I'm using Spring Securitys Java Config.
我正在使用 Spring Securitys Java 配置。
Want to translate the following XML:
想要翻译以下XML:
<intercept-url pattern="/login" access="permitAll" method="POST" />
Got it working with Java Config:
让它与Java Config一起工作:
http.authorizeUrls().antMatchers("/login").permitAll();
But one problem is there:
但存在一个问题:
I can still use "/login" with a Browser and do a GET-Request. But I only want that the url can be accessed by POST.
我仍然可以在浏览器中使用“/login”并执行 GET-Request。但我只希望 url 可以通过 POST 访问。
Quesion:
问题:
How can I add this >> method="POST" << to java configuration?
如何将此 >> method="POST" << 添加到 java 配置?
采纳答案by Paulius Matulionis
If you'd check the documentation of antMatchersmethod, you will see that enumeration of HttpMethodcan be passed as the first parameter.
如果您查看antMatchers方法的文档,您会看到HttpMethod 的枚举可以作为第一个参数传递。
So something like this should work:
所以这样的事情应该有效:
http.authorizeUrls().antMatchers(HttpMethod.POST, "/login").permitAll();