I am trying to write an application for the Google engine that will be available only to me. (I know this sounds weird ... for now). I am trying to write a login servlet that will authenticate a user using Google UserService and allow the user to log into the application only if I log in and show a short message asking everyone else to log out.
Here is the code I wrote:
public class MainPageServlet extends HttpServlet { public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { resp.setHeader("Cache-Control", "no-store, no-cache, must-revalidate"); resp.setContentType("text/html"); UserService userService = UserServiceFactory.getUserService(); User user = userService.getCurrentUser(); if (user != null) { if(user.getEmail().equals(" aaadith@gmail.com ")) { resp.getWriter().println("done"); } else { resp.getWriter().println("Hello, " + user.getNickname()+"<br>"); resp.getWriter().println("Thanks for your interest. But this application is still not available to everybody."); resp.getWriter().println("<a href="+UserServiceFactory.getUserService().createLogoutURL(userService.createLoginURL(req.getRequestURI()))+">Log out</a>"); } } else { resp.sendRedirect(userService.createLoginURL(req.getRequestURI())); } }
}
The code associated with the "distillation" of all other users works fine. But I ran into problems when logging in: after logging in, it displays a โdoneโ message, as expected. However, after that, if I open some other google service and exit it and call this servlet again, it will still display the message โdoneโ. I expected the application to prompt me to log in again. This is not happening. I thought this was happening because the result is cached and caching is disabled (the 1st line in the method) so ... but the problem persists even after that ... is something wrong? How to get the expected behavior?
source share