Security SpringMVC:如何在请求体中要求POST参数并忽略查询字符串参数?

Security SpringMVC:如何在请求体中要求POST参数并忽略查询字符串参数?,security,authentication,spring-mvc,Security,Authentication,Spring Mvc,我有一个提供身份验证web服务的简单控制器。它接受用户名和密码作为POST参数,并返回JSON结果。由于密码正在提交,我不想鼓励任何人在查询字符串中提交密码。我想强制要求它只在请求主体中被接受。这将确保对发布的值进行ssl加密。我如何在Sping MVC中实现这一点 @RequestMapping(value = "/authenticate", method = RequestMethod.POST) public ResponseEntity<String> handle

我有一个提供身份验证web服务的简单控制器。它接受用户名和密码作为POST参数,并返回JSON结果。由于密码正在提交,我不想鼓励任何人在查询字符串中提交密码。我想强制要求它只在请求主体中被接受。这将确保对发布的值进行ssl加密。我如何在Sping MVC中实现这一点

@RequestMapping(value = "/authenticate", method = RequestMethod.POST)
    public ResponseEntity<String> handleAuthenticateGet(
            @RequestParam(value = PRAConstants.USERNAME) String username,
            @RequestParam(value = PRAConstants.PASSWORD) String password)
    {
        boolean authSuccess = LDAPUtil.authenticateUser(username, password);
        HttpHeaders responseHeaders = new HttpHeaders();
        responseHeaders.setContentType(MediaType.APPLICATION_JSON);
        return new ResponseEntity<String>("{\"result\":" + authSuccess + "}", responseHeaders, HttpStatus.OK);
    }
}
@RequestMapping(value=“/authenticate”,method=RequestMethod.POST)
公共响应handleAuthenticateGet(
@RequestParam(value=practants.USERNAME)字符串用户名,
@RequestParam(值=practants.PASSWORD)字符串(密码)
{
布尔authSuccess=LDAPUtil.authenticateUser(用户名、密码);
HttpHeaders responseHeaders=新的HttpHeaders();
setContentType(MediaType.APPLICATION_JSON);
返回新的ResponseEntity(“{\“result\”:“+authSuccess+”}”,responseHeaders,HttpStatus.OK);
}
}

根据Lee Meador,我添加了以下内容:

boolean authSuccess = false;
// if password is passed on the query string, then always return false. otherwise, go ahead and check with ldap
if ( !StringUtils.contains(request.getQueryString(), PRAConstants.PASSWORD) )
{
    authSuccess = LDAPUtil.authenticateUser(username, password);
}

这对我很有用…

查看HTTP请求以找到实际的完整URL并验证否parameters@LeeMeador:那对我很有用。我将其作为解决方案发布—检查request.getQueryString()。谢谢@Jaffadog,你找到什么惯用的方法来代替StringUtils吗?