/** * Logs off the currently logged user. */ public void logout() { session.setAttribute(ATTR_LOGGEDIN, null); }
if (request.getSession().getAttribute(attributeName) != null) { pageHits = Integer.parseInt((String) request.getSession().getAttribute(attributeName)); request.getSession().setAttribute(attributeName, Integer.toString(pageHits)); response.getWriter().println("<p>Session is new: " + request.getSession().isNew() + "</p>"); response.getWriter().println("<p>Session creation time: " + request.getSession().getCreationTime() + "</p>"); response.getWriter().println("<p>Session last accessed time: " + request.getSession().getLastAccessedTime() + "</p>"); response.getWriter().println("<p>Session max inactive interval in seconds: " + request.getSession().getMaxInactiveInterval() + "</p>");
/** * Tells whether the user is logged. * * @return */ public boolean isLogged() { if (session == null) { LOGGER.fine("No session, not logged in"); return false; } if (session.getAttribute(ATTR_LOGGEDIN) != null) { if (session.getAttribute(ATTR_LOGGEDIN).equals("1")) { return true; } else { LOGGER.fine("Not logging in - session attribute is NOT null"); } } else { LOGGER.fine("Not logging in - session attribute is null"); } return false; }
/** * Logs the user in if the login and password match. * * @param login * @param password * @return */ public boolean doLogin(final String login, final String password) { if (serverConfig.getAttribute("admin.login").equals(login) && serverConfig.getAttribute("admin.password").equals(password)) { session.setAttribute(ATTR_LOGGEDIN, "1"); return true; } else { LOGGER.fine("Not logging in - wrong password"); } return false; } }