Grails + Spring Security Rest,发出POST请求

时间:2015-04-15 07:20:56

标签: rest grails spring-security spring-security-rest

我能够登录(/ api / login)并且能够成功发出GET请求。但是,我似乎无法弄清楚如何发出POST请求,同样我也无法注销(/ api / logout)。

控制器:(com.example.test)

static allowedMethods = [secret:['POST', 'GET']]
@Secured(['ROLE_ADMIN'])
def secret() {
  render "You have ACCESS!!!"
}

登录(和HTTP响应):

curl -v -H "Content-Type: application/json" -X POST -d
  '{"username":"user", "password":"pass"}' 
  http://localhost:8080/restplug/api/login

< HTTP/1.1 200 OK
 {"username":"user","roles":"ROLE_ADMIN"],
 "access_token":"a2d4biqg7oqu0ig4m22pj20qsesva81d",
 "token_type":"Bearer"}

GET请求的卷曲(方法机密的示例):

curl -v -i -H "Authorization: Bearer a2d4biqg7oqu0ig4m22pj20qsesva81d" 
   -X GET http://localhost:8080/restplug/TestData/secret

我的POST请求总是会导致重定向到登录页面(即使我传递令牌)。 请展示如何使用curl或其他类似休息客户端(Postman)执行发布请求的示例。如果可能,还显示如何注销(/ api / logout)

配置
grails.plugin.springsecurity.rest.login.active =真 grails.plugin.springsecurity.rest.login.endpointUrl =&#39; / API /登录&#39; grails.plugin.springsecurity.rest.login.failureStatusCode = 401 grails.plugin.springsecurity.rest.login.useJsonCredentials =真 grails.plugin.springsecurity.rest.login.usernamePropertyName =&#39;用户名&#39; grails.plugin.springsecurity.rest.login.passwordPropertyName =&#39;密码&#39; grails.plugin.springsecurity.rest.logout.endpointUrl =&#39; / API /注销&#39; grails.plugin.springsecurity.rest.token.storage.useGorm = true grails.plugin.springsecurity.rest.token.storage.gorm.tokenDomainClassName =&#34; com.example.AuthenticationToken&#34; grails.plugin.springsecurity.rest.token.storage.gorm.tokenValuePropertyName =&#34; tokenValue&#34; grails.plugin.springsecurity.rest.token.storage.gorm.usernamePropertyName =&#39;用户名&#39; grails.plugin.springsecurity.rest.login.usernamePropertyName =&#39;用户名&#39; grails.plugin.springsecurity.rest.login.passwordPropertyName =&#39;密码&#39; grails.plugin.springsecurity.rest.token.generation.useSecureRandom = true

尝试使用失败的POST

以下是我尝试使用Curl和postman的一些内容:

 curl -v -X POST --form "access_token=bdv3de54oglo2i997k1tomvdgptm2ojq"
    http://localhost:8080/restplug/TestData/secret

 curl -v -X POST -H "Content-Type: application/x-www-form-urlencode"
    --form "access_token=bdv3de54oglo2i997k1tomvdgptm2ojq"
    http://localhost:8080/restplug/TestData/secret


并且还使用邮差(POST for logout附加图像):

0 个答案:

没有答案