Example usage for io.netty.handler.codec.http.cookie Cookie setHttpOnly

List of usage examples for io.netty.handler.codec.http.cookie Cookie setHttpOnly

Introduction

In this page you can find the example usage for io.netty.handler.codec.http.cookie Cookie setHttpOnly.

Prototype

void setHttpOnly(boolean httpOnly);

Source Link

Document

Determines if this Cookie is HTTP only.

Usage

From source file:com.bay1ts.bay.core.Response.java

License:Apache License

/**
 * Adds cookie to the response. Can be invoked multiple times to insert more than one cookie.
 *
 * @param path     path of the cookie/*from   w  ww .  ja v a  2  s  .  co  m*/
 * @param name     name of the cookie
 * @param value    value of the cookie
 * @param maxAge   max age of the cookie in seconds (negative for the not persistent cookie, zero - deletes the cookie)
 * @param secured  if true : cookie will be secured
 * @param httpOnly if true: cookie will be marked as http only
 */
public void cookie(String path, String name, String value, int maxAge, boolean secured, boolean httpOnly) {
    Cookie cookie = new DefaultCookie(name, value);
    cookie.setPath(path);
    cookie.setMaxAge(maxAge);
    cookie.setSecure(secured);
    cookie.setHttpOnly(httpOnly);
    response.headers().set(HttpHeaderNames.COOKIE, ServerCookieEncoder.STRICT.encode(cookie));
}

From source file:nikoladasm.aspark.ResponseImpl.java

License:Open Source License

@Override
public void cookie(String path, String name, String value, int maxAge, boolean secured, boolean httpOnly) {
    Cookie cookie = new DefaultCookie(name, value);
    cookie.setPath(path);/*from   ww w.  j  av  a2s .c o m*/
    cookie.setMaxAge(maxAge);
    cookie.setSecure(secured);
    cookie.setHttpOnly(httpOnly);
    cookies.put(name, cookie);
}

From source file:org.glowroot.ui.HttpSessionManager.java

License:Apache License

void deleteSessionCookie(CommonResponse response) throws Exception {
    Cookie cookie = new DefaultCookie(configRepository.getWebConfig().sessionCookieName(), "");
    cookie.setHttpOnly(true);
    cookie.setMaxAge(0);//from www.  jav  a2s  . c o m
    cookie.setPath("/");
    response.setHeader(HttpHeaderNames.SET_COOKIE, ServerCookieEncoder.STRICT.encode(cookie));
}

From source file:org.glowroot.ui.HttpSessionManager.java

License:Apache License

private CommonResponse createSession(String username, Set<String> roles, boolean ldap) throws Exception {
    String sessionId = new BigInteger(130, secureRandom).toString(32);
    ImmutableSession session = ImmutableSession.builder().caseAmbiguousUsername(username).ldap(ldap)
            .roles(roles).lastRequest(clock.currentTimeMillis()).build();
    sessionMap.put(sessionId, session);//from w w  w  .j  a  va2  s .  c o m

    String layoutJson = layoutService.getLayoutJson(session.createAuthentication(central, configRepository));
    CommonResponse response = new CommonResponse(OK, MediaType.JSON_UTF_8, layoutJson);
    Cookie cookie = new DefaultCookie(configRepository.getWebConfig().sessionCookieName(), sessionId);
    cookie.setHttpOnly(true);
    cookie.setPath("/");
    response.setHeader(HttpHeaderNames.SET_COOKIE, ServerCookieEncoder.STRICT.encode(cookie));
    purgeExpiredSessions();

    auditSuccessfulLogin(username);
    return response;
}

From source file:org.springframework.http.server.reactive.ReactorServerHttpResponse.java

License:Apache License

@Override
protected void applyCookies() {
    for (String name : getCookies().keySet()) {
        for (ResponseCookie httpCookie : getCookies().get(name)) {
            Cookie cookie = new DefaultCookie(name, httpCookie.getValue());
            if (!httpCookie.getMaxAge().isNegative()) {
                cookie.setMaxAge(httpCookie.getMaxAge().getSeconds());
            }//from  www.  j a va2  s. c  o  m
            if (httpCookie.getDomain() != null) {
                cookie.setDomain(httpCookie.getDomain());
            }
            if (httpCookie.getPath() != null) {
                cookie.setPath(httpCookie.getPath());
            }
            cookie.setSecure(httpCookie.isSecure());
            cookie.setHttpOnly(httpCookie.isHttpOnly());
            this.response.addCookie(cookie);
        }
    }
}

From source file:org.springframework.http.server.reactive.RxNettyServerHttpResponse.java

License:Apache License

@Override
protected void applyCookies() {
    for (String name : getCookies().keySet()) {
        for (ResponseCookie httpCookie : getCookies().get(name)) {
            Cookie cookie = new DefaultCookie(name, httpCookie.getValue());
            if (!httpCookie.getMaxAge().isNegative()) {
                cookie.setMaxAge(httpCookie.getMaxAge().getSeconds());
            }//from   w w w .jav  a2s.co  m
            httpCookie.getDomain().ifPresent(cookie::setDomain);
            httpCookie.getPath().ifPresent(cookie::setPath);
            cookie.setSecure(httpCookie.isSecure());
            cookie.setHttpOnly(httpCookie.isHttpOnly());
            this.response.addCookie(cookie);
        }
    }
}

From source file:ratpack.session.clientside.internal.ClientSideSessionStore.java

License:Apache License

private void invalidateCookie(String name) {
    Cookie cookie = response.get().expireCookie(name);
    if (cookieConfig.getPath() != null) {
        cookie.setPath(cookieConfig.getPath());
    }//from   ww  w .  j av a2  s  .  com
    if (cookieConfig.getDomain() != null) {
        cookie.setDomain(cookieConfig.getDomain());
    }
    cookie.setHttpOnly(cookieConfig.isHttpOnly());
    cookie.setSecure(cookieConfig.isSecure());
}

From source file:ratpack.session.clientside.internal.ClientSideSessionStore.java

License:Apache License

private void addCookie(String name, String value) {
    Cookie cookie = response.get().cookie(name, value);
    if (cookieConfig.getPath() != null) {
        cookie.setPath(cookieConfig.getPath());
    }/*from  w  w  w  .  j  a  v a2  s . co  m*/
    if (cookieConfig.getDomain() != null) {
        cookie.setDomain(cookieConfig.getDomain());
    }

    long expirySeconds = cookieConfig.getExpires() == null ? 0 : cookieConfig.getExpires().getSeconds();
    if (expirySeconds > 0) {
        cookie.setMaxAge(expirySeconds);
    }
    cookie.setHttpOnly(cookieConfig.isHttpOnly());
    cookie.setSecure(cookieConfig.isSecure());
}