首页 文章

Spring 季安全

提问于
浏览
0

我正在尝试在我的应用程序中使用spring security来开发restful web服务,而不是直接向j_spring_security_check发送请求的方式,以便我可以提供相同的url作为web服务来授权用户名和密码 .

目前我正在使用以下请求模式:

URL:“http:// localhost:8080 / CabFMS / j_spring_security_check”内容类型:application / x-www-form-urlencoded正文:{'j_username':'user','j_password':'123'}

响应:是凭据错误

我不确定Content-type和body参数 . 请提供建议 . 发送请求我正在使用REST客户端

塔伦古普塔

3 回答

  • 1

    正如您正确地注意到 j_spring_security_checks 期望application/x-www-form-urlencoded content,因此您需要对其进行编码:

    j_username=user&j_password=123
    
  • 0

    您的请求模式应该是:

    / j_spring_security_check?为j_username =用户为j_password = 123

    使用方法“POST”类型 .

    除此之外,您可以通过在属性中配置备用文本来更改请求操作和参数文本“j_spring_security_check”和“j_username”,“j_password”:

    login-processing-url,username-parameter,password-parameter

    安全配置xml文件中的spring“form-login”标记 .

  • 0

    为此创建一个 AuthenticationSuccessHadler ,在authenticationSuccess方法中,返回带有模式 username:password 的base64编码的授权头

    然后,在每个请求上,将标头设置为 Basic yourtokenhere

相关问题