Example usage for javax.servlet.http Cookie getName

List of usage examples for javax.servlet.http Cookie getName

Introduction

In this page you can find the example usage for javax.servlet.http Cookie getName.

Prototype

public String getName() 

Source Link

Document

Returns the name of the cookie.

Usage

From source file:com.citrix.cpbm.portal.fragment.controllers.AbstractManageResourceController.java

@RequestMapping(value = "/get_sso_cmd_string", method = RequestMethod.POST)
@ResponseBody/*from   ww w  .  j  a va2  s . co  m*/
public Map<String, String> getSSOCmdString(@ModelAttribute("currentTenant") Tenant tenant,
        @RequestParam(value = "tenant", required = false) String tenantParam,
        @RequestParam(value = "serviceInstanceUUID", required = true) String serviceInstanceUUID, ModelMap map,
        HttpServletRequest request, HttpServletResponse response) {

    logger.debug("### In getSSOCmdString  start method (POST)...");
    SsoObject ssoObject = new SsoObject();
    Tenant userTenant = (Tenant) request.getAttribute(UserContextInterceptor.EFFECTIVE_TENANT_KEY);
    Map<String, String> responseMap = new HashMap<String, String>();
    if (userTenant.getState() == Tenant.State.NEW) {
        responseMap.put("status", "fail");
        if ((Boolean) request.getAttribute("isSurrogatedTenant")) {
            responseMap.put("error_message",
                    messageSource.getMessage("message.user.no.billing", null, getSessionLocale(request)));
            responseMap.put("url", "/portal/portal/home");
        } else {
            responseMap.put("url", "/portal/portal/tenants/editcurrent");
        }
    } else {
        // if user logged in as root and try to access cloud resources under specific account then using the specific
        // account and account owner.
        SsoHandler ssoHandler = ((CloudConnector) connectorManagementService
                .getServiceInstance(serviceInstanceUUID)).getSSOHandler();
        if (ssoHandler != null) {
            if ((Boolean) request.getAttribute("isSurrogatedTenant")) {
                logger.trace("###SPI Calling SsoHandler.handleLogin(User) for user:" + userTenant.getOwner());
                ssoObject = ssoHandler.handleLogin(userTenant.getOwner());
                logger.trace("###SPI Called SsoHandler.handleLogin(User) for user:" + userTenant.getOwner());
            } else {
                logger.trace("###SPI Calling SsoHandler.handleLogin(User) for user:" + getCurrentUser());
                ssoObject = ssoHandler.handleLogin(getCurrentUser());
                logger.trace("###SPI Calling SsoHandler.handleLogin(User) for user:" + getCurrentUser());
            }
            if (ssoObject != null && ssoObject.getCookies().size() > 0) {
                for (Cookie cookie : ssoObject.getCookies()) {
                    response.addCookie(cookie);
                    logger.debug("Sending cookies:" + cookie.getName() + " domain:" + cookie.getDomain());
                }
            }
            responseMap.put("callback", ssoObject.getCallBack());
            responseMap.put("status", "success");
            responseMap.put("cmdString", ssoObject.getSsoString());
        } else {
            // if a connector is not implementing a ssoHandler, return success
            responseMap.put("status", "success");
        }
    }
    logger.debug("### getSSOCmdString method ending...(POST)");
    return responseMap;
}

From source file:com.hypersocket.session.json.SessionUtils.java

public Session getActiveSession(HttpServletRequest request) {

    Session session = null;/*from  w w  w  .  j a  v  a2s.  co  m*/

    if (request.getAttribute(AUTHENTICATED_SESSION) != null) {
        session = (Session) request.getAttribute(AUTHENTICATED_SESSION);
        if (sessionService.isLoggedOn(session, true)) {
            return session;
        }
    }
    if (request.getSession().getAttribute(AUTHENTICATED_SESSION) != null) {
        session = (Session) request.getSession().getAttribute(AUTHENTICATED_SESSION);
        if (sessionService.isLoggedOn(session, true)) {
            return session;
        }
    }
    for (Cookie c : request.getCookies()) {
        if (c.getName().equals(HYPERSOCKET_API_SESSION)) {
            session = sessionService.getSession(c.getValue());
            if (session != null && sessionService.isLoggedOn(session, true)) {
                return session;
            }
        }
    }

    if (request.getParameterMap().containsKey(HYPERSOCKET_API_KEY)) {
        session = sessionService.getSession(request.getParameter(HYPERSOCKET_API_KEY));
    } else if (request.getHeader(HYPERSOCKET_API_SESSION) != null) {
        session = sessionService.getSession((String) request.getHeader(HYPERSOCKET_API_SESSION));
    }

    if (session != null && sessionService.isLoggedOn(session, true)) {
        return session;
    }

    return null;
}

From source file:org.craftercms.engine.view.freemarker.CrafterFreeMarkerView.java

protected Map<String, String> createCookieMap(HttpServletRequest request) {
    Map<String, String> cookieMap = new HashMap<String, String>();
    Cookie[] cookies = request.getCookies();

    if (ArrayUtils.isNotEmpty(cookies)) {
        for (Cookie cookie : cookies) {
            cookieMap.put(cookie.getName(), cookie.getValue());
        }// w  ww  . j  a va 2 s  .  co  m
    }

    return cookieMap;
}

From source file:com.braintree.cscockpit.widgets.renderers.impl.customer.CustomerPaymentMethodAddWidgetRenderer.java

private String getNonceFromCookie() {
    final String nonce = null;
    final Cookie[] cookies = ((HttpServletRequest) Executions.getCurrent().getNativeRequest()).getCookies();

    for (final Cookie cookie : cookies) {
        if (COOKIE_PAYMENT_METHOD_NONCE.equals(cookie.getName())) {
            LOG.info("payment method nonce received from virtual client: " + nonce);
            return cookie.getValue();
        }/* w  w w.  j a  v  a 2 s .  c o  m*/
    }
    return nonce;
}

From source file:de.metas.procurement.webui.service.impl.LoginRememberMeService.java

private Cookie getRememberMeCookie() {
    final VaadinRequest vaadinRequest = VaadinService.getCurrentRequest();
    if (vaadinRequest == null) {
        logger.warn(/*from   w  w  w . ja v a2s. c  o m*/
                "Could not get the VaadinRequest. It might be that we are called from a websocket connection.");
        return null;
    }

    //
    // Get the remember me cookie
    final Cookie[] cookies = vaadinRequest.getCookies();
    if (cookies == null) {
        return null;
    }

    for (final Cookie cookie : cookies) {
        if (COOKIENAME_RememberMe.equals(cookie.getName())) {
            return cookie;
        }
    }

    return null;
}

From source file:cec.easyshop.storefront.filters.CartRestorationFilter.java

@Override
public void doFilterInternal(final HttpServletRequest request, final HttpServletResponse response,
        final FilterChain filterChain) throws IOException, ServletException {
    if (getUserService().isAnonymousUser(getUserService().getCurrentUser())) {
        if (getCartService().hasSessionCart() && getBaseSiteService().getCurrentBaseSite().equals(
                getBaseSiteService().getBaseSiteForUID(getCartService().getSessionCart().getSite().getUid()))) {
            final String guid = getCartService().getSessionCart().getGuid();

            if (!StringUtils.isEmpty(guid)) {
                getCartRestoreCookieGenerator().addCookie(response, guid);
            }/* w w w .  j  a  v  a  2  s .  co m*/
        } else if (request.getSession().isNew() || (getCartService().hasSessionCart()
                && !getBaseSiteService().getCurrentBaseSite().equals(getBaseSiteService()
                        .getBaseSiteForUID(getCartService().getSessionCart().getSite().getUid())))) {
            String cartGuid = null;

            if (request.getCookies() != null) {
                final String anonymousCartCookieName = getCartRestoreCookieGenerator().getCookieName();

                for (final Cookie cookie : request.getCookies()) {
                    if (anonymousCartCookieName.equals(cookie.getName())) {
                        cartGuid = cookie.getValue();
                        break;
                    }
                }
            }

            if (!StringUtils.isEmpty(cartGuid)) {
                getSessionService().setAttribute(WebConstants.CART_RESTORATION_SHOW_MESSAGE, Boolean.TRUE);
                try {
                    getSessionService().setAttribute(WebConstants.CART_RESTORATION,
                            getCartFacade().restoreSavedCart(cartGuid));
                } catch (final CommerceCartRestorationException e) {
                    getSessionService().setAttribute(WebConstants.CART_RESTORATION_ERROR_STATUS,
                            WebConstants.CART_RESTORATION_ERROR_STATUS);
                }
            }
        }

    } else {
        if ((!getCartService().hasSessionCart()
                && getSessionService().getAttribute(WebConstants.CART_RESTORATION) == null)
                || (getCartService().hasSessionCart()
                        && !getBaseSiteService().getCurrentBaseSite().equals(getBaseSiteService()
                                .getBaseSiteForUID(getCartService().getSessionCart().getSite().getUid())))) {
            getSessionService().setAttribute(WebConstants.CART_RESTORATION_SHOW_MESSAGE, Boolean.TRUE);
            try {
                getSessionService().setAttribute(WebConstants.CART_RESTORATION,
                        getCartFacade().restoreSavedCart(null));
            } catch (final CommerceCartRestorationException e) {
                getSessionService().setAttribute(WebConstants.CART_RESTORATION,
                        WebConstants.CART_RESTORATION_ERROR_STATUS);
            }
        }
    }

    filterChain.doFilter(request, response);
}

From source file:org.apache.hadoop.yarn.server.webproxy.amfilter.AmIpFilter.java

@Override
public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain)
        throws IOException, ServletException {
    if (!(req instanceof HttpServletRequest)) {
        throw new ServletException("This filter only works for HTTP/HTTPS");
    }//from ww  w . j a va  2 s  .c  om

    HttpServletRequest httpReq = (HttpServletRequest) req;
    HttpServletResponse httpResp = (HttpServletResponse) resp;
    if (LOG.isDebugEnabled()) {
        LOG.debug("Remote address for request is: " + httpReq.getRemoteAddr());
    }
    if (!getProxyAddresses().contains(httpReq.getRemoteAddr())) {
        String redirectUrl = findRedirectUrl();
        redirectUrl = httpResp.encodeRedirectURL(redirectUrl + httpReq.getRequestURI());
        httpResp.sendRedirect(redirectUrl);
        return;
    }

    String user = null;

    if (httpReq.getCookies() != null) {
        for (Cookie c : httpReq.getCookies()) {
            if (WebAppProxyServlet.PROXY_USER_COOKIE_NAME.equals(c.getName())) {
                user = c.getValue();
                break;
            }
        }
    }
    if (user == null) {
        LOG.warn("Could not find " + WebAppProxyServlet.PROXY_USER_COOKIE_NAME
                + " cookie, so user will not be set");
        chain.doFilter(req, resp);
    } else {
        final AmIpPrincipal principal = new AmIpPrincipal(user);
        ServletRequest requestWrapper = new AmIpServletRequestWrapper(httpReq, principal);
        chain.doFilter(requestWrapper, resp);
    }
}

From source file:org.bpmscript.web.BpmScriptCookieController.java

@SuppressWarnings("unchecked")
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response)
        throws Exception {

    response.setContentType(contentType);

    String requestUri = request.getRequestURI();
    String definitionName = null;
    String methodName = null;/*from w  w  w  .j  a va2 s .c  om*/
    String split[] = request.getRequestURI().split("/");
    if (requestUri.endsWith("/")) {
        definitionName = split[split.length - 1];
        methodName = defaultIndexName;
    } else {
        definitionName = split[split.length - 2];
        methodName = split[split.length - 1].split("\\.")[0];
    }

    String correlationIdParam = null;

    String cookieName = cookiePrefix + StringUtils.capitalize(definitionName)
            + StringUtils.capitalize(methodName);

    Cookie[] cookies = request.getCookies();
    for (Cookie cookie : cookies) {
        String name = cookie.getName();
        if (cookieName.equals(name)) {
            correlationIdParam = cookie.getValue();
        }
    }

    String timeoutParam = request.getParameter("timeout");
    long timeout = defaultTimeout;
    if (timeoutParam != null) {
        try {
            timeout = Integer.parseInt(timeoutParam);
        } catch (NumberFormatException e) {
            log.debug(e);
        }
    }
    try {
        SerializableHttpServletRequest serializableHttpServletRequest = new SerializableHttpServletRequest(
                request);
        if (correlationIdParam == null) {
            Object result = null;
            String conversationId = null;
            Object message = bpmScriptFacade.call(definitionName, methodName, timeout,
                    serializableHttpServletRequest);
            if (message instanceof IInvocationMessage) {
                IInvocationMessage conversationMessage = (IInvocationMessage) message;
                result = conversationMessage.getArgs()[0];
                conversationId = conversationMessage.getCorrelationId();
            } else {
                result = message;
            }
            if (result instanceof Map) {
                Map<String, Object> map = (Map<String, Object>) result;
                if (conversationId != null) {
                    map.put("conversationId", conversationId);
                    response.addCookie(new Cookie(cookieName, conversationId));
                }
                ModelAndView modelAndView = new ModelAndView((String) map.get("view"), map);
                return modelAndView;
            } else {
                throw new Exception("result must be a map or a conversation");
            }
        } else {

            IInvocationMessage conversationMessage = null;

            conversationMessage = (IInvocationMessage) conversationCorrelator.call(correlationIdParam, timeout,
                    serializableHttpServletRequest);

            if (conversationMessage != null) {
                Map<String, Object> result = (Map<String, Object>) conversationMessage.getArgs()[0];
                String conversationId = conversationMessage.getCorrelationId();
                result.put("conversationId", conversationId);
                String replyTo = conversationMessage.getReplyTo();
                Cookie cookie = new Cookie(cookieName, conversationId);
                if (replyTo == null) {
                    cookie.setMaxAge(0);
                }
                response.addCookie(cookie);
                ModelAndView modelAndView = new ModelAndView((String) result.get("view"), result);
                return modelAndView;
            } else {
                Cookie cookie = new Cookie(cookieName, "");
                cookie.setMaxAge(0);
                response.addCookie(cookie);
                throw new Exception("Did not get a response for message " + correlationIdParam);
            }
        }
    } catch (Throwable e) {
        if (e instanceof Exception) {
            throw (Exception) e;
        } else {
            throw new Exception(e);
        }
    }
}

From source file:org.alfresco.web.app.servlet.LanguageCookieFilter.java

protected void dumpCookies(ServletRequest servletRequest) {
    Cookie[] cookies = ((HttpServletRequest) servletRequest).getCookies();
    if (cookies == null)
        return;/*from  w ww  .j av  a 2 s .com*/
    Cookie cookie;
    for (int i = 0; i < cookies.length; i++) {
        cookie = cookies[i];
        System.out.println("Cookie Name: " + cookie.getName() + " Value:*" + cookie.getValue() + "*");
    }
}

From source file:net.longfalcon.web.BaseController.java

protected boolean isCookieSet(String cookieName, HttpServletRequest httpServletRequest) {
    try {//ww w . ja  v a  2s  .c o m
        Cookie[] cookies = httpServletRequest.getCookies();
        for (Cookie cookie : cookies) {
            if (cookie.getName().equals(cookieName) && ValidatorUtil.isNotNull(cookie.getValue())) {
                return true;
            }
        }
    } catch (Exception e) {
        _log.error(e);
    }
    return false;
}