List of usage examples for io.netty.handler.codec.http.cookie Cookie isHttpOnly
boolean isHttpOnly();
From source file:com.vmware.xenon.services.common.authn.TestBasicAuthenticationService.java
License:Open Source License
private void doTestAuthWithUserInfo(boolean remote) throws Throwable { this.host.resetAuthorizationContext(); String userPassStr = new StringBuilder(USER).append(BASIC_AUTH_USER_SEPARATOR).append(PASSWORD).toString(); URI authServiceUri = UriUtils.buildUri(this.host, BasicAuthenticationService.SELF_LINK, null, userPassStr); this.host.testStart(1); Operation post = Operation.createPost(authServiceUri).setBody(new Object()).setCompletion((o, e) -> { if (e != null) { this.host.failIteration(e); return; }// www .j a v a2 s . c om if (o.getStatusCode() != Operation.STATUS_CODE_OK) { this.host.failIteration(new IllegalStateException("Invalid status code returned")); return; } if (!o.isRemote() && o.getAuthorizationContext() == null) { this.host.failIteration(new IllegalStateException("Authorization context not set")); return; } // now issue a logout AuthenticationRequest request = new AuthenticationRequest(); request.requestType = AuthenticationRequestType.LOGOUT; Operation logoutOp = Operation.createPost(authServiceUri).setBody(request).forceRemote() .setCompletion((oo, ee) -> { if (ee != null) { this.host.failIteration(ee); return; } if (oo.getStatusCode() != Operation.STATUS_CODE_OK) { this.host.failIteration(new IllegalStateException("Invalid status code returned")); return; } String cookieHeader = oo.getResponseHeader(SET_COOKIE_HEADER); if (cookieHeader == null) { this.host.failIteration(new IllegalStateException("Cookie is null")); return; } Cookie cookie = ClientCookieDecoder.LAX.decode(cookieHeader); if (cookie.maxAge() != 0) { this.host.failIteration(new IllegalStateException("Max-Age for cookie is not zero")); return; } if (!cookie.isHttpOnly()) { this.host.failIteration(new IllegalStateException("Cookie is not HTTP-only")); return; } this.host.resetAuthorizationContext(); this.host.completeIteration(); }); this.host.setAuthorizationContext(o.getAuthorizationContext()); this.host.send(logoutOp); }); if (remote) { post.forceRemote(); } this.host.send(post); this.host.testWait(); }
From source file:org.atmosphere.nettosphere.BridgeRuntime.java
License:Apache License
private Set<javax.servlet.http.Cookie> getCookies(final HttpRequest request) { Set<javax.servlet.http.Cookie> result = new HashSet<javax.servlet.http.Cookie>(); String cookieHeader = request.headers().get("Cookie"); if (cookieHeader != null) { Set<io.netty.handler.codec.http.cookie.Cookie> cookies = ServerCookieDecoder.LAX.decode(cookieHeader); for (io.netty.handler.codec.http.cookie.Cookie cookie : cookies) { javax.servlet.http.Cookie c = new javax.servlet.http.Cookie(cookie.name(), cookie.value()); if (cookie.domain() != null) { c.setDomain(cookie.domain()); }/*from ww w .j a v a2 s.c o m*/ c.setHttpOnly(cookie.isHttpOnly()); c.setMaxAge((int) cookie.maxAge()); if (cookie.path() != null) { c.setPath(cookie.path()); } c.setSecure(cookie.isSecure()); result.add(c); } } return result; }