Example usage for javax.servlet.http HttpSession getId

List of usage examples for javax.servlet.http HttpSession getId

Introduction

In this page you can find the example usage for javax.servlet.http HttpSession getId.

Prototype

public String getId();

Source Link

Document

Returns a string containing the unique identifier assigned to this session.

Usage

From source file:gov.nih.nci.ncicb.cadsr.common.security.LogoutServlet.java

protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    //unlock all forms locked by this session
    HttpSession session = request.getSession();
    String logTjsp = getServletConfig().getInitParameter("LogthroughJSP");
    if (logTjsp != null && !logTjsp.equals(""))
        LOGTHROUGH_JSP = logTjsp;/*w  w  w  . j av  a  2  s  .  c  o  m*/

    String lojsp = getServletConfig().getInitParameter("LogoutJSP");
    if (lojsp != null && !lojsp.equals(""))
        LOGOUT_JSP = lojsp;
    String authjsp = getServletConfig().getInitParameter("ErrorJSP");
    if (authjsp != null && !authjsp.equals(""))
        AUTHORIZATION_ERROR_JSP = authjsp;

    if (!request.getContextPath().contains("CDEBrowser")) {
        getApplicationServiceLocator(session.getServletContext()).findLockingService()
                .unlockFormByUser(request.getRemoteUser());
    }
    synchronized (SessionUtils.sessionObjectCache) {
        log.error("LogoutServlet.doPost at start:" + TimeUtils.getEasternTime());
        String error = request.getParameter("authorizationError");
        String forwardUrl;
        //// GF29128 Begin. D.An, 20130729. 
        String un = (String) session.getAttribute("myUsername");
        ;
        ////   if (un == null)
        ////      un = "viewer";
        System.out.println("logoutServlet: " + session.getAttribute("myUsername"));
        if (error == null) {
            if (un.equals("viewer"))
                forwardUrl = LOGTHROUGH_JSP;
            //// GF29128  end.      
            else
                forwardUrl = LOGOUT_JSP;
        } else {
            forwardUrl = AUTHORIZATION_ERROR_JSP;
        }

        if ((session != null) && isLoggedIn(request)) {
            for (int i = 0; i < logoutKeys.length; i++) {
                session.removeAttribute(logoutKeys[i]);
            }

            //remove formbuilder specific objects
            //TODO has to be moved to an action
            Collection keys = (Collection) session.getAttribute(FormBuilderConstants.CLEAR_SESSION_KEYS);
            if (keys != null) {
                Iterator it = keys.iterator();
                while (it.hasNext()) {
                    session.removeAttribute((String) it.next());
                }
            }
            HashMap allMap = new HashMap();
            allMap.put(CaDSRConstants.GLOBAL_SESSION_KEYS, copyAllsessionKeys(session));
            allMap.put(CaDSRConstants.GLOBAL_SESSION_MAP, copyAllsessionObjects(session));
            SessionUtils.addToSessionCache(session.getId(), allMap);
            forwardUrl = forwardUrl + "?" + CaDSRConstants.PREVIOUS_SESSION_ID + "=" + session.getId();
            session.invalidate();
        }

        RequestDispatcher dispacher = request.getRequestDispatcher(forwardUrl);
        dispacher.forward(request, response);
        log.error("LogoutServlet.doPost at end:" + TimeUtils.getEasternTime());
    }
}

From source file:Controller.ProviderController.java

@RequestMapping(value = "/Password", method = RequestMethod.GET)
public String ProviderPassword(HttpServletRequest request) {
    try {//from w w  w .j  av  a  2  s  . c  o m
        request.setAttribute("page", "providerPassword");
        return "provider/password";
    } catch (Exception e) {
        HttpSession session = request.getSession();
        String content = "Function: ProviderController - ProviderPassword\n" + "****Error****\n"
                + e.getMessage() + "\n" + "**********";
        request.setAttribute("errorID", session.getId());
        request.setAttribute("errorTime", errorService.logBugWithAccount(content, session, e));
        return "forward:/Common/Error";
    }
}

From source file:Controller.ProviderController.java

@RequestMapping()
public String goToProviderPage(HttpServletRequest request) {
    try {//from w w  w .j ava 2  s  . c  o m
        if (request.getParameter("language") != null) {
            return "redirect:/Provider/AccountInfo" + "?language=" + request.getParameter("language");
        } else {
            return "redirect:/Provider/AccountInfo";
        }

    } catch (Exception e) {
        HttpSession session = request.getSession();
        String content = "Function: ProviderController - goToProviderPage\n" + "****Error****\n"
                + e.getMessage() + "\n" + "**********";
        request.setAttribute("errorID", session.getId());
        request.setAttribute("errorTime", errorService.logBugWithAccount(content, session, e));
        return "forward:/Common/Error";
    }
}

From source file:edu.harvard.i2b2.fhir.oauth2.ws.OAuth2AuthzEndpoint.java

@Path("processScope")
@GET//from   w  w w  .j  a  v  a2  s . c  o  m
public Response processResourceOwnerScopeChoice(@Context HttpServletRequest request) {
    try {
        logger.trace("processing scope: sessionid:" + request.getSession().getId());
        // save scope to session and
        // redirect to client uri
        HttpSession session = request.getSession();
        session.setAttribute("permittedScopes", "user/*.*");

        String msg = "";
        Enumeration x = session.getAttributeNames();
        while (x.hasMoreElements()) {
            String p = (String) x.nextElement();
            msg = msg + p + "=" + session.getAttribute(p).toString() + "\n";
        }
        logger.trace("sessionAttributes:" + msg);
        // create AuthToken in Database;

        String pmResponseXml = (String) session.getAttribute("pmResponseXml");
        if (pmResponseXml == null)
            throw new RuntimeException("PMRESPONSE NOT FOUND");

        String resourceUserId = (String) session.getAttribute("i2b2User");
        String i2b2Token = (String) I2b2Util.getToken(pmResponseXml);
        String authorizationCode = (String) session.getAttribute("authorizationCode");
        String clientRedirectUri = (String) session.getAttribute("redirectUri");
        String clientId = (String) session.getAttribute("clientId");
        String i2b2Project = (String) session.getAttribute("i2b2Project");
        String state = (String) session.getAttribute("state");
        String patientId = (String) session.getAttribute("patientId");

        HashSet<String> scopeHashSet = (HashSet<String>) session.getAttribute("scope");
        String scope = "";
        for (String s : scopeHashSet) {
            scope += "," + s;
        }
        scope = scope.substring(1);
        logger.debug(">>scopeHS=" + scopeHashSet.toString());
        //String scope = "user/*.*";//(String) session.getAttribute("scope");//"user/*.*";// 
        AuthToken authToken = authTokenBean.find(authorizationCode);
        if (authToken == null)
            authToken = authTokenBean.createAuthToken(authorizationCode, resourceUserId, i2b2Token,
                    clientRedirectUri, clientId, state, scope, i2b2Project, patientId);

        session.setAttribute("msg", "");

        //String finalUri = successfulResponse((HttpServletRequest) session.getAttribute("request"),scope,patientId,state);
        String finalUri = (String) session.getAttribute("finalUri");
        //+"&patient="+patientId.trim()   +"&scope="+patientId.trim();
        logger.trace("finalUri:" + finalUri);
        return Response.status(Status.MOVED_PERMANENTLY).location(new URI(finalUri))
                .header("session_id", session.getId()).build();
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        e.printStackTrace();
        return Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
    }
}

From source file:Login.java

public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {

    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    out.println("<html>");
    out.println("<head>");
    out.println("<title>Login</title>");
    out.println("</head>");
    out.println("<body>");

    HttpSession session = request.getSession();
    Connection connection = (Connection) session.getAttribute("connection");
    if (connection == null) {
        String userName = request.getParameter("username");
        String password = request.getParameter("password");
        if (userName == null || password == null) {
            // prompt the user for her username and password
            out.println("<form method=\"get\" action=\"Login\">");
            out.println("Please specify the following to log in:<p>");
            out.println("Username: <input type=\"text\" " + "name=\"username\" size=\"30\"><p>");
            out.println("Password: <input type=\"password\" " + "name=\"password\" size=\"30\"><p>");
            out.println("<input type=\"submit\" value=\"Login\">");
            out.println("</form>");
        } else {//from  ww w .ja v  a2 s . c o m
            // create the connection
            try {
                connection = DriverManager.getConnection("jdbc:oracle:thin:@dssw2k01:1521:orcl", userName,
                        password);
            } catch (SQLException e) {
                out.println("Login doGet() " + e.getMessage());
            }
            if (connection != null) {
                // store the connection
                session.setAttribute("connection", connection);
                response.sendRedirect("Login");
                return;
            }
        }
    } else {
        String logout = request.getParameter("logout");
        if (logout == null) {
            // test the connection
            Statement statement = null;
            ResultSet resultSet = null;
            String userName = null;
            try {
                statement = connection.createStatement();
                resultSet = statement.executeQuery("select initcap(user) from sys.dual");
                if (resultSet.next())
                    userName = resultSet.getString(1);
            } catch (SQLException e) {
                out.println("Login doGet() SQLException: " + e.getMessage() + "<p>");
            } finally {
                if (resultSet != null)
                    try {
                        resultSet.close();
                    } catch (SQLException ignore) {
                    }
                if (statement != null)
                    try {
                        statement.close();
                    } catch (SQLException ignore) {
                    }
            }
            out.println("Hello " + userName + "!<p>");
            out.println("Your session ID is " + session.getId() + "<p>");
            out.println("It was created on " + new java.util.Date(session.getCreationTime()) + "<p>");
            out.println("It was last accessed on " + new java.util.Date(session.getLastAccessedTime()) + "<p>");
            out.println("<form method=\"get\" action=\"Login\">");
            out.println("<input type=\"submit\" name=\"logout\" " + "value=\"Logout\">");
            out.println("</form>");
        } else {
            // close the connection and remove it from the session
            try {
                connection.close();
            } catch (SQLException ignore) {
            }
            session.removeAttribute("connection");
            out.println("You have been logged out.");
        }
    }
    out.println("</body>");
    out.println("</html>");
}

From source file:Controller.ProviderController.java

@RequestMapping(value = "/Sales")
public String getSales(ModelMap map, HttpSession session) {
    try {//from  w  w w .  j  a v  a2  s  .  c o  m
        return "provider/saleManagement";
    } catch (Exception e) {
        String content = "Function: ProviderController - getSales\n" + "****Error****\n" + e.getMessage() + "\n"
                + "**********";
        map.addAttribute("errorID", session.getId());
        map.addAttribute("errorTime", errorService.logBugWithAccount(content, session, e));
        return "forward:/Common/Error";
    }
}

From source file:Controller.ProviderController.java

@RequestMapping(value = "/SalesLeft")
public String getSalesLeft(ModelMap map, HttpSession session) {
    try {/*from  w w  w  . j a  v  a 2  s.  c  o m*/
        return "provider/saleManagementContentLeft";
    } catch (Exception e) {
        String content = "Function: ProviderController - getSales\n" + "****Error****\n" + e.getMessage() + "\n"
                + "**********";
        map.addAttribute("errorID", session.getId());
        map.addAttribute("errorTime", errorService.logBugWithAccount(content, session, e));
        return "forward:/Common/Error";
    }
}

From source file:Controller.ProviderController.java

@RequestMapping(value = "/Survey", method = RequestMethod.GET)
public String takeSurvey(ModelMap model, HttpSession session, HttpServletRequest request) {
    try {/*  ww  w. j av  a2s . co  m*/
        return "provider/apply";
    } catch (Exception e) {
        String content = "Function: ProviderController - takeSurvey\n" + "***Input***\n" + "**********\n"
                + "****Error****\n" + e.getMessage() + "\n" + "**********";
        model.addAttribute("errorID", session.getId());
        model.addAttribute("errorTime", errorService.logBugWithAccount(content, session, e));
        return "forward:/Common/Error";
    }
}

From source file:Controller.ProviderController.java

@RequestMapping(value = "/LoadLowestPackage", method = RequestMethod.POST)
public @ResponseBody String loadLowestPackage(ModelMap model, HttpSession session,
        @RequestBody final String data) {
    try {//from w  w  w. j  a  v  a 2  s . com
        return providerService.loadLowestPackage(data);
    } catch (Exception e) {
        String content = "Function: ProviderController - loadLowestPackage\n" + "****Error****\n"
                + e.getMessage() + "\n" + "**********";
        model.addAttribute("errorID", session.getId());
        model.addAttribute("errorTime", errorService.logBugWithAccount(content, session, e));
        return "forward:/Common/Error";
    }
}

From source file:Controller.ProviderController.java

@RequestMapping(value = "/LoadHighestPackage", method = RequestMethod.POST)
public @ResponseBody String loadHighestPackage(ModelMap model, HttpSession session,
        @RequestBody final String data) {
    try {/*from  ww w.ja v a2s .  co m*/
        return providerService.loadHighestPackage(data);
    } catch (Exception e) {
        String content = "Function: ProviderController - loadHighestPackage\n" + "****Error****\n"
                + e.getMessage() + "\n" + "**********";
        model.addAttribute("errorID", session.getId());
        model.addAttribute("errorTime", errorService.logBugWithAccount(content, session, e));
        return "forward:/Common/Error";
    }
}