jeudi 14 septembre 2017

Add method inside RequestMapping SpringBoot

I adding two factory authentication in my Java Web Project. In the login page, user have to key in username, password and security code (Secure code will start generate in login page). If these three matched, they can access to main page.

  @RequestMapping(value = "")
    public String login() throws InterruptedException, GeneralSecurityException {
        getSecureCode();
        return "login";   // return to login.jsp
    }

 public void getSecureCode() throws InterruptedException, GeneralSecurityException {

    String base32Secret = TimeBasedOneTimePasswordUtil.generateBase32Secret(16);
    String keyId = "abc123";
    logger.info("Image url = " + TimeBasedOneTimePasswordUtil.qrImageUrl(keyId, base32Secret));
    code = TimeBasedOneTimePasswordUtil.generateCurrentNumberString(base32Secret);
    while (true) {

        long diff = TimeBasedOneTimePasswordUtil.DEFAULT_TIME_STEP_SECONDS
                - ((System.currentTimeMillis() / 1000) % TimeBasedOneTimePasswordUtil.DEFAULT_TIME_STEP_SECONDS);
        code = TimeBasedOneTimePasswordUtil.generateCurrentNumberString(base32Secret);
        logger.info("Secret code = " + code + ", change in " + diff + " seconds");
        Thread.sleep(1000);
    }
}

 // after button in login.jsp clicked
 @RequestMapping(value = "check", method = RequestMethod.POST)

I added a getSecureCode method, so the user can get the security code inside the login page. Unfortunately, the web page not getting loaded! If I remove only it works! Do there any idea to solve ?

Aucun commentaire:

Enregistrer un commentaire