首页 > 编程语言 > 详细

自己写的SpringBoot里的Controller加Auth验证

时间:2021-08-29 21:52:45      阅读:47      评论:0      收藏:0      [点我收藏+]
@RequestMapping("/user")
public String user(@RequestHeader(name="Authorization") String auth, @RequestBody Users items, HttpServletResponse response){
    if(!this.authRequest(auth)) {
        response.setStatus(401);
        return "";
    }
    ...
}

 

private Boolean authRequest(String auth){
    String authStr = Base64.decodeStr(auth.replaceAll("Basic ","").trim());
    String username = "";
    String password = "";
    if(authStr != null){
        username = authStr.split(":")[0];
        password = authStr.split(":")[1];
    }
    logger.info(authStr);
    if(auth == null){
        return false;
    }
    if(!username.equals("cmp") || !password.equals("Cmp@123")){
        return false;
    }

    return true;
}

 

自己写的SpringBoot里的Controller加Auth验证

原文:https://www.cnblogs.com/wpcnblog/p/15193524.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!