贫民窟里的程序高手

  博客园 :: 首页 :: 新随笔 :: 联系 :: 订阅 :: 管理 ::
@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;
}

 

posted on 2021-08-27 14:05  贫民窟里的程序高手  阅读(311)  评论(0)    收藏  举报