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:nl.tue.gale.ae.GaleContext.java

public static String getCookie(Resource resource, String name) {
    Cookie[] cookies = req(resource).getCookies();
    if (cookies == null)
        return null;
    for (Cookie cookie : cookies)
        if (cookie.getName().equalsIgnoreCase(name))
            return decodeURL(cookie.getValue());
    return null;/*from w  w w  .j  a  va 2 s.c  o  m*/
}

From source file:cn.vlabs.umt.ui.servlet.login.LoginMethod.java

public static Cookie getCookieByName(HttpServletRequest request, String cookieName) {
    Cookie fcookie = null;/*from www.ja va 2 s  .co  m*/
    if (cookieName != null) {
        Cookie[] cookies = request.getCookies();
        if (cookies != null) {
            for (Cookie cookie : cookies) {
                if (cookieName.equals(cookie.getName())) {
                    fcookie = cookie;
                    break;
                }
            }
        }
    }
    return fcookie;
}

From source file:org.apache.hive.service.cli.thrift.ThriftHttpServlet.java

/**
 * Generate httponly cookie from HS2 cookie
 * @param cookie HS2 generated cookie//w w  w .j  a  v a2s .c o  m
 * @return The httponly cookie
 */
private static String getHttpOnlyCookieHeader(Cookie cookie) {
    NewCookie newCookie = new NewCookie(cookie.getName(), cookie.getValue(), cookie.getPath(),
            cookie.getDomain(), cookie.getVersion(), cookie.getComment(), cookie.getMaxAge(),
            cookie.getSecure());
    return newCookie + "; HttpOnly";
}

From source file:de.betterform.agent.web.WebUtil.java

private static Vector<BasicClientCookie> saveAsBasicClientCookie(Iterator iterator,
        Vector<BasicClientCookie> commonsCookies) {
    while (iterator.hasNext()) {
        javax.servlet.http.Cookie c = (Cookie) iterator.next();
        BasicClientCookie commonsCookie = new BasicClientCookie(c.getName(), c.getValue());
        commonsCookie.setDomain(c.getDomain());
        commonsCookie.setPath(c.getPath());
        commonsCookie.setAttribute(ClientCookie.MAX_AGE_ATTR, Integer.toString(c.getMaxAge()));
        commonsCookie.setSecure(c.getSecure());

        commonsCookies.add(commonsCookie);

        if (WebUtil.LOGGER.isDebugEnabled()) {
            WebUtil.LOGGER.debug("adding cookie >>>>>");
            WebUtil.LOGGER.debug("name: " + c.getName());
            WebUtil.LOGGER.debug("value: " + c.getValue());
            WebUtil.LOGGER.debug("path: " + c.getPath());
            WebUtil.LOGGER.debug("maxAge: " + c.getMaxAge());
            WebUtil.LOGGER.debug("secure: " + c.getSecure());
            WebUtil.LOGGER.debug("adding cookie done <<<<<");
        }/*from  ww  w .ja va  2  s  . c  o m*/
    }

    return commonsCookies;
}

From source file:org.itracker.web.util.LoginUtilities.java

public static User setupSession(String login, HttpServletRequest request, HttpServletResponse response) {
    if (null == login) {
        logger.warn("setupSession: null login", (logger.isDebugEnabled() ? new RuntimeException() : null));
        throw new IllegalArgumentException("null login");
    }//w  ww  .  j a  v a2  s . c o m
    UserService userService = ServletContextUtils.getItrackerServices().getUserService();
    User user = userService.getUserByLogin(login);
    if (user != null) {
        String encPassword = null;
        Cookie[] cookies = request.getCookies();
        if (cookies != null) {
            for (Cookie cookie : cookies) {
                if (Constants.COOKIE_NAME.equals(cookie.getName())) {
                    int seperator = cookie.getValue().indexOf('~');
                    if (seperator > 0) {
                        encPassword = cookie.getValue().substring(seperator + 1);
                    }
                }
            }
        }

        return setupSession(user, encPassword, request, response);
    }
    return null;
}

From source file:org.itracker.web.util.LoginUtilities.java

public static boolean checkAutoLogin(HttpServletRequest request, boolean allowSaveLogin) {
    boolean foundLogin = false;

    if (request != null) {
        int authType = getRequestAuthType(request);

        // Check for auto login in request
        if (authType == AuthenticationConstants.AUTH_TYPE_REQUEST) {
            String redirectURL = request.getRequestURI().substring(request.getContextPath().length())
                    + (request.getQueryString() != null ? "?" + request.getQueryString() : "");
            request.setAttribute(Constants.AUTH_TYPE_KEY, AuthenticationConstants.AUTH_TYPE_REQUEST);
            request.setAttribute(Constants.AUTH_REDIRECT_KEY, redirectURL);
            request.setAttribute("processLogin", "true");
            foundLogin = true;/*  w  w  w. j ava2 s.co  m*/

        }

        // Add in check for client certs

        // Check for auto login with cookies, this will only happen if users
        // are allowed to save
        // their logins to cookies
        if (allowSaveLogin && !foundLogin) {
            Cookie[] cookies = request.getCookies();
            if (cookies != null) {
                for (Cookie cookie : cookies) {
                    if (Constants.COOKIE_NAME.equals(cookie.getName())) {
                        int seperator = cookie.getValue().indexOf('~');
                        final String login;
                        if (seperator > 0) {
                            login = cookie.getValue().substring(0, seperator);
                            if (logger.isDebugEnabled()) {
                                logger.debug("Attempting autologin for user " + login + ".");
                            }

                            String redirectURL = request.getRequestURI()
                                    .substring(request.getContextPath().length())
                                    + (request.getQueryString() != null ? "?" + request.getQueryString() : "");
                            request.setAttribute(Constants.AUTH_LOGIN_KEY,
                                    cookie.getValue().substring(0, seperator));
                            request.setAttribute(Constants.AUTH_TYPE_KEY,
                                    AuthenticationConstants.AUTH_TYPE_PASSWORD_ENC);

                            request.setAttribute(Constants.AUTH_VALUE_KEY,
                                    cookie.getValue().substring(seperator + 1));
                            request.setAttribute(Constants.AUTH_REDIRECT_KEY, redirectURL);
                            request.setAttribute("processLogin", "true");
                            foundLogin = true;
                        }
                    }
                }
            }
        }

    }

    return foundLogin;
}

From source file:com.tc.utils.XSPUtils.java

public static String getCookie(String name) {
    String value = "";
    for (Cookie cookie : getCookies()) {
        if (cookie.getName().equals(name)) {
            value = cookie.getValue();//  ww w  .  j  a v a  2s  . com
            break;
        }
    }
    return value;
}

From source file:com.xpn.xwiki.user.impl.xwiki.MyPersistentLoginManager.java

/**
 * Given an array of cookies and a name, this method tries to find and return the cookie from the array that has the
 * given name. If there is no cookie matching the name in the array, null is returned.
 * /*from  www .  j a  va 2  s . c o m*/
 * @param cookies The list of cookies sent by the client.
 * @param cookieName The name of the cookie to be retrieved.
 * @return The requested cookie, or null if no cookie with the given name was found.
 */
private static Cookie getCookie(Cookie[] cookies, String cookieName) {
    if (cookies != null) {
        for (int i = 0; i < cookies.length; i++) {
            Cookie cookie = cookies[i];
            if (cookieName.equals(cookie.getName())) {
                return (cookie);
            }
        }
    }
    return null;
}

From source file:com.xpn.xwiki.user.impl.xwiki.MyPersistentLoginManager.java

/**
 * Given an array of Cookies, a name, and a default value, this method tries to find the value of the cookie with
 * the given name. If there is no cookie matching the name in the array, then the default value is returned instead.
 * // w  ww  . j a  va2s.  c om
 * @param cookies The list of cookies to search.
 * @param cookieName The name of the cookie whose value should be returned.
 * @param defaultValue The default value that should be returned when no cookie with the given name was found.
 * @return The value of the cookie with the given name, or defaultValue if no such cookie was found.
 */
private static String getCookieValue(Cookie[] cookies, String cookieName, String defaultValue) {
    String value = defaultValue;
    if (cookies != null) {
        for (int i = 0; i < cookies.length; i++) {
            Cookie cookie = cookies[i];
            if (cookieName.equals(cookie.getName())) {
                value = cookie.getValue();
            }
        }
    }
    return value;
}

From source file:com.vmware.identity.openidconnect.sample.RelyingPartyController.java

private static String getCookieValue(Cookie[] cookies, String cookieName, String defaultValue) {
    if (cookies != null) {
        for (int i = 0; i < cookies.length; i++) {
            Cookie cookie = cookies[i];
            if (cookieName.equals(cookie.getName())) {
                return (cookie.getValue());
            }//from   w w w  .ja  v  a 2 s .com
        }
    }
    return defaultValue;
}