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:controllers.Parent_Controller.java

public String[] checkSetCookie2(HttpServletRequest request) {
    Cookie[] cookies2;//from  w w w .  j  a v  a2 s.c om
    cookies2 = request.getCookies();
    String creds[] = new String[2];
    int countcookies = 0;
    try {
        for (Cookie cookie1 : cookies2) {
            switch (cookie1.getName()) {
            case "handle":
                System.out.println("Got Handle cookie");
                creds[0] = cookie1.getValue();
                countcookies++;
                break;
            case "uid":
                System.out.println("Got uid cookie");
                creds[1] = cookie1.getValue();
                countcookies++;
                break;
            }
        }
        if (countcookies == 0) {
            creds = null;
            return creds;
        } else {

            return creds;

        }
    } catch (Exception e) {
        System.out.println("Parent_Controller>checksetcookie2() error-->" + e);
        creds = null;
        return creds;
    }
}

From source file:com.epam.cme.storefront.interceptors.beforecontroller.SecureRequestCookieCheckBeforeControllerHandler.java

@Override
public boolean beforeController(final HttpServletRequest request, final HttpServletResponse response)
        throws Exception // NOPMD
{
    final String path = getUrlPathHelper().getServletPath(request);
    if (request.isSecure() && !getExcludeUrls().contains(path)) {
        boolean redirect = true;
        final String guid = (String) request.getSession().getAttribute(SECURE_GUID_SESSION_KEY);
        if (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);
                        }//from   w  w  w  .  ja va  2  s. c o m
                    }
                }
            }
        }
        if (redirect) {
            LOG.warn((guid == null ? "missing secure token in session" : "no matching guid cookie")
                    + ", redirecting");
            getRedirectStrategy().sendRedirect(request, response, getLoginUrl());
            return false;
        }
    }

    return true;
}

From source file:com.epam.training.storefront.interceptors.beforecontroller.SecureRequestCookieCheckBeforeControllerHandler.java

@Override
public boolean beforeController(final HttpServletRequest request, final HttpServletResponse response)
        throws Exception //NOPMD
{
    final String path = getUrlPathHelper().getServletPath(request);
    if (request.isSecure() && !getExcludeUrls().contains(path)) {
        boolean redirect = true;
        final String guid = (String) request.getSession().getAttribute(SECURE_GUID_SESSION_KEY);
        if (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  ww . j av a2s .c om*/
                    }
                }
            }
        }
        if (redirect) {
            LOG.warn((guid == null ? "missing secure token in session" : "no matching guid cookie")
                    + ", redirecting");
            getRedirectStrategy().sendRedirect(request, response, getLoginUrl());
            return false;
        }
    }

    return true;
}

From source file:com.mobileman.projecth.web.util.PersistentCookieHelper.java

public User getUser(UserService userService, HttpServletRequest request, HttpServletResponse response) {
    Cookie[] cookies = request.getCookies();
    boolean removeCookie = false;
    if (cookies != null) {
        for (Cookie c : cookies) {
            if (COOKIE_NAME.equals(c.getName())) {
                removeCookie = true;//from w ww  .j  a v  a  2  s.  c o m
                String hash = c.getValue();

                //extract id, salt, hash
                if (StringUtils.isNotBlank(hash)) {
                    //if not found remove cookie!!!
                    String[] split = hash.split(SEPARATOR);
                    if (split.length == 3) {
                        try {
                            Long id = Long.parseLong(split[0]);
                            //find user
                            User user = userService.findById(id);
                            if (user != null) {
                                //check hash
                                String h2 = createHash(split[1], user);
                                if (hash.equals(h2)) {
                                    return user;
                                }
                            }
                        } catch (Exception ex) {
                        }
                    }
                }
            }
        }
    }
    if (removeCookie && response != null) {
        removeUser(request, response);
    }
    return null;
}

From source file:org.jasig.portlet.test.mvc.tests.CookieTestController.java

/**
 * Alter an existing cookie that has the same name as the command object.
 * Ignores invocations where the command does not match an existing cookie (by name).
 * /*from   ww  w .j av a  2  s.  co m*/
 * @param command
 * @param errors
 * @param request
 * @param response
 */
@ActionMapping(value = "editCookieAction")
protected void editExistingCookie(CreateCookieFormBackingObject command, ActionRequest request,
        ActionResponse response) {
    if (command == null) {
        return;
    }

    Cookie[] existingCookies = request.getCookies();
    if (existingCookies != null) {
        Cookie cookieToAlter = null;
        for (Cookie existing : existingCookies) {
            if (existing.getName().equals(command.getName())) {
                cookieToAlter = existing;
                break;
            }
        }

        if (cookieToAlter != null) {
            response.addProperty(command.toCookie());
        }
    }
}

From source file:com.vmware.identity.samlservice.impl.AuthnRequestStateTLSClientAuthenticationFilter.java

@Override
public void preAuthenticate(AuthnRequestState t) throws SamlServiceException {
    log.debug("AuthnRequestStateTLSClientAuthenticationFilter.preAuthenticate is called");

    Validate.notNull(t);/*www  .j av a2  s.c om*/
    HttpServletRequest request = t.getRequest();
    Validate.notNull(request);
    IdmAccessor accessor = t.getIdmAccessor();
    Validate.notNull(accessor);

    // then check if required auth header is present
    if (request.getParameter(Shared.REQUEST_AUTH_PARAM) == null) {
        // authentication not possible
        log.debug(Shared.REQUEST_AUTH_PARAM + " is missing, requesting " + Shared.TLSCLIENT_AUTH_PREFIX);
        t.setWwwAuthenticate(Shared.TLSCLIENT_AUTH_PREFIX);
        ValidationResult vr = new ValidationResult(HttpServletResponse.SC_UNAUTHORIZED, WebSSOError.BAD_REQUEST,
                null);
        t.setValidationResult(vr);
        throw new SamlServiceException();
    }

    // check if logout cookie is present
    Cookie[] cookies = request.getCookies();
    String logoutCookieName = Shared.getLogoutCookieName(accessor.getTenant());
    if (cookies != null && cookies.length > 0) {
        for (Cookie cookie : cookies) {
            if (cookie.getName().equalsIgnoreCase(logoutCookieName)) {
                ValidationResult vr = new ValidationResult(HttpServletResponse.SC_BAD_REQUEST,
                        WebSSOError.UNAUTHORIZED, WebSSOError.LOGGED_OUT_TLS_SESSION);
                t.setValidationResult(vr);
                throw new SamlServiceException();
            }
        }
    }
}

From source file:hudson.plugins.timestamper.TimestampFormatter.java

/**
 * Create a new {@link TimestampFormatter}.
 * //from  w  w  w  . ja v  a 2 s .  c o m
 * @param systemTimeFormat
 *          the system clock time format
 * @param elapsedTimeFormat
 *          the elapsed time format
 * @param request
 *          the current HTTP request
 */
public TimestampFormatter(String systemTimeFormat, String elapsedTimeFormat, HttpServletRequest request) {
    String cookieValue = null;
    Cookie[] cookies = request.getCookies();
    if (cookies != null) {
        for (Cookie cookie : cookies) {
            if ("jenkins-timestamper".equals(cookie.getName())) {
                cookieValue = cookie.getValue();
                break;
            }
        }
    }

    if ("elapsed".equalsIgnoreCase(cookieValue)) {
        formatTimestamp = new ElapsedTimeFormatFunction(elapsedTimeFormat);
    } else if ("none".equalsIgnoreCase(cookieValue)) {
        formatTimestamp = new EmptyFormatFunction();
    } else {
        // "system", no cookie, or unrecognised cookie
        formatTimestamp = new SystemTimeFormatFunction(systemTimeFormat);
    }
}

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

public static String getCookieValue(HttpServletRequest request, String name) {
    String value = null;//from   w  w  w . j a  v a  2 s .co  m
    Cookie[] cookies = request.getCookies();
    if (cookies != null && cookies.length > 0) {
        for (Cookie cookie : cookies) {
            if (StringUtils.equals(cookie.getName(), name)) {
                value = cookie.getValue();
            }
        }
    }
    return value;
}

From source file:com.vmware.identity.openidconnect.protocol.HttpRequest.java

public String getCookieValue(String cookieName) {
    Validate.notEmpty(cookieName, "cookieName");

    if (this.httpServletRequest != null && this.httpServletRequest.getCookies() != null) {
        for (Cookie cookie : this.httpServletRequest.getCookies()) {
            if (cookie.getName().equals(cookieName)) {
                return cookie.getValue();
            }//from  w  w w  .  ja  va  2s . c o  m
        }
    }
    return null;
}

From source file:com.sse.abtester.VariantSelectionFilter.java

/**
 * Gets the cookie value.//from   w ww.j  a  v  a 2  s  .com
 *
 * @param request the request
 * @return cookie value attached to VSKEY, or empty String.
 */
private String getCookieValue(HttpServletRequest request) {
    Cookie[] cookies = request.getCookies();
    String cookieValue = "";
    if (cookies == null)
        return cookieValue;

    for (Cookie c : cookies) {
        if (c.getName() == VSKEY) {
            cookieValue = c.getValue();
            break;
        }
    }
    return cookieValue;
}