Spring Security和JSON认证 [英] Spring Security and JSON Authentication

查看:283
本文介绍了Spring Security和JSON认证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在spring/spring-mvc中有一个完全使用JSON通信的应用程序. 现在,我需要通过JSON使用Spring Security 3(使用LdapAuthenticationProvider)对我的应用程序进行身份验证.

I've an application in spring/spring-mvc that totally uses JSON communications. Now I need to authenticate my application with spring security 3 (that uses LdapAuthenticationProvider) via JSON.

默认的春季seurity提交表单需要这样的POST:

The default spring seurity submit form requires a POST like this:

POST /myapp/j_spring_security_check HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: application/x-www-form-urlencoded
Content-Length: 32
Host: 127.0.0.1:8080
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)

j_username=myUsername&j_password=myPass

但是我想像这样传递一个JSON对象:

But I want to pass a JSON object like this:

{"j_username":"myUsername","j_password":"myPass"}

我读了很多帖子,例如其他没有运气,在所有的ajax情况下,都需要执行上述的POST.

I read many post like this, this other or this one without luck, in all ajax cases is done a POST like above.

有什么想法吗?

推荐答案

您可以编写自己的安全过滤器来解析JSON.

You can write your own security filter that will parse your JSON.

http://docs.spring.io/spring-security/site/docs/3.0.x/reference/core-web-filters.html

您可以使用BasicAuthenticationFilter作为参考:

You can use the BasicAuthenticationFilter as a reference:

http://docs.spring.io/spring-security/site/docs/3.0.x/apidocs/org/springframework/security/web/authentication/www/BasicAuthenticationFilter.html

这篇关于Spring Security和JSON认证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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