Example usage for javax.servlet.http HttpSession isNew

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

Introduction

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

Prototype

public boolean isNew();

Source Link

Document

Returns true if the client does not yet know about the session or if the client chooses not to join the session.

Usage

From source file:org.dvare.rest.resource.RuleEngineResource.java

@POST
public Response ruleEngine(@Context HttpServletRequest request, @Context UriInfo uriInfo) {
    HttpSession session = request.getSession();
    if (session.isNew() || session.getAttribute("registry") == null) {
        RuleEngineRegistry registry = new RuleEngineRegistry();
        session.setAttribute("registry", registry);
        session.setAttribute("counter", 0);
    }/*from w  w w . j a  v a  2 s  .c o  m*/

    RuleEngineRegistry registry = (RuleEngineRegistry) session.getAttribute("registry");
    Integer counter = (Integer) session.getAttribute("counter");
    session.setAttribute("counter", ++counter);
    String ruleEngine = registry.createNewEngine(request.getSession().getId() + counter);

    JSONObject message = new JSONObject();
    message.put("ruleEngine", ruleEngine);

    JSONArray links = ruleEngineLinks(ruleEngine, uriInfo);
    message.put("links", links);

    return Response.status(201).entity(message.toString()).build();
}

From source file:org.helios.ember.api.SFTPService.java

/**
 * Returns a file listing for the current SFTP context. If there is no current context, will list the root.
 * @param request The Http request/*from  ww w  .  j  a  v a2  s  .  c  o  m*/
 * @param path The path to list
 * @return A direcotry listing
 */
@GET
@Produces({ "application/json" })
@Path("/list/{path}")
public FileObjectWrapperCollection listPath(@Context HttpServletRequest request,
        @PathParam("path") String path) {
    if (path == null || path.trim().isEmpty()) {
        path = ".";
    }
    HttpSession session = request.getSession();
    boolean newSession = session.isNew();
    SessionLogin sessionLogin = (SessionLogin) securityContext.getUserPrincipal();
    if (newSession) {
        session.setAttribute("auth", sessionLogin);
    }

    try {
        FileObject fo = getFileObject(sessionLogin, path);

        return FileObjectWrapper.wrap(fo, fo.getChildren());
    } catch (FileSystemException e) {
        log.error("Failed to list into [" + path + "]", e);
        throw new WebApplicationException(e,
                new ResponseBuilderImpl().status(Status.INTERNAL_SERVER_ERROR).entity(
                        new GenericEntity<String>("{err:'Failed to list into " + path + "'}", String.class))
                        .build());
    }
}

From source file:org.emr.intercepter.RequestInterceptor.java

public boolean validateSession(HttpServletRequest request, HttpServletResponse response, FactoryBean loginBean)
        throws IOException, JSONException {
    HttpSession session = request.getSession();
    boolean status = true;
    if (session.isNew()) {
        System.out.println("new session found :");
        String username = (String) request.getParameter("username");
        String password = (String) request.getParameter("password");
        ArrayList<FactoryBean> factoryBean = model
                .select("from LoginBean where username = '" + username + "' and password = '" + password + "'");
        if (factoryBean.size() == 0) {
            System.out.println("invalidate session on first request if login failed:");
            session.invalidate();// w  w w.j a  va2 s.c  om
            return false;
        }
        /*
         * get user profile : 
         */
        loginBean = (LoginBean) factoryBean.get(0);
        System.out.println("username : " + username);
        session.setAttribute("loginBean", ((LoginBean) loginBean));
        session.setMaxInactiveInterval(60);
    }
    return status;
}

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

public String setAssociation(BaseAssociationForm baseAssociationForm) throws Exception {
    HttpServletRequest request = ServletActionContext.getRequest();
    HttpSession session = request.getSession();

    if (session.isNew() || (session.getAttribute(DisplayConstants.LOGIN_OBJECT) == null)) {
        if (logAssociation.isDebugEnabled())
            logAssociation.debug("||" + baseAssociationForm.getFormName()
                    + "|setAssociation|Failure|No Session or User Object Forwarding to the Login Page||");
        return ForwardConstants.LOGIN_PAGE;
    }/*from w  w  w . j ava  2  s.co  m*/
    try {
        session.setAttribute(DisplayConstants.CREATE_WORKFLOW, "0");
        UserProvisioningManager userProvisioningManager = (UserProvisioningManager) (request.getSession())
                .getAttribute(DisplayConstants.USER_PROVISIONING_MANAGER);
        baseAssociationForm.setRequest(request);
        baseAssociationForm.buildDisplayForm(userProvisioningManager);
        baseAssociationForm.setAssociationObject(userProvisioningManager);
        addActionMessage("Association Update Successful");
    } catch (CSException cse) {
        addActionError(org.apache.commons.lang.StringEscapeUtils.escapeHtml(cse.getMessage()));
        if (logAssociation.isDebugEnabled())
            logAssociation.debug(session.getId() + "|"
                    + ((LoginForm) session.getAttribute(DisplayConstants.LOGIN_OBJECT)).getLoginId() + "|"
                    + baseAssociationForm.getFormName()
                    + "|setAssociation|Failure|Error in setting Association for the "
                    + baseAssociationForm.getFormName() + " object|" + "|" + cse.getMessage());
    }
    session.setAttribute(DisplayConstants.CURRENT_ACTION, DisplayConstants.SEARCH);
    session.setAttribute(DisplayConstants.CURRENT_FORM, baseAssociationForm);
    if (logAssociation.isDebugEnabled())
        logAssociation.debug(session.getId() + "|"
                + ((LoginForm) session.getAttribute(DisplayConstants.LOGIN_OBJECT)).getLoginId() + "|"
                + baseAssociationForm.getFormName()
                + "|setAssociation|Success|Success in setting association for "
                + baseAssociationForm.getFormName() + " object|");
    return ForwardConstants.SET_ASSOCIATION_SUCCESS;
}

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

public String setAssociation(String[] associatedIds) throws Exception {
    HttpServletRequest request = ServletActionContext.getRequest();
    HttpSession session = request.getSession();

    if (session.isNew() || (session.getAttribute(DisplayConstants.LOGIN_OBJECT) == null)) {
        if (logAssociation.isDebugEnabled())
            logAssociation.debug("||" + applicationForm.getFormName()
                    + "|setAssociation|Failure|No Session or User Object Forwarding to the Login Page||");
        return ForwardConstants.LOGIN_PAGE;
    }/*from  w  w  w .  j av  a2s.  co m*/
    try {
        session.setAttribute(DisplayConstants.CREATE_WORKFLOW, "0");
        UserProvisioningManager userProvisioningManager = (UserProvisioningManager) (request.getSession())
                .getAttribute(DisplayConstants.USER_PROVISIONING_MANAGER);
        applicationForm.setRequest(request);
        applicationForm.buildDisplayForm(userProvisioningManager);
        applicationForm.setAssociatedIds(associatedIds);
        applicationForm.setAssociationObject(userProvisioningManager);
        addActionMessage("Association Update Successful");
    } catch (CSException cse) {
        cse.printStackTrace();
        addActionError(org.apache.commons.lang.StringEscapeUtils.escapeHtml(cse.getMessage()));
        if (logAssociation.isDebugEnabled())
            logAssociation.debug(session.getId() + "|"
                    + ((LoginForm) session.getAttribute(DisplayConstants.LOGIN_OBJECT)).getLoginId() + "|"
                    + applicationForm.getFormName()
                    + "|setAssociation|Failure|Error in setting Association for the "
                    + applicationForm.getFormName() + " object|" + "|" + cse.getMessage());
    }
    session.setAttribute(DisplayConstants.CURRENT_ACTION, DisplayConstants.SEARCH);
    session.setAttribute(DisplayConstants.CURRENT_FORM, applicationForm);
    if (logAssociation.isDebugEnabled())
        logAssociation.debug(session.getId() + "|"
                + ((LoginForm) session.getAttribute(DisplayConstants.LOGIN_OBJECT)).getLoginId() + "|"
                + applicationForm.getFormName() + "|setAssociation|Success|Success in setting association for "
                + applicationForm.getFormName() + " object|");
    return ForwardConstants.SET_ASSOCIATION_SUCCESS;
}

From source file:org.esgf.globusonline.GOauthView1Controller.java

@SuppressWarnings("unchecked")
@RequestMapping(method = RequestMethod.POST)
public ModelAndView doPost(final HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    //grab the dataset name, file names and urls from the query string
    String dataset_name = request.getParameter("id");
    String[] file_names = request.getParameterValues("child_id");
    String[] file_urls = request.getParameterValues("child_url");
    String esg_user = "";
    String esg_password = "";
    //String e;/*  w w  w. jav a2s .  c o m*/
    //grab the credential string
    String credential = request.getParameter("credential");
    System.out.println("Starting GlobusOnline workflow");
    //System.out.println("\n\n\n\t\tGO Credential " + credential + "\n\n\n");

    StringBuffer currentURL = request.getRequestURL();
    String currentURI = request.getRequestURI();
    //System.out.println("current URL is: " + currentURL);
    //System.out.println("current URI is: " + currentURI);
    //System.out.println("index is: " + currentURL.lastIndexOf(currentURI));
    String BaseURL = currentURL.substring(0, currentURL.lastIndexOf(currentURI));
    //System.out.println("BaseURL string is: " + BaseURL );

    //Instantiate model object:
    Map<String, Object> model = new HashMap<String, Object>();

    //Bail out if no gsiftp URLs are in file_names
    if (file_names != null) {
        for (int i = 0; i < file_names.length; i++) {
            if (!(file_urls[i] == null) && (file_urls[i].contains("gsiftp"))) {
                break;
            } else {
                model.put(GOFORMVIEW_ERROR, "error");
                String error_msg = "Selected dataset " + dataset_name
                        + " contains no GridFTP URLS, and cannot be transferred with this transfer method.";
                model.put(GOFORMVIEW_ERROR_MSG, error_msg);
                return new ModelAndView("goauthview3", model);
            }
        }
    } else {
        System.out.println("file_urls itself was null\n");
        model.put(GOFORMVIEW_ERROR, "error");
        String error_msg = "Selected dataset(s) " + dataset_name
                + " contain no GridFTP URLS, and cannot be transferred with this transfer method.";
        model.put(GOFORMVIEW_ERROR_MSG, error_msg);
        return new ModelAndView("goauthview3", model);
    }
    //Create a session if it doesn't already exist, so we can save state.
    HttpSession session = request.getSession(true);
    if (session.isNew() == false) {
        session.invalidate();
        session = request.getSession(true);
    }

    //System.out.println("Auth1, session id is:" + session.getId());

    session.setAttribute("fileUrls", file_urls);
    session.setAttribute("fileNames", file_names);
    session.setAttribute("datasetName", dataset_name);
    session.setAttribute("baseurl", BaseURL);
    if (!(credential == null)) {
        session.setAttribute("usercertificatefile", credential);
    }

    Cookie[] cookies = request.getCookies();
    String openId = "";

    for (int i = 0; i < cookies.length; i++) {
        if (cookies[i].getName().equals("esgf.idp.cookie")) {
            openId = cookies[i].getValue();
        }
    }

    LOG.debug("Got User OpenID: " + openId);
    // Create the client
    Properties GOProperties = getGOProperties();
    String PortalID = (String) GOProperties.getProperty("GOesgfPortalID", "bogususer");
    String PortalPass = (String) GOProperties.getProperty("GOesgfPortalPassword", "boguspassword");

    String loginUri = "";
    try {
        GoauthClient cli = new GoauthClient("nexus.api.globusonline.org", "globusonline.org", PortalID,
                PortalPass);
        cli.setIgnoreCertErrors(true);

        // Redirect the user agent to the globusonline log in page
        loginUri = cli.getLoginUrl(response.encodeURL(BaseURL + "/esgf-web-fe/goauthview2"));

    } catch (NexusClientException e) {
        System.out.println("ERROR:  GOesgfPortalID and/or GOesgfPortalPassword wrong or not set.");
        //            e.printStackTrace();
        model.put(GOFORMVIEW_ERROR, "error");
        String error_msg = "GlobusOnline Configuration file not found. Please create /esg/config/globusonline.properties and populate it with GOesgfPortalID and GOesgfPortalPassword";
        model.put(GOFORMVIEW_ERROR_MSG, error_msg);
        return new ModelAndView("goauthview3", model);
    }
    String myproxyServerStr = null;

    return new ModelAndView("redirect:" + loginUri, model);
}

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

public String loadAssociation(BaseAssociationForm baseAssociationForm) throws Exception {
    HttpServletRequest request = ServletActionContext.getRequest();
    HttpSession session = request.getSession();
    session.setAttribute(DisplayConstants.CREATE_WORKFLOW, "0");

    if (session.isNew() || (session.getAttribute(DisplayConstants.LOGIN_OBJECT) == null)) {
        if (logAssociation.isDebugEnabled())
            logAssociation.debug("||" + baseAssociationForm.getFormName()
                    + "|loadAssociation|Failure|No Session or User Object Forwarding to the Login Page||");
        return ForwardConstants.LOGIN_PAGE;
    }//  w w w .j a va2s .co  m
    try {
        UserProvisioningManager userProvisioningManager = (UserProvisioningManager) (request.getSession())
                .getAttribute(DisplayConstants.USER_PROVISIONING_MANAGER);
        baseAssociationForm.setRequest(request);
        baseAssociationForm.buildAssociationObject(userProvisioningManager);
    } catch (CSException cse) {
        addActionError(org.apache.commons.lang.StringEscapeUtils.escapeHtml(cse.getMessage()));
        if (logAssociation.isDebugEnabled())
            logAssociation.debug(session.getId() + "|"
                    + ((LoginForm) session.getAttribute(DisplayConstants.LOGIN_OBJECT)).getLoginId() + "|"
                    + baseAssociationForm.getFormName()
                    + "|loadAssociation|Failure|Error Loading Association for the "
                    + baseAssociationForm.getFormName() + "|" + cse.getMessage());
    }
    if (logAssociation.isDebugEnabled())
        logAssociation.debug(session.getId() + "|"
                + ((LoginForm) session.getAttribute(DisplayConstants.LOGIN_OBJECT)).getLoginId() + "|"
                + baseAssociationForm.getFormName()
                + "|loadAssociation|Success|Success in loading association for "
                + baseAssociationForm.getFormName() + " object|");
    return ForwardConstants.LOAD_ASSOCIATION_SUCCESS;
}

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

public String loadAssociation() throws Exception {
    HttpServletRequest request = ServletActionContext.getRequest();
    HttpSession session = request.getSession();
    session.setAttribute(DisplayConstants.CREATE_WORKFLOW, "0");

    if (session.isNew() || (session.getAttribute(DisplayConstants.LOGIN_OBJECT) == null)) {
        if (logAssociation.isDebugEnabled())
            logAssociation.debug("||" + applicationForm.getFormName()
                    + "|loadAssociation|Failure|No Session or User Object Forwarding to the Login Page||");
        return ForwardConstants.LOGIN_PAGE;
    }/*from w ww  .ja  v a 2  s  . c o  m*/
    try {
        UserProvisioningManager userProvisioningManager = (UserProvisioningManager) (request.getSession())
                .getAttribute(DisplayConstants.USER_PROVISIONING_MANAGER);
        applicationForm.setRequest(request);
        applicationForm.buildDisplayForm(userProvisioningManager);
        applicationForm.buildAssociationObject(userProvisioningManager);
    } catch (CSException cse) {
        addActionError(org.apache.commons.lang.StringEscapeUtils.escapeHtml(cse.getMessage()));
        if (logAssociation.isDebugEnabled())
            logAssociation.debug(session.getId() + "|"
                    + ((LoginForm) session.getAttribute(DisplayConstants.LOGIN_OBJECT)).getLoginId() + "|"
                    + applicationForm.getFormName()
                    + "|loadAssociation|Failure|Error Loading Association for the "
                    + applicationForm.getFormName() + "|" + cse.getMessage());
    }
    if (logAssociation.isDebugEnabled())
        logAssociation.debug(session.getId() + "|"
                + ((LoginForm) session.getAttribute(DisplayConstants.LOGIN_OBJECT)).getLoginId() + "|"
                + applicationForm.getFormName() + "|loadAssociation|Success|Success in loading association for "
                + applicationForm.getFormName() + " object|");
    return ForwardConstants.LOAD_ASSOCIATION_SUCCESS;
}

From source file:com.pedra.storefront.filters.UrlEncoderFilter.java

@Override
protected void doFilterInternal(final HttpServletRequest request, final HttpServletResponse response,
        final FilterChain filterChain) throws ServletException, IOException {
    if (LOG.isDebugEnabled()) {
        LOG.debug(" The incoming URL : [" + request.getRequestURL().toString() + "]");
    }//from  w w  w  .ja  va2 s  .  c om
    final List<UrlEncoderData> urlEncodingAttributes = getUrlEncoderFacade().variablesForUrlEncoding();
    if (urlEncodingAttributes != null && !urlEncodingAttributes.isEmpty()) {
        final HttpSession session = request.getSession(false);
        final UrlEncoderPatternData patternData = getUrlEncoderFacade().patternForUrlEncoding(
                request.getRequestURL().toString(), request.getContextPath(),
                (session != null && session.isNew()));
        final String patternBeforeProcessing = getSessionService()
                .getAttribute(WebConstants.URL_ENCODING_ATTRIBUTES);
        final String pattern = "/" + patternData.getPattern();
        if (!StringUtils.equalsIgnoreCase(patternBeforeProcessing, pattern)) {
            if (patternData.isRedirectRequired()) {
                String redirectUrl = StringUtils.replace(request.getRequestURL().toString(),
                        patternBeforeProcessing, pattern);
                final String queryString = request.getQueryString();
                if (StringUtils.isNotBlank(queryString)) {
                    redirectUrl = redirectUrl + "?" + queryString;
                }
                response.sendRedirect(redirectUrl);
            } else {
                getUrlEncoderFacade().updateUrlEncodingData();
            }
        }
        getSessionService().setAttribute(WebConstants.URL_ENCODING_ATTRIBUTES, pattern);
        final UrlEncodeHttpRequestWrapper wrappedRequest = new UrlEncodeHttpRequestWrapper(request,
                patternData.getPattern());
        wrappedRequest.setAttribute(WebConstants.URL_ENCODING_ATTRIBUTES, pattern);
        wrappedRequest.setAttribute("originalContextPath", request.getContextPath());
        if (LOG.isDebugEnabled()) {
            LOG.debug("ContextPath=[" + wrappedRequest.getContextPath() + "]" + " Servlet Path= ["
                    + wrappedRequest.getServletPath() + "]" + " Request Url= [" + wrappedRequest.getRequestURL()
                    + "]");
        }
        filterChain.doFilter(wrappedRequest, response);
    } else {
        if (LOG.isDebugEnabled()) {
            LOG.debug(" No URL attributes defined");
        }
        request.setAttribute(WebConstants.URL_ENCODING_ATTRIBUTES, "");
        filterChain.doFilter(request, response);
    }
}

From source file:com.acc.storefront.filters.UrlEncoderFilter.java

@Override
protected void doFilterInternal(final HttpServletRequest request, final HttpServletResponse response,
        final FilterChain filterChain) throws ServletException, IOException {
    if (LOG.isDebugEnabled()) {
        LOG.debug(" The incoming URL : [" + request.getRequestURL().toString() + "]");
    }// www  .java 2s. co  m
    final List<UrlEncoderData> urlEncodingAttributes = getUrlEncoderFacade().variablesForUrlEncoding();
    if (urlEncodingAttributes != null && !urlEncodingAttributes.isEmpty()) {
        final HttpSession session = request.getSession(false);
        final UrlEncoderPatternData patternData = getUrlEncoderFacade().patternForUrlEncoding(
                request.getRequestURI().toString(), request.getContextPath(),
                (session != null && session.isNew()));
        final String patternBeforeProcessing = getSessionService()
                .getAttribute(WebConstants.URL_ENCODING_ATTRIBUTES);
        final String pattern = "/" + patternData.getPattern();
        if (!StringUtils.equalsIgnoreCase(patternBeforeProcessing, pattern)) {
            if (patternData.isRedirectRequired()) {
                String redirectUrl = StringUtils.replace(request.getRequestURL().toString(),
                        patternBeforeProcessing + "/", pattern + "/");
                final String queryString = request.getQueryString();
                if (StringUtils.isNotBlank(queryString)) {
                    redirectUrl = redirectUrl + "?" + queryString;
                }
                response.sendRedirect(redirectUrl);
            } else {
                getUrlEncoderFacade().updateUrlEncodingData();
            }
        }
        getSessionService().setAttribute(WebConstants.URL_ENCODING_ATTRIBUTES, pattern);
        final UrlEncodeHttpRequestWrapper wrappedRequest = new UrlEncodeHttpRequestWrapper(request,
                patternData.getPattern());
        wrappedRequest.setAttribute(WebConstants.URL_ENCODING_ATTRIBUTES, pattern);
        wrappedRequest.setAttribute("originalContextPath",
                StringUtils.isBlank(request.getContextPath()) ? "/" : request.getContextPath());
        if (LOG.isDebugEnabled()) {
            LOG.debug("ContextPath=[" + wrappedRequest.getContextPath() + "]" + " Servlet Path= ["
                    + wrappedRequest.getServletPath() + "]" + " Request Url= [" + wrappedRequest.getRequestURL()
                    + "]");
        }
        filterChain.doFilter(wrappedRequest, response);
    } else {
        if (LOG.isDebugEnabled()) {
            LOG.debug(" No URL attributes defined");
        }
        request.setAttribute(WebConstants.URL_ENCODING_ATTRIBUTES, "");
        filterChain.doFilter(request, response);
    }
}