我一直在尋找答案高和低。我希望能夠通過Spring Security核心插件在Grails應用程序中發送JSON數據,以驗證身份驗證。我似乎無法得到這個工作。Grails彈簧安全插件AJAX認證
我試圖測試這個使用捲曲用下面的命令:
curl -v -H "Content-Type: application/json" -X POST --data @ajax_login.json http://localhost:8080/j_spring_security_check?ajax=true
我ajax_login.json看起來是這樣的:
{
"j_username":"[email protected]",
"j_password":"password"
}
我的回答是這樣的:
* About to connect() to localhost port 8080 (#0)
* Trying 127.0.0.1... connected
* Connected to localhost (127.0.0.1) port 8080 (#0)
> POST /j_spring_security_check?ajax=true HTTP/1.1
> User-Agent: curl/7.21.4 (universal-apple-darwin11.0) libcurl/7.21.4 OpenSSL/0.9.8r zlib/1.2.5
> Host: localhost:8080
> Accept: */*
> Content-Type: application/json
> Content-Length: 63
>
< HTTP/1.1 302 Moved Temporarily
< Server: Apache-Coyote/1.1
< Set-Cookie: JSESSIONID=974763464D383CD90962E8933DBB8335; Path=/
< Set-Cookie: grails_remember_me=""; Expires=Thu, 01-Jan-1970 00:00:10 GMT; Path=/
< Location: http://localhost:8080/login/authfail;jsessionid=974763464D383CD90962E8933DBB8335?ajax=true
< Content-Length: 0
< Date: Wed, 12 Dec 2012 22:53:27 GMT
<
* Connection #0 to host localhost left intact
* Closing connection #0
我希望按照LoginController的ajaxSuccess動作看到類似這樣的東西:
{
"success":true,
"username":"[email protected]"
}
或至少每LoginController中的ajaxfail行動失敗JSON:
{
"error":"#yourdoingitwrong"
}
僅供參考,我Config.groovy中有這樣的:
grails.plugins.springsecurity.interceptUrlMap = [
'/css/**': ['IS_AUTHENTICATED_ANONYMOUSLY'],
'/common.css': ['IS_AUTHENTICATED_ANONYMOUSLY'],
'/favicon.ico': ['IS_AUTHENTICATED_ANONYMOUSLY'],
'/images/**': ['IS_AUTHENTICATED_ANONYMOUSLY'],
'/js/**': ['IS_AUTHENTICATED_ANONYMOUSLY'],
'/login/**': ['IS_AUTHENTICATED_ANONYMOUSLY'],
'/logout/**': ['IS_AUTHENTICATED_ANONYMOUSLY'],
'/register/**': ['IS_AUTHENTICATED_ANONYMOUSLY'],
'/error/**': ['IS_AUTHENTICATED_ANONYMOUSLY'],
'/**': ['IS_AUTHENTICATED_REMEMBERED']
]
我已經子類GormUserDetailsService和重寫loadUserByUsername做我自己的查找,但傳入的用戶名是空白的......空字符串。我知道這一點,因爲我能夠在該方法中設置斷點,並且當我發送cURL命令時,執行結束於此。
我錯過了其他任何細節?
Http stats 302意味着重定向。如果您嘗試在登錄帖子後調用「位置」中顯示的網址,會發生什麼情況?在你的例子是:http:// localhost:8080/login/authfail; jsessionid = 974763464D383CD90962E8933DBB8335?ajax = true –