Java Https Token认证,后端处理
程序员文章站
2023-12-21 18:25:16
...
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;
}
}
推荐阅读
-
Java Https Token认证,后端处理
-
java+react前后端分离项目处理重复提交问题
-
java实现基于JWT的token认证
-
Session与Token认证机制 前后端分离下如何登录
-
通过web.client.RestTemplate在java后端代码中发送https请求
-
【java后端】restTemplate异常处理
-
JAVA后端生成Token(令牌),用于校验客户端
-
httpclient访问需要客户端认证数字证书的https接口的处理方法
-
作为一个java后端程序员,我是怎么接手android项目,并完成移动端的pdf处理需求的?
-
spring boot+spring security+jwt+vue整合前后端分离token权限认证项目详细过程代码 含AES加密