Example usage for javax.servlet.http Cookie getPath

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

Introduction

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

Prototype

public String getPath() 

Source Link

Document

Returns the path on the server to which the browser returns this cookie.

Usage

From source file:org.sonar.server.authentication.OAuthCsrfVerifierTest.java

@Test
public void verify_state() throws Exception {
    String state = "state";
    when(request.getCookies()).thenReturn(new Cookie[] { new Cookie("OAUTHSTATE", sha256Hex(state)) });
    when(request.getParameter("state")).thenReturn(state);

    underTest.verifyState(request, response, identityProvider);

    verify(response).addCookie(cookieArgumentCaptor.capture());
    Cookie updatedCookie = cookieArgumentCaptor.getValue();
    assertThat(updatedCookie.getName()).isEqualTo("OAUTHSTATE");
    assertThat(updatedCookie.getValue()).isNull();
    assertThat(updatedCookie.getPath()).isEqualTo("/");
    assertThat(updatedCookie.getMaxAge()).isEqualTo(0);
}

From source file:org.sonar.server.authentication.OAuthCsrfVerifierTest.java

private void verifyCookie(Cookie cookie) {
    assertThat(cookie.getName()).isEqualTo("OAUTHSTATE");
    assertThat(cookie.getValue()).isNotEmpty();
    assertThat(cookie.getPath()).isEqualTo("/");
    assertThat(cookie.isHttpOnly()).isTrue();
    assertThat(cookie.getMaxAge()).isEqualTo(-1);
    assertThat(cookie.getSecure()).isFalse();
}

From source file:org.wso2.carbon.identity.auth.service.factory.AuthenticationRequestBuilderFactory.java

/**
 * Tomcat Valve can use this method to create AuthenticationRequest by using connector objects.
 *
 * @param request//from  w w w.  j a v  a  2s  .c  o m
 * @param response
 * @return AuthenticationRequest.AuthenticationRequestBuilder
 * @throws AuthClientException
 */
public AuthenticationRequest.AuthenticationRequestBuilder createRequestBuilder(Request request,
        Response response) throws AuthClientException {

    AuthenticationRequest.AuthenticationRequestBuilder authenticationRequestBuilder = new AuthenticationRequest.AuthenticationRequestBuilder();

    Enumeration<String> attributeNames = request.getAttributeNames();
    while (attributeNames.hasMoreElements()) {
        String attributeName = attributeNames.nextElement();
        authenticationRequestBuilder.addAttribute(attributeName, request.getAttribute(attributeName));
    }

    Enumeration<String> headerNames = request.getHeaderNames();
    while (headerNames.hasMoreElements()) {
        String headerName = headerNames.nextElement();
        authenticationRequestBuilder.addHeader(headerName, request.getHeader(headerName));
    }
    Cookie[] cookies = request.getCookies();
    if (cookies != null) {
        for (Cookie cookie : cookies) {
            authenticationRequestBuilder
                    .addCookie(new AuthenticationRequest.CookieKey(cookie.getName(), cookie.getPath()), cookie);
        }
    }
    authenticationRequestBuilder.setContextPath(request.getContextPath());
    authenticationRequestBuilder.setMethod(request.getMethod());

    return authenticationRequestBuilder;
}

From source file:org.wso2.carbon.identity.provider.openid.util.OpenIDUtil.java

public static void deleteCookie(String name, String path, HttpServletRequest request) {
    Cookie[] reqCookies = request.getCookies();
    if (reqCookies != null) {
        for (Cookie cookie : reqCookies) {
            if (cookie.getName().equals(name) && cookie.getPath() != null && cookie.getPath().equals(path)) {
                cookie.setMaxAge(0);/*  ww  w  . ja v  a  2s  . c om*/
                break;
            }
        }
    }
}

From source file:uk.ac.ed.epcc.webapp.servlet.DefaultServletService.java

/**invalidate the servlet session and optionally remove the session cookie.
 *
 * //ww w .j a va 2 s  .com
 * 
 * @param remove_cookie should cookie be removed
 * 
 */
public void logout(boolean remove_cookie) {
    HttpSession sess = getSession();
    if (sess != null) {
        sess.invalidate();
    }
    if (remove_cookie) {
        HttpServletRequest request = getRequest();
        if (request != null) {
            Cookie[] cookies = request.getCookies();
            if (cookies != null && cookies.length > 0) {
                for (Cookie c : cookies) {
                    if (c.getName().equalsIgnoreCase("JSESSIONID") || getContext()
                            .getBooleanParameter(LOGOUT_REMOVE_COOKIE_PREFIX + c.getName(), false)) {
                        Cookie c2 = (Cookie) c.clone();
                        c2.setMaxAge(0); // This should request a delete
                        if (c2.getPath() == null) {
                            String contextPath = request.getContextPath();
                            c2.setPath(contextPath + "/"); // browser did not include path. This will only work if path matched exactly
                        }
                        c2.setValue("");
                        ((HttpServletResponse) res).addCookie(c2);
                    }
                }
            }
        }
    }
}