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.rembrandt.web.ajax.DynamicReportGenerator.java

public void generateDynamicReport(String key, Map<String, String> params) {
    String html = new String();

    HttpSession session = ExecutionContext.get().getSession(false);
    PresentationTierCache ptc = ApplicationFactory.getPresentationTierCache();
    BusinessTierCache btc = ApplicationFactory.getBusinessTierCache();
    HttpServletRequest request = ExecutionContext.get().getHttpServletRequest();
    //      HttpServletResponse response = ExecutionContext.get().getHttpServletResponse();

    //lets hold a list of xml generating jobs, so we dont keep kicking off the same job
    ArrayList jobs = session.getAttribute("xmlJobs") != null ? (ArrayList) session.getAttribute("xmlJobs")
            : new ArrayList();

    //only generate XML if its not already cached...leave off for debug
    if (ptc.getNonPersistableObjectFromSessionCache(session.getId(), key) == null && !jobs.contains(key)) {
        Object o = btc.getObjectFromSessionCache(session.getId(), key);
        Finding finding = (Finding) o;//ww  w  .j  av a 2s .  c o  m
        //generate the XML and cached it
        ReportGeneratorHelper.generateReportXML(finding);
        if (!jobs.contains(key))
            jobs.add(key);
        session.setAttribute("xmlJobs", jobs);
    }
    Object ob = ptc.getNonPersistableObjectFromSessionCache(session.getId(), key);
    if (ob != null && ob instanceof FindingReportBean) {
        try {
            FindingReportBean frb = (FindingReportBean) ob;
            Document reportXML = (Document) frb.getXmlDoc();

            html = ReportGeneratorHelper.renderReport(params, reportXML, "cc_report.xsl");

            jobs.remove(key);
            session.setAttribute("xmlJobs", jobs);
        } catch (Exception e) {
            html = "Error Generating the report.";
            StringWriter stack = new StringWriter();
            e.printStackTrace(new PrintWriter(stack));

            html = stack.toString();
        }
    } else {
        html = "Error generating the report";
    }
    //out the XHTML in the session for reference in presentation...could store in Prescache
    session.setAttribute(key + "_xhtml", html);
    return;
}

From source file:gov.nih.nci.ispy.web.ajax.DynamicReportGenerator.java

public void generateDynamicReport(String key, Map<String, String> params, String stylesheet) {
    String html = new String();

    HttpSession session = ExecutionContext.get().getSession(false);
    PresentationTierCache ptc = CacheFactory.getPresentationTierCache();
    BusinessTierCache btc = CacheFactory.getBusinessTierCache();
    HttpServletRequest request = ExecutionContext.get().getHttpServletRequest();
    //      HttpServletResponse response = ExecutionContext.get().getHttpServletResponse();

    //lets hold a list of xml generating jobs, so we dont keep kicking off the same job
    ArrayList jobs = session.getAttribute("xmlJobs") != null ? (ArrayList) session.getAttribute("xmlJobs")
            : new ArrayList();

    //only generate XML if its not already cached...leave off for debug
    //RCL - remove this constraint for now, to avoid caching for tasks with the same key/id
    //if(ptc.getPersistableObjectFromSessionCache(session.getId(), key) == null && !jobs.contains(key)) {
    Object o = btc.getObjectFromSessionCache(session.getId(), key);
    Finding finding = (Finding) o;//from   w w w  .  ja va 2s .  c o  m
    //generate the XML and cached it
    ReportGeneratorHelper.generateReportXML(finding);
    if (!jobs.contains(key))
        jobs.add(key);
    session.setAttribute("xmlJobs", jobs);
    //}
    Object ob = ptc.getPersistableObjectFromSessionCache(session.getId(), key);
    if (ob != null && ob instanceof FindingReportBean) {
        try {
            FindingReportBean frb = (FindingReportBean) ob;
            Document reportXML = (Document) frb.getXmlDoc();

            html = ReportGeneratorHelper.renderReport(params, reportXML, stylesheet);

            jobs.remove(key);
            session.setAttribute("xmlJobs", jobs);
        } catch (Exception e) {
            html = "Error Generating the report.";
        }
    } else {
        html = "Error generating the report";
    }
    //out the XHTML in the session for reference in presentation...could store in Prescache
    session.setAttribute(key + "_xhtml", html);
    return;
}

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

@Path("i2b2login")
@GET/* w  w  w .  j a  va  2s  . com*/
public Response srvResourceOwnerLoginPage(@Context HttpServletRequest request) throws URISyntaxException {
    HttpSession session = request.getSession();
    String msg = (String) session.getAttribute("msg");
    if (msg == null)
        msg = "";

    String loginPage = "<div align=\"center\">" + "<br><p style=\"color:red\">" + msg + "</p><br>"
            + "The application located at the following URL is requesting read access to i2b2 data accessible to your account:<br><bold>"
            + session.getAttribute("redirectUri") + "</bold></div><br><br>"
            + "<form align=\"center\" action=\"processi2b2login\" method=\"post\">"
            + " UserName:<br> <input type=\"text\" name=\"username\" value=\"demo\">"
            + "<br> Password:<br><input type=\"text\" name=\"password\" value=\"demouser\">"

            + "<br><br><input type=\"submit\" value=\"Submit\">" + "</form>";
    return Response.ok().entity(loginPage).header("session_id", session.getId()).build();
}

From source file:pivotal.au.se.gemfirexdweb.controller.QueryController.java

@RequestMapping(value = "/executequery", method = RequestMethod.GET)
public String executeQuery(@ModelAttribute("queryAttribute") QueryWindow queryAttribute, Model model,
        HttpServletResponse response, HttpServletRequest request, HttpSession session) throws Exception {
    if (session.getAttribute("user_key") == null) {
        logger.debug("user_key is null new Login required");
        response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login");
        return null;
    }/*from  w w w  . j  a v  a  2  s  .co  m*/

    logger.debug("Received request to action a query directly");

    UserPref userPrefs = (UserPref) session.getAttribute("prefs");

    ConnectionManager cm = ConnectionManager.getInstance();
    // retrieve connection
    Connection conn = cm.getConnection(session.getId());

    String query = request.getParameter("query");
    logger.debug("Query = " + query);

    QueryWindow qw = new QueryWindow();
    qw.setQuery(query);
    qw.setElapsedTime("N");
    qw.setExplainPlan("N");
    qw.setQueryCount("N");
    qw.setShowMember("N");

    CommandResult result = new CommandResult();
    String s = query.trim();

    if (determineQueryType(s).equals("SELECT")) {
        try {
            Result res = QueryUtil.runQuery(conn, query, userPrefs.getMaxRecordsinSQLQueryWindow());
            logger.debug("Query run");
            model.addAttribute("queryResults", res);
            model.addAttribute("queryAttribute", qw);
            model.addAttribute("querysql", query);

        } catch (Exception ex) {
            logger.debug("in here");
            result.setCommand(query);
            result.setMessage(ex.getMessage() == null ? "Unable to run query" : ex.getMessage());
            result.setRows(-1);
            model.addAttribute("result", result);
            model.addAttribute("query", query);
        }
    } else if (determineQueryType(s).equals("COMMIT")) {
        result = QueryUtil.runCommitOrRollback(conn, true, qw.getElapsedTime());
        model.addAttribute("result", result);
    } else if (determineQueryType(s).equals("ROLLBACK")) {
        result = QueryUtil.runCommitOrRollback(conn, false, qw.getElapsedTime());
        model.addAttribute("result", result);
    } else if (determineQueryType(s).equals("CALL")) {

        String procName = getProcName(s);

        if (procName != null) {
            String schema = null;

            int x = procName.indexOf(".");
            if (x != -1) {
                String newProcName = procName.substring((procName.indexOf(".") + 1));
                schema = procName.substring(0, (procName.indexOf(".")));
                procName = newProcName;
            } else {
                schema = (String) session.getAttribute("schema");
            }

            logger.debug("schema for stored procedure = " + schema);
            logger.debug("call statement called for proc with name " + procName);

            // need to get schema name to check proc details
            int numberOfDynamicResultSets = QueryUtil.checkForDynamicResultSetProc(conn, schema, procName);

            if (numberOfDynamicResultSets > 0) {
                logger.debug("call statement with " + numberOfDynamicResultSets + " dynamic resultset(s)");
                try {
                    List<Result> procResults = QueryUtil.runStoredprocWithResultSet(conn, s,
                            userPrefs.getMaxRecordsinSQLQueryWindow(), numberOfDynamicResultSets);
                    model.addAttribute("procresults", procResults);
                    model.addAttribute("callstatement", procName);
                    model.addAttribute("dynamicresults", numberOfDynamicResultSets);
                } catch (Exception ex) {
                    result.setCommand(s);
                    result.setMessage(ex.getMessage() == null ? "Unable to run query" : ex.getMessage());
                    result.setRows(-1);
                    model.addAttribute("result", result);
                    model.addAttribute("query", s);
                }
            } else {
                result = QueryUtil.runCommand(conn, s, qw.getElapsedTime());
                model.addAttribute("result", result);
            }
        } else {
            result = QueryUtil.runCommand(conn, s, qw.getElapsedTime());
            model.addAttribute("result", result);
        }
    } else {
        result = QueryUtil.runCommand(conn, s, qw.getElapsedTime());
        model.addAttribute("result", result);
    }

    return "query";
}

From source file:gov.nih.nci.security.upt.actions.CommonDBAction.java

public String loadHome(BaseDBForm form) throws Exception {
    HttpServletRequest request = ServletActionContext.getRequest();
    HttpSession session = request.getSession();

    if (session.isNew() || (session.getAttribute(DisplayConstants.LOGIN_OBJECT) == null)) {
        if (logDB.isDebugEnabled())
            logDB.debug("||" + form.getFormName()
                    + "|loadHome|Failure|No Session or User Object Forwarding to the Login Page||");
        return ForwardConstants.LOGIN_PAGE;
    }/*from   w  ww. ja  v a 2s  .  c  o  m*/

    session.removeAttribute(DisplayConstants.CURRENT_ACTION);
    session.removeAttribute(DisplayConstants.CURRENT_FORM);
    session.removeAttribute(DisplayConstants.SEARCH_RESULT);
    session.removeAttribute(DisplayConstants.CREATE_WORKFLOW);

    if (logDB.isDebugEnabled())
        logDB.debug(session.getId() + "|"
                + ((LoginForm) session.getAttribute(DisplayConstants.LOGIN_OBJECT)).getLoginId() + "|"
                + form.getFormName() + "|loadHome|Success|Load the Home Page||");

    return ForwardConstants.LOAD_HOME_SUCCESS;
}

From source file:gwtupload.server.UploadServlet.java

/**
 * This method parses the submit action, puts in session a listener where the
 * progress status is updated, and eventually stores the received data in
 * the user session./*from   www  . j a  v a2  s . c  o m*/
 *
 * returns null in the case of success or a string with the error
 *
 */
protected String parsePostRequest(HttpServletRequest request, HttpServletResponse response) {
    try {
        String delay = request.getParameter(PARAM_DELAY);
        String maxFilesize = request.getParameter(PARAM_MAX_FILE_SIZE);
        maxSize = maxFilesize != null && maxFilesize.matches("[0-9]*") ? Long.parseLong(maxFilesize) : maxSize;
        uploadDelay = Integer.parseInt(delay);
    } catch (Exception e) {
    }

    HttpSession session = request.getSession();

    logger.debug("UPLOAD-SERVLET (" + session.getId() + ") new upload request received.");

    AbstractUploadListener listener = getCurrentListener(request);
    if (listener != null) {
        if (listener.isFrozen() || listener.isCanceled() || listener.getPercent() >= 100) {
            removeCurrentListener(request);
        } else {
            String error = getMessage("busy");
            logger.error("UPLOAD-SERVLET (" + session.getId() + ") " + error);
            return error;
        }
    }

    // Create a file upload progress listener, and put it in the user session,
    // so the browser can use ajax to query status of the upload process
    listener = createNewListener(request);

    List<FileItem> uploadedItems;
    try {

        // Call to a method which the user can override
        checkRequest(request);

        // Create the factory used for uploading files,
        FileItemFactory factory = getFileItemFactory(getContentLength(request));
        ServletFileUpload uploader = new ServletFileUpload(factory);
        uploader.setSizeMax(maxSize);
        uploader.setFileSizeMax(maxFileSize);
        uploader.setProgressListener(listener);

        // Receive the files
        logger.debug("UPLOAD-SERVLET (" + session.getId() + ") parsing HTTP POST request ");
        uploadedItems = uploader.parseRequest(request);
        session.removeAttribute(getSessionLastFilesKey(request));
        logger.debug("UPLOAD-SERVLET (" + session.getId() + ") parsed request, " + uploadedItems.size()
                + " items received.");

        // Received files are put in session
        List<FileItem> sessionFiles = getMySessionFileItems(request);
        if (sessionFiles == null) {
            sessionFiles = new ArrayList<FileItem>();
        }

        String error = "";
        if (uploadedItems.size() > 0) {
            sessionFiles.addAll(uploadedItems);
            String msg = "";
            for (FileItem i : sessionFiles) {
                msg += i.getFieldName() + " => " + i.getName() + "(" + i.getSize() + " bytes),";
            }
            logger.debug("UPLOAD-SERVLET (" + session.getId() + ") puting items in session: " + msg);
            session.setAttribute(getSessionFilesKey(request), sessionFiles);
            session.setAttribute(getSessionLastFilesKey(request), uploadedItems);
        } else if (!isAppEngine()) {
            logger.error("UPLOAD-SERVLET (" + session.getId() + ") error NO DATA received ");
            error += getMessage("no_data");
        }
        return error.length() > 0 ? error : null;

        // So much silly questions in the list about this issue.
    } catch (LinkageError e) {
        logger.error("UPLOAD-SERVLET (" + request.getSession().getId() + ") Exception: " + e.getMessage() + "\n"
                + stackTraceToString(e));
        RuntimeException ex = new UploadActionException(getMessage("restricted", e.getMessage()), e);
        listener.setException(ex);
        throw ex;
    } catch (SizeLimitExceededException e) {
        RuntimeException ex = new UploadSizeLimitException(e.getPermittedSize(), e.getActualSize());
        listener.setException(ex);
        throw ex;
    } catch (UploadSizeLimitException e) {
        listener.setException(e);
        throw e;
    } catch (UploadCanceledException e) {
        listener.setException(e);
        throw e;
    } catch (UploadTimeoutException e) {
        listener.setException(e);
        throw e;
    } catch (Throwable e) {
        logger.error("UPLOAD-SERVLET (" + request.getSession().getId() + ") Unexpected Exception -> "
                + e.getMessage(), e);
        e.printStackTrace();
        RuntimeException ex = new UploadException(e);
        listener.setException(ex);
        throw ex;
    }
}

From source file:com.funambol.transport.http.server.Sync4jServlet.java

/**
 * Factory method for <i>SyncHolder</i> objects. If the underlying http session
 * contains a SyncHolder it is returned otherwise a new one is created and
 * stored in the session//from w w  w  . ja  v a2  s. co  m
 *
 * @param session the http session
 *
 * @return a <i>SyncHolder</i>
 * @throws java.lang.Exception if an error occurs
 *
 */
private SyncHolder createHolder(HttpSession session) throws Exception {

    String sessionId = session.getId();
    SyncHolder holder = (SyncHolder) session.getAttribute(SESSION_ATTRIBUTE_SYNC_HOLDER);

    if (holder == null) {

        if (log.isTraceEnabled()) {
            log.trace("Holder not found. A new holder will be created");
        }

        holder = (SyncHolder) getClass().forName(syncHolderClass).newInstance();

        holder.setSessionId(sessionId);
        session.setAttribute(SESSION_ATTRIBUTE_SYNC_HOLDER, holder);
    } else {
        if (log.isTraceEnabled()) {
            log.trace("Holder found");
        }
    }

    return holder;
}

From source file:com.aurel.track.attachment.AttachBL.java

public static Integer storeFile(Integer workItemID, Integer personID, String description, Locale locale,
        Map<String, Object> session, HttpServletResponse response, File file, String fileName,
        Double maxAttachmentSizeInMb, int MAXFILESIZE, List<LabelValueBean> errors, boolean addToHistory) {
    File f = file;/* w  ww. j  a  v a 2s. c  o m*/
    LOGGER.debug("upload path for file'" + fileName + "':" + f.getAbsolutePath());
    if (f.length() > MAXFILESIZE) {
        String err = getText("item.tabs.attachment.maxLengthExceeded",
                new String[] { maxAttachmentSizeInMb + "" }, locale);
        errors.add(new LabelValueBean(err, "theFile"));
        return null;
    }

    FileInputStream is;
    try {
        is = new FileInputStream(f);
    } catch (FileNotFoundException e) {
        LOGGER.debug(ExceptionUtils.getStackTrace(e));
        LOGGER.error("Error upload file" + f.getAbsolutePath() + " file not found!");
        String err = "File not found";
        errors.add(new LabelValueBean(err, "theFile"));
        return null;
    }
    ApplicationBean appBean = ApplicationBean.getInstance();
    if (appBean.isBackupInProgress()) {
        String err = getText("item.tabs.attachment.err.backupInProgress", locale);
        try {
            is.close();
        } catch (IOException ioe) {
            LOGGER.error("Unable to close input stream.");
        }
        errors.add(new LabelValueBean(err, "theFile"));
        return null;
    }
    if (workItemID == null/*||workItemID.intValue()==-1*/) {
        HttpServletRequest request = ServletActionContext.getRequest();
        HttpSession httpSession = request.getSession();
        WorkItemContext ctx = (WorkItemContext) session.get("workItemContext");
        if (ctx == null) {
            LOGGER.error("No context on session");
            try {
                is.close();
            } catch (IOException ioe) {
                LOGGER.error("Unable to close input stream.");
            }
            String err = "No context on session!";
            errors.add(new LabelValueBean(err, "theFile"));
            return null;
        }
        List<TAttachmentBean> attachments = ctx.getAttachmentsList();
        if (attachments == null) {
            attachments = new ArrayList<TAttachmentBean>();
        }
        String sessionID = httpSession.getId();
        Integer attachKey = null;
        try {
            attachKey = AttachBL.saveLocal(workItemID, description, fileName, is, attachments, sessionID,
                    personID);
        } catch (AttachBLException e) {
            String err = "";
            if (e.getLocalizedKey() != null) {
                err = getText(e.getLocalizedKey(), e.getLocalizedParameteres(), locale);
            } else {
                err = e.getMessage();
            }
            errors.add(new LabelValueBean(err, "theFile"));
            return null;
        }
        ctx.setAttachmentsList(attachments);
        f.delete();
        return attachKey;
    } else {
        try {
            TAttachmentBean attachmentBean = AttachBL.save(workItemID, description, fileName, is, personID);
            TPersonBean person = LookupContainer.getPersonBean(personID);
            LOGGER.debug("Saving attachment " + fileName + " by user " + person.getFullName());
            //add to history
            if (addToHistory) {
                HistorySaverBL.addAttachment(workItemID, personID, locale, fileName, description,
                        Long.valueOf(f.length()), false);
            }
            f.delete();
            return attachmentBean.getObjectID();
        } catch (AttachBLException e) {
            LOGGER.error("Can't save attachemnt", e);
            String err = "";
            if (e.getLocalizedKey() != null) {
                err = getText(e.getLocalizedKey(), e.getLocalizedParameteres(), locale);
            } else {
                err = e.getMessage();
            }
            errors.add(new LabelValueBean(err, "theFile"));
            return null;
        }
    }
}

From source file:edu.umich.ctools.sectionsUtilityTool.SectionsUtilityToolServlet.java

public void storeContext(Context context, HttpServletRequest request) {
    Map<String, String> ltiValues = new HashMap<String, String>();

    ViewToolContext vtc = (ViewToolContext) context;
    HttpServletResponse response = vtc.getResponse();
    HttpSession session = request.getSession(true);
    M_log.debug("session id: " + session.getId());

    HashMap<String, Object> customValuesMap = new HashMap<String, Object>();

    customValuesMap.put(CUSTOM_CANVAS_COURSE_ID, request.getParameter(CUSTOM_CANVAS_COURSE_ID));
    customValuesMap.put(CUSTOM_CANVAS_ENROLLMENT_STATE, request.getParameter(CUSTOM_CANVAS_ENROLLMENT_STATE));
    customValuesMap.put(CUSTOM_CANVAS_USER_LOGIN_ID, request.getParameter(CUSTOM_CANVAS_USER_LOGIN_ID));
    customValuesMap.put(LIS_PERSON_CONTACT_EMAIL_PRIMARY,
            request.getParameter(LIS_PERSON_CONTACT_EMAIL_PRIMARY));
    customValuesMap.put(LIS_PERSON_NAME_FAMILY, request.getParameter(LIS_PERSON_NAME_FAMILY));
    customValuesMap.put(LIS_PERSON_NAME_GIVEN, request.getParameter(LIS_PERSON_NAME_GIVEN));
    customValuesMap.put(CUSTOM_CANVAS_USER_ID, request.getParameter(CUSTOM_CANVAS_USER_ID));
    customValuesMap.put(SESSION_ROLES_FOR_ADDING_TEACHER,
            appExtPropertiesFile.getProperty(ROLE_CAN_ADD_TEACHER));

    TcSessionData tc = (TcSessionData) session.getAttribute(TC_SESSION_DATA);

    OauthCredentials oac = oacf.getOauthCredentials(ltiKey);

    if (tc == null) {
        tc = new TcSessionData(request, oac, customValuesMap);
    }// www  . ja  v  a2  s  . c o  m

    session.setAttribute(TC_SESSION_DATA, tc);
    M_log.debug("TC Session Data: " + tc.getUserId());

    // sanity check the result
    if (tc.getUserId() == null || tc.getUserId().length() == 0) {
        String msg = "Canvas Course Manager: tc session data is bad - userId is empty.";
        response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        M_log.error(msg);
        try {
            doError(request, response, "Canvas Course Manager LTI: tc session data is bad: userId is empty.");
        } catch (IOException e) {
            M_log.error("fillContext: IOException: ", e);
        }
        return;
    }

    if (customValuesMap.containsValue(null)) {
        String msg = "Canvas Course Manager: Found launch parameters null.";
        response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        M_log.error(msg);
        try {
            doError(request, response, "Canvas Course Manager LTI: null Launch parameter found.");
        } catch (IOException e) {
            M_log.error("fillContext: IOException: ", e);
        }
        return;
    }

    // Verify this is an LTI launch request and some of the required parameters (if not stub testing)
    if (!isStubTesting) {
        if (!SectionUtilityToolFilter.BASIC_LTI_LAUNCH_REQUEST
                .equals(request.getParameter(SectionUtilityToolFilter.LTI_MESSAGE_TYPE))
                || !LTI_1P0_CONST.equals(request.getParameter(LTI_VERSION)) || ltiKey == null) {
            try {
                M_log.debug("LTI request Message: "
                        + request.getParameter(SectionUtilityToolFilter.LTI_MESSAGE_TYPE));
                M_log.debug("LTI request Version: " + request.getParameter(LTI_VERSION));
                M_log.debug("LTI Key: " + ltiKey);
                doError(request, response,
                        "Missing required parameter:   LTI Message Type, LTI Version, or Consumer Key is incorrect.");
            } catch (IOException e) {
                M_log.error("fillContext: IOException: ", e);
            }
            return;
        }

        OauthCredentials oc = tc.getOauthCredentials();

        Boolean validMessage = checkForValidMessage(request, oc);
        if (!validMessage) {
            String msg = "Launch data does not validate";
            M_log.error(msg);
            return;
        }
    }

    // Fill context with the required lti values.
    // The VelocityViewServlet will take care of sending the processing on
    // to the proper velocity template.
    fillCcmValuesForContext(ltiValues, request);

    context.put("ltiValues", ltiValues);
}

From source file:com.adito.security.SessionInfo.java

private SessionInfo(int id, HttpSession session, String logonTicket, User user, InetAddress address, int type,
        String userAgent) {/*from  w w  w.jav a  2  s  .  c o  m*/
    attributes = new HashMap<String, Object>();
    this.user = user;
    this.id = id;
    this.session = session;
    this.logonTicket = logonTicket;
    this.address = address;
    navigationContext = USER_CONSOLE_CONTEXT;
    this.type = type;
    this.userAgent = userAgent;
    logonTime = new GregorianCalendar();
    lastAccessTime = System.currentTimeMillis();

    /**
     * Generate a unique session id
     */
    Hash hash = new Hash(new MD5Digest());
    hash.putString(String.valueOf(logonTime));
    if (session != null) {
        hash.putString(session.getId());
    }
    hash.putInt(id);
    hash.putString(user.getPrincipalName());
    hash.putString(address.getHostAddress());
    byte[] tmp = hash.doFinal();
    uid = Util.toHexString(tmp);

    CoreServlet.getServlet().addCoreListener(this);
}