Example usage for javax.servlet.http Cookie getValue

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

Introduction

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

Prototype

public String getValue() 

Source Link

Document

Gets the current value of this Cookie.

Usage

From source file:eionet.webq.service.CDREnvelopeServiceImpl.java

@Override
public HttpHeaders getAuthorizationHeader(UserFile file) {
    HttpHeaders authorization = new HttpHeaders();
    if (file.isAuthorized()) {
        String authorizationInfo = file.getAuthorization();
        if (StringUtils.isNotEmpty(authorizationInfo)) {
            authorization.add("Authorization", authorizationInfo);
            LOGGER.info("Use basic auth for file: " + file.getId());
        }// www .  jav  a  2s .  co m
        String cookiesInfo = file.getCookies();
        if (StringUtils.isNotEmpty(cookiesInfo)) {
            Cookie[] cookies = cookiesConverter.convertStringToCookies(cookiesInfo);
            for (Cookie cookie : cookies) {
                authorization.add("Cookie", cookie.getName() + "=" + cookie.getValue());
                LOGGER.info("User cookie auth for file: " + file.getId());
            }
        }
    }
    return authorization;
}

From source file:com.streamsets.lib.security.http.SSOUserAuthenticator.java

String getAuthTokenFromCookie(HttpServletRequest httpReq) {
    Cookie cookie = getAuthCookie(httpReq);
    return (cookie == null) ? null : cookie.getValue();
}

From source file:org.obiba.shiro.web.filter.AuthenticationFilter.java

@Nullable
private Subject authenticateTicket(HttpServletRequest request) {
    Cookie ticketCookie = WebUtils.getCookie(request, OBIBA_COOKIE_ID);
    if (isValid(ticketCookie)) {
        String ticketId = ticketCookie.getValue();
        AuthenticationToken token = new TicketAuthenticationToken(ticketId, request.getRequestURI(),
                OBIBA_COOKIE_ID);/* w  w  w .  jav  a2s .c o m*/
        try {
            return getAuthenticationExecutor().login(token);
        } catch (AuthenticationException e) {
            return null;
        }
    }
    return null;
}

From source file:net.anthonychaves.bookmarks.web.PersistentLoginFilter.java

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {

    HttpServletRequest httpRequest = (HttpServletRequest) request;
    HttpServletResponse httpResponse = (HttpServletResponse) response;
    Cookie tokenCookie = getCookieByName(httpRequest.getCookies(), "loginToken");

    HttpSession session = httpRequest.getSession();
    User user = (User) session.getAttribute("user");

    if (user == null && tokenCookie != null) {
        user = tokenService.loginWithToken(tokenCookie.getValue());
        String tokenValue = tokenService.setupNewLoginToken(user);

        httpRequest.getSession().setAttribute("user", user);
        tokenCookie.setMaxAge(0);//from   w w  w. j  ava 2  s. c om
        httpResponse.addCookie(tokenCookie);

        tokenCookie = new Cookie("loginToken", tokenValue);
        tokenCookie.setPath("/bookmarks");
        tokenCookie.setMaxAge(168 * 60 * 60);
        httpResponse.addCookie(tokenCookie);
    }

    chain.doFilter(httpRequest, httpResponse);
}

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.  c  om*/

    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:com.datatorrent.stram.security.StramWSFilter.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   w w  w .j av a2 s .co m

    HttpServletRequest httpReq = (HttpServletRequest) req;
    HttpServletResponse httpResp = (HttpServletResponse) resp;
    if (LOG.isDebugEnabled()) {
        LOG.debug("Remote address for request is: " + httpReq.getRemoteAddr());
    }
    String requestURI = httpReq.getRequestURI();
    if (LOG.isDebugEnabled()) {
        LOG.debug("Request path " + requestURI);
    }
    boolean authenticate = true;
    String user = null;
    if (getProxyAddresses().contains(httpReq.getRemoteAddr())) {
        if (httpReq.getCookies() != null) {
            for (Cookie c : httpReq.getCookies()) {
                if (WEBAPP_PROXY_USER.equals(c.getName())) {
                    user = c.getValue();
                    break;
                }
            }
        }
        if (requestURI.equals(WebServices.PATH) && (user != null)) {
            String token = createClientToken(user, httpReq.getLocalAddr());
            if (LOG.isDebugEnabled()) {
                LOG.debug("Create token " + token);
            }
            Cookie cookie = new Cookie(CLIENT_COOKIE, token);
            httpResp.addCookie(cookie);
        }
        authenticate = false;
    }
    if (authenticate) {
        Cookie cookie = null;
        if (httpReq.getCookies() != null) {
            for (Cookie c : httpReq.getCookies()) {
                if (c.getName().equals(CLIENT_COOKIE)) {
                    cookie = c;
                    break;
                }
            }
        }
        boolean valid = false;
        if (cookie != null) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Verifying token " + cookie.getValue());
            }
            user = verifyClientToken(cookie.getValue());
            valid = true;
            if (LOG.isDebugEnabled()) {
                LOG.debug("Token valid");
            }
        }
        if (!valid) {
            httpResp.sendError(HttpServletResponse.SC_UNAUTHORIZED);
            return;
        }
    }

    if (user == null) {
        LOG.warn("Could not find " + WEBAPP_PROXY_USER + " cookie, so user will not be set");
        chain.doFilter(req, resp);
    } else {
        final StramWSPrincipal principal = new StramWSPrincipal(user);
        ServletRequest requestWrapper = new StramWSServletRequestWrapper(httpReq, principal);
        chain.doFilter(requestWrapper, resp);
    }
}

From source file:architecture.ee.web.struts2.action.support.FrameworkActionSupport.java

protected String getGuestProperty(String name) {
    Cookie cookie = CookieUtils.getCookie(ServletActionContext.getRequest(), name);
    if (cookie != null)
        return cookie.getValue();
    else/*from  w w  w  .  j  a va  2  s. com*/
        return null;
}

From source file:com.vmware.demo.HomeController.java

@RequestMapping(value = "/sso", method = RequestMethod.GET)
public String createForm(HttpServletRequest request, Locale locale, Model model) {
    if (null != request.getSession().getAttribute(ATTRIBUTE_SAML_CERTIFICATE)) {
        model.addAttribute(ATTRIBUTE_SAML_CERTIFICATE,
                request.getSession().getAttribute(ATTRIBUTE_SAML_CERTIFICATE));
    }/* w w w.  j  a v  a 2s  .c o  m*/
    if (null != request.getSession().getAttribute(ATTRIBUTE_IDP_URI)) {
        model.addAttribute(ATTRIBUTE_IDP_URI, request.getSession().getAttribute(ATTRIBUTE_IDP_URI));
    } else {
        String cookieValue = null;
        Cookie[] cookies = request.getCookies();
        if (null != cookies) {
            for (Cookie cookie : cookies) {
                if (COOKIE_NAME.equals(cookie.getName())) {
                    cookieValue = cookie.getValue();
                }
            }
        }
        if (null != cookieValue) {
        } else {
            model.addAttribute(ATTRIBUTE_IDP_URI, DEFAULT_SAML_CONSUMER);
        }
    }
    model.addAttribute(ATTRIBUTE_META_DATA, generateMetaData(request));
    model.addAttribute(ATTRIBUTE_RELAY_STATE, getURLWithContextPath(request));
    model.addAttribute("action", "setup");
    return "home";
}

From source file:de.anycook.session.Session.java

private void loginWithCookies(javax.servlet.http.Cookie[] cookies) throws IOException, SQLException {
    if (cookies == null) {
        return;//from  w  w w.  j av a 2 s.com
    }

    for (javax.servlet.http.Cookie cookie : cookies) {
        if (cookie.getName().equals("anycook")) {
            String cookieId = cookie.getValue();
            try {
                login(cookieId);
            } catch (DBUser.CookieNotFoundException | DBUser.UserNotFoundException e) {
                logger.warn(e, e);
            }
        }

        String fbCookieKey = "fbsr_" + FacebookHandler.APP_ID;
        if (cookie.getName().equals(fbCookieKey)) {
            String cookieValue = cookie.getValue();
            FacebookHandler.FacebookRequest request = FacebookHandler.decode(cookieValue);
            Long uid = Long.parseLong(request.user_id);
            try {
                facebookLogin(uid);
            } catch (User.LoginException | DBUser.UserNotFoundException e) {
                logger.warn(e, e);
            }
        }
    }
}

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;//w  w  w. j a v a  2s . c o  m
    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);
        }
    }
}