1、测试场景
2、传递的参数为
{ "servicename":"bweb_mind"
}
3、服务端验证代码为
@RequestMapping(value = "/jenkinsconfirm/testtoken.do", method = RequestMethod.POST)
@ResponseBody
public String testtoken(HttpServletRequest request, HttpServletResponse response, @RequestBody JSONObject obj) throws Exception {
// String sessionAuth = (String) request.getSession().getAttribute("auth");
// if (sessionAuth != null) {
// System.out.println("this is next step");
// nextStep(request, response);
// } else {
if(!checkHeaderAuth(request, response)){
response.setStatus(401);
response.setHeader("Cache-Control", "no-store");
response.setDateHeader("Expires", 0);
response.setHeader("WWW-authenticate", "Basic Realm=\"test\"");
return "fail";
}
JSONObject jsonObject = JSONObject.fromObject(obj.toString());
String name=jsonObject.getString("servicename");
if(name.equals("bweb_mind")){
return "success";}
else return "servicename错误";
// }
}
private boolean checkHeaderAuth(HttpServletRequest request, HttpServletResponse response) throws IOException {
String auth = request.getHeader("Authorization");
System.out.println("auth encoded in base64 is " + getFromBASE64(auth));
if ((auth != null) && (auth.length() > 6)) {
auth = auth.substring(6, auth.length());
if(auth.equals("08*********"));
// String decodedAuth = getFromBASE64(auth);
// System.out.println("auth decoded from base64 is " + decodedAuth);
// request.getSession().setAttribute("auth", decodedAuth);
return true;
}else{
return false;
}
}
2279



被折叠的 条评论
为什么被折叠?



