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

@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验证

上一篇:[ACTF新生赛2020]Universe_final_answer(python z3库的使用)


下一篇:java常用类之String