Spring Security:Java Config:如何添加方法类型? [英] Spring Security: Java Config: How to add the method type?

查看:95
本文介绍了Spring Security:Java Config:如何添加方法类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Spring Securitys Java Config。

I'm using Spring Securitys Java Config.

想要翻译以下 XML

<intercept-url pattern="/login" access="permitAll" method="POST" />

使用 Java Config

http.authorizeUrls().antMatchers("/login").permitAll();

但有一个问题是:

我仍然可以在浏览器中使用/ login并执行GET-Request。但我只想通过POST访问网址。

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.

Quesion:

如何添加此>> method =POST<<到java配置?

How can I add this >> method="POST" << to java configuration?

推荐答案

如果你查看 antMatchers 方法,你会看到 HttpMethod 可以作为第一个参数传递。

If you'd check the documentation of antMatchers method, you will see that enumeration of HttpMethod can be passed as the first parameter.

所以这样的事情应该有效:

So something like this should work:

http.authorizeUrls().antMatchers(HttpMethod.POST, "/login").permitAll();

这篇关于Spring Security:Java Config:如何添加方法类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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