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.atlassian.jira.security.xsrf.SimpleXsrfTokenGenerator.java

@Override
public String getToken(HttpServletRequest request) {
    final Cookie[] cookies = request.getCookies();
    if (cookies != null) {
        for (Cookie cookie : cookies) {
            if (TOKEN_HTTP_SESSION_KEY.equalsIgnoreCase(cookie.getName())) {
                return htmlEncode(cookie.getValue());
            }//from   w  w w .  j av a 2  s.c om
        }
    }
    return null;
}

From source file:com.glaf.core.util.RequestUtils.java

public static String getActorId(HttpServletRequest request) {
    String actorId = null;//from   ww  w . ja v a2 s.c  o  m
    String ip = getIPAddress(request);
    ip = DigestUtils.md5Hex(ip);
    HttpSession session = request.getSession(false);
    if (session != null) {
        String value = (String) session.getAttribute(Constants.LOGIN_INFO);
        Map<String, String> cookieMap = decodeValues(ip, value);
        if (StringUtils.equals(cookieMap.get(Constants.LOGIN_IP), ip)) {
            actorId = cookieMap.get(Constants.LOGIN_ACTORID);
            logger.debug("#actorId=" + actorId);
        }
    }

    if (actorId == null) {
        Cookie[] cookies = request.getCookies();
        if (cookies != null && cookies.length > 0) {
            for (Cookie cookie : cookies) {
                if (StringUtils.equals(cookie.getName(), Constants.COOKIE_NAME)) {
                    String value = cookie.getValue();
                    Map<String, String> cookieMap = decodeValues(ip, value);
                    // logger.debug("#cookieMap=" + cookieMap);
                    if (StringUtils.equals(cookieMap.get(Constants.LOGIN_IP), ip)) {
                        String time = cookieMap.get(Constants.TS);
                        long now = Long.MAX_VALUE - System.currentTimeMillis();
                        if (StringUtils.isNumeric(time)
                                && (Long.parseLong(time) - now) < COOKIE_LIVING_SECONDS * 1000) {
                            actorId = cookieMap.get(Constants.LOGIN_ACTORID);
                            break;
                        }
                    }
                }
            }
        }
    }

    logger.debug("@actorId=" + actorId);

    return actorId;
}

From source file:com.glaf.core.util.RequestUtils.java

public static String getCurrentSystem(HttpServletRequest request) {
    String currentSystem = null;//w w w  .  ja  v a  2 s . c om
    String paramValue = request.getParameter(Constants.SYSTEM_NAME);
    if (StringUtils.isNotEmpty(paramValue)) {
        return paramValue;
    }
    String ip = getIPAddress(request);
    ip = DigestUtils.md5Hex(ip);
    HttpSession session = request.getSession(false);
    if (session != null) {
        String value = (String) session.getAttribute(Constants.LOGIN_INFO);
        Map<String, String> cookieMap = decodeValues(ip, value);
        if (StringUtils.equals(cookieMap.get(Constants.LOGIN_IP), ip)) {
            currentSystem = cookieMap.get(Constants.SYSTEM_NAME);
        }
    }

    if (currentSystem == null) {
        Cookie[] cookies = request.getCookies();
        if (cookies != null && cookies.length > 0) {
            for (Cookie cookie : cookies) {
                if (StringUtils.equals(cookie.getName(), Constants.COOKIE_NAME)) {
                    String value = cookie.getValue();
                    Map<String, String> cookieMap = decodeValues(ip, value);
                    if (StringUtils.equals(cookieMap.get(Constants.LOGIN_IP), ip)) {
                        String time = cookieMap.get(Constants.TS);
                        long now = Long.MAX_VALUE - System.currentTimeMillis();
                        if (StringUtils.isNumeric(time)
                                && (Long.parseLong(time) - now) < COOKIE_LIVING_SECONDS * 1000) {
                            currentSystem = cookieMap.get(Constants.SYSTEM_NAME);
                            break;
                        }
                    }
                }
            }
        }
    }

    return currentSystem;
}

From source file:com.googlesource.gerrit.plugins.github.oauth.OAuthWebFilter.java

private Cookie getGerritCookie(HttpServletRequest httpRequest) {
    for (Cookie cookie : getCookies(httpRequest)) {
        if (cookie.getName().equalsIgnoreCase(GERRIT_COOKIE_NAME)) {
            return cookie;
        }/*from ww  w  .  j  av  a2 s  .c  om*/
    }
    return null;
}

From source file:nl.surfnet.coin.teams.interceptor.LoginInterceptor.java

private String getTeamsCookie(HttpServletRequest request) {
    String result = "";
    Cookie[] cookies = request.getCookies();
    if (null != cookies) {
        for (Cookie current : cookies) {
            if (current.getName().equals(TEAMS_COOKIE)) {
                result = current.getValue();
                break;
            }/*from   w w w .ja v a  2  s  . c o  m*/
        }
    }
    return result;
}

From source file:com.exxonmobile.ace.hybris.storefront.interceptors.beforecontroller.RequireHardLoginBeforeControllerHandler.java

@Override
public boolean beforeController(final HttpServletRequest request, final HttpServletResponse response,
        final HandlerMethod handler) throws Exception {
    // We only care if the request is secure
    if (request.isSecure()) {
        // Check if the handler has our annotation
        final RequireHardLogIn annotation = findAnnotation(handler, RequireHardLogIn.class);
        if (annotation != null) {
            boolean redirect = true;
            final String guid = (String) request.getSession().getAttribute(SECURE_GUID_SESSION_KEY);
            final boolean anonymousUser = getUserService().isAnonymousUser(getUserService().getCurrentUser());
            if (!anonymousUser && guid != null && request.getCookies() != null) {
                final String guidCookieName = getCookieGenerator().getCookieName();
                if (guidCookieName != null) {
                    for (final Cookie cookie : request.getCookies()) {
                        if (guidCookieName.equals(cookie.getName())) {
                            if (guid.equals(cookie.getValue())) {
                                redirect = false;
                                break;
                            } else {
                                LOG.info("Found secure cookie with invalid value. expected [" + guid
                                        + "] actual [" + cookie.getValue() + "]. removing.");
                                getCookieGenerator().removeCookie(response);
                            }/*  w  w  w. j a v a2  s.c o m*/
                        }
                    }
                }
            }

            if (redirect) {
                LOG.warn((guid == null ? "missing secure token in session" : "no matching guid cookie")
                        + ", redirecting");
                getRedirectStrategy().sendRedirect(request, response, getRedirectUrl(request));
                return false;
            }
        }
    }

    return true;
}

From source file:gr.abiss.calipso.web.filters.RestRequestNormalizerFilter.java

protected String getCookieToken(HttpServletRequest httpRequest) {
    String authToken = null;/*from   w  ww  .j ava 2 s . co m*/
    Cookie[] cookies = httpRequest.getCookies();
    String ssoCookieName = userDetailsConfig.getCookiesBasicAuthTokenName();
    if (cookies != null) {
        for (int i = 0; i < cookies.length; i++) {
            Cookie cookie = cookies[i];
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("Found cookie '" + cookie.getName() + "', secure:  " + cookie.getSecure()
                        + ", comment: " + cookie.getComment() + ", domain: " + cookie.getDomain() + ", value: "
                        + cookie.getValue());
            }
            if (cookie.getName().equalsIgnoreCase(ssoCookieName)) {
                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug("Matched calipso SSO cookie'" + cookie.getName() + "', secure:  "
                            + cookie.getSecure() + ", comment: " + cookie.getComment() + ", domain: "
                            + cookie.getDomain() + ", value: " + cookie.getValue());
                }
                authToken = cookie.getValue();
                break;
            }
        }
        if (LOGGER.isDebugEnabled() && authToken == null) {
            LOGGER.debug("Found no calipso SSO cookie with name: " + ssoCookieName);

        }
    }
    return authToken;
}

From source file:com.xwiki.authentication.AbstractSSOAuthServiceImpl.java

protected XWikiUser checkAuthSSO(String username, String password, XWikiContext context) throws XWikiException {
    Cookie cookie;/* w ww  . java2 s.  c  o m*/

    LOG.debug("checkAuth");

    LOG.debug("Action: " + context.getAction());
    if (context.getAction().startsWith("logout")) {
        cookie = getCookie(COOKIE_NAME, context);
        if (cookie != null) {
            cookie.setMaxAge(0);
            context.getResponse().addCookie(cookie);
        }

        return null;
    }

    Principal principal = null;

    if (LOG.isDebugEnabled()) {
        Cookie[] cookies = context.getRequest().getCookies();
        if (cookies != null) {
            for (Cookie c : cookies) {
                LOG.debug("CookieList: " + c.getName() + " => " + c.getValue());
            }
        }
    }

    cookie = getCookie(COOKIE_NAME, context);
    if (cookie != null) {
        LOG.debug("Found Cookie");
        String uname = decryptText(cookie.getValue(), context);
        if (uname != null) {
            principal = new SimplePrincipal(uname);
        }
    }

    XWikiUser user;

    // Authenticate
    if (principal == null) {
        principal = authenticate(username, password, context);
        if (principal == null) {
            return null;
        }

        LOG.debug("Saving auth cookie");
        String encuname = encryptText(principal.getName().contains(":") ? principal.getName()
                : context.getDatabase() + ":" + principal.getName(), context);
        Cookie usernameCookie = new Cookie(COOKIE_NAME, encuname);
        usernameCookie.setMaxAge(-1);
        usernameCookie.setPath("/");
        context.getResponse().addCookie(usernameCookie);

        user = new XWikiUser(principal.getName());
    } else {
        user = new XWikiUser(principal.getName().startsWith(context.getDatabase())
                ? principal.getName().substring(context.getDatabase().length() + 1)
                : principal.getName());
    }

    return user;
}

From source file:edu.usu.sdl.openstorefront.web.action.BaseAction.java

protected String getCookieValue(String key) {
    String value = null;//  w ww  . j av a  2 s  . c  o  m

    Cookie cookies[] = getContext().getRequest().getCookies();
    if (cookies != null) {
        for (Cookie cookie : cookies) {
            if (cookie.getName().equals(key)) {
                value = cookie.getValue();
            }
        }
    }

    return value;
}

From source file:com.ebook.storefront.interceptors.beforecontroller.RequireHardLoginBeforeControllerHandler.java

protected boolean isGuidStoredinCookies(final HttpServletRequest request, final HttpServletResponse response,
        final String guid, final String guidCookieName) {
    for (final Cookie cookie : request.getCookies()) {
        if (guidCookieName.equals(cookie.getName())) {
            if (guid.equals(cookie.getValue())) {
                return true;
            } else {
                LOG.info("Found secure cookie with invalid value. expected [" + guid + "] actual ["
                        + cookie.getValue() + "]. removing.");
                getCookieGenerator().removeCookie(response);
            }//w w  w  . j av  a 2  s  . c  o  m
        }
    }
    return false;
}