Chan Chun Weng
Chan Chun Weng

Reputation: 896

Spring security alert user before logout

here I have a change password page. And I will log the user out once the password has been changed successfully but I have to inform user that the password has been changed successfully before I log him/her out. How should I do the trick? Below is my code:

@RequestMapping(value = "/changepassword", method = RequestMethod.POST)
public String change(Model model, String oldPassword, String newPassword, Principal principal) throws NoSuchAlgorithmException {

    //Some method

        return "redirect:/somename/j_spring_security_logout";
    }
}

I guess it is a simple trick but I just can't figure it out..

Upvotes: 0

Views: 215

Answers (1)

vanpavel
vanpavel

Reputation: 106

I see 2 options:

1.Just make an ajax call to change the password. And then redirect on client side instead of server side. For example (mnemo code in javascript)

ajaxCall.success = {
    showMessage("Your session will be terminated. Please login again.")
    //wait for 3 seconds and then redirect
    setTimeout(function(){ window.location = "/somename/j_spring_security_logout" }, 3000);

} 

2.Keep the code as is, just add a request parameter on redirect:

return "redirect:/somename/j_spring_security_logout?notify_about_password=true";

On your logout page add some extra-logic to handle this request parameter.

Upvotes: 1

Related Questions