Example usage for javax.servlet.http HttpServletRequest getCookies

List of usage examples for javax.servlet.http HttpServletRequest getCookies

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletRequest getCookies.

Prototype

public Cookie[] getCookies();

Source Link

Document

Returns an array containing all of the Cookie objects the client sent with this request.

Usage

From source file:fr.paris.lutece.plugins.mylutece.modules.wssodatabase.authentication.security.WSSOSessionTrackingFilter.java

/**
 * {@inheritDoc}//w  ww.  ja  v a  2  s . com
 */
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    HttpServletRequest req = (HttpServletRequest) request;
    LuteceUser user = SecurityService.getInstance().getRegisteredUser(req);

    if (user != null) {
        Cookie[] cookies = req.getCookies();
        String strUserID = null;

        if (cookies != null) {
            for (int i = 0; i < cookies.length; i++) {
                Cookie cookie = cookies[i];

                if (cookie.getName().equals(AppPropertiesService.getProperty(PROPERTY_COOKIE_WSSOGUID))) {
                    strUserID = cookie.getValue();
                    if (!StringUtils.isEmpty(strUserID) && !strUserID.equals(user.getName())) {

                        SecurityService.getInstance().unregisterUser(req);

                    }

                    break;

                }
            }
        }
    }

    chain.doFilter(request, response);
}

From source file:fr.univlille2.ecm.platform.ui.web.auth.cas2.AnonymousAuthenticatorForCAS2.java

@Override
public Boolean handleLogout(HttpServletRequest httpRequest, HttpServletResponse httpResponse) {

    boolean isRedirectionToCas = false;
    log.debug(httpRequest.getRequestURL().toString());
    Cookie[] cookies = httpRequest.getCookies();
    for (Cookie cookie : cookies) {
        log.debug(String.format("ANONYMOUS_AUTH : cookie->%s:%s", cookie.getName(), cookie.getValue()));
        if (NXAuthConstants.SSO_INITIAL_URL_REQUEST_KEY.equals(cookie.getName())) {
            isRedirectionToCas = true;//from w w  w  .  j  a v  a  2 s  . co  m
            log.debug("isRedirectionToCAS");
            break;
        }
    }

    if (isRedirectionToCas) {
        String authURL = getCas2Authenticator().getServiceURL(httpRequest, Cas2Authenticator.LOGIN_ACTION);
        String appURL = getCas2Authenticator().getAppURL(httpRequest);

        try {
            Map<String, String> urlParameters = new HashMap<String, String>();
            urlParameters.put("service", URLEncoder.encode(appURL, "UTF-8"));
            String location = URIUtils.addParametersToURIQuery(authURL, urlParameters);
            httpResponse.sendRedirect(location);
            return true;
        } catch (IOException e) {
            log.error("Unable to redirect to CAS logout screen:", e);
            return false;
        }
    }
    return super.handleLogout(httpRequest, httpResponse);
}

From source file:org.osmsurround.ae.IndexController.java

@RequestMapping("/index")
public ModelAndView index(@ModelAttribute StartModel startModel, HttpServletRequest request) {

    StartParameters startParameters = new StartParameters(startModel, version);

    if (startParameters.getGeoLocation() == null) {
        startParameters.setGeoLocation(DEFAULT_LOCATION);
    }//from   w w  w. j  a  v  a2  s. c  o  m

    Cookie[] cookies = request.getCookies();
    startParameters.setOauthTokenAvailable(oauthCookieService.initOauthServiceFromCookies(cookies));

    return new ModelAndView("index", "startParameters", startParameters);
}

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

protected boolean checkForGUIDCookie(final HttpServletRequest request, final HttpServletResponse response,
        final String guid) {
    if (guid != null && request.getCookies() != null) {
        final String guidCookieName = getCookieGenerator().getCookieName();
        if (guidCookieName != null) {
            return isGuidStoredinCookies(request, response, guid, guidCookieName);
        }//w w  w .  ja v  a 2s  . com
    }

    return false;

}

From source file:it.publisys.liferay.hook.shibboleth.ShibbolethPostLogoutAction.java

/**
 * Prepara i {@link Cookie}s da inoltrare
 *
 * @param request {@link HttpServletRequest}
 * @return cookies string//ww  w .ja  va2s  .c  o m
 */
private String _prepareCookies(HttpServletRequest request) {
    StringBuilder _cookieBuffer = new StringBuilder();
    try {
        Cookie[] _cookies = request.getCookies();
        for (Cookie _cookie : _cookies) {
            _cookieBuffer.append(_cookie.getName()).append("=")
                    .append(URLEncoder.encode(_cookie.getValue(), "UTF-8"));
            _cookieBuffer.append("; ");
        }
    } catch (UnsupportedEncodingException uee) {
        uee.printStackTrace(System.err);
    }

    if (_cookieBuffer.length() > 2) {
        _cookieBuffer.delete(_cookieBuffer.length() - 2, _cookieBuffer.length());
    }
    return _cookieBuffer.toString();
}

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

protected boolean checkForGUIDCookie(final HttpServletRequest request, final HttpServletResponse response,
        final String guid) {
    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())) {
                        return true;
                    } else {
                        LOG.info("Found secure cookie with invalid value. expected [" + guid + "] actual ["
                                + cookie.getValue() + "]. removing.");
                        getCookieGenerator().removeCookie(response);
                    }/*from w w  w  .j  a  v  a2  s . c o m*/
                }
            }
        }
    }

    return false;

}

From source file:com.gradecak.alfresco.mvc.aop.AuthenticationAdvice.java

private String getTicket() {

    String ticket = "";
    HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes())
            .getRequest();/*from  ww  w .j ava  2s.  co  m*/

    Cookie[] cookies = request.getCookies();
    if (cookies != null) {
        for (int i = 0; i < cookies.length; i++) {
            Cookie cookie = cookies[i];
            if (cookie != null && "TICKET".equals(cookie.getName().toUpperCase())) {
                ticket = cookie.getValue();
            }
        }
    }

    @SuppressWarnings("unchecked")
    Map<String, Object> parameterMap = request.getParameterMap();

    if (parameterMap != null) {
        for (Object parameter : parameterMap.keySet()) {
            if (parameter != null && "TICKET".equals(((String) parameter).toUpperCase())) {
                ticket = (String) parameterMap.get(parameter);
            }
        }
    }

    // HttpSession session = request.getSession();
    // if (session != null) {
    // // TODO dgradecak: FIX THIS
    // User user = (User)session.getAttribute("_alfAuthTicket");
    // ticket = user.getTicket();
    // }

    return ticket;
}

From source file:shiver.me.timbers.spring.security.jwt.AuthenticationRequestJwtTokenParserTest.java

@Test
public void Can_fail_to_find_a_jwt_token() throws JwtInvalidTokenException {

    final HttpServletRequest request = mock(HttpServletRequest.class);

    final JwtInvalidTokenException exception = new JwtInvalidTokenException(new Exception());

    // Given/*from w w w  . ja va  2 s . co  m*/
    given(request.getCookies()).willReturn(null);
    given(request.getHeader(tokenName)).willReturn(null);
    given(principleTokenParser.parse("")).willThrow(exception);
    expectedException.expect(is(exception));

    // When
    tokenParser.parse(request);
}

From source file:org.edeoliveira.oauth2.dropwizard.oauth2.auth.OAuth2Resource.java

@GET
@Timed//from www .  j a v  a 2 s . c  om
@Path(value = "/logout")
public Response logout(@Context final HttpServletRequest request) {
    // invalidate cookie if exists
    ResponseBuilder reply = Response.ok();

    for (Cookie c : request.getCookies()) {
        if (OAuth2AuthFilter.AUTH_COOKIE_NAME.equals(c.getName())) {
            reply.cookie(new NewCookie(OAuth2AuthFilter.AUTH_COOKIE_NAME, null, "/", request.getServerName(),
                    null, 0, true));
            break;
        }
    }

    return reply.build();
}

From source file:com.persistent.cloudninja.web.security.CNAuthenticationProcessingFilter.java

private String getCookie(HttpServletRequest request) {
    // Check whether the browser already has a SSO cookie
    String currentCookie = "";
    Cookie[] cookies = request.getCookies();
    if (cookies != null)
        for (int i = 0; i < cookies.length; i++)
            if (cookieName.equals(cookies[i].getName())) {
                currentCookie = cookies[i].getValue();
                break;
            }//  ww w.j av  a2s  . c o m
    return currentCookie;
}