/** * Batch encodes cookies into Set-Cookie header values. * * @param cookies a bunch of cookies * @return the corresponding bunch of Set-Cookie headers */ @Deprecated public static List<String> encode(Iterable<Cookie> cookies) { return io.netty.handler.codec.http.cookie.ServerCookieEncoder.LAX.encode(cookies); }
/** * Encodes the specified cookie name-value pair into a Set-Cookie header value. * * @param name the cookie name * @param value the cookie value * @return a single Set-Cookie header value */ @Deprecated public static String encode(String name, String value) { return io.netty.handler.codec.http.cookie.ServerCookieEncoder.LAX.encode(name, value); }
/** * Encodes the specified cookie into a Set-Cookie header value. * * @param cookie the cookie * @return a single Set-Cookie header value */ @Deprecated public static String encode(Cookie cookie) { return io.netty.handler.codec.http.cookie.ServerCookieEncoder.LAX.encode(cookie); }
/** * Batch encodes cookies into Set-Cookie header values. * * @param cookies a bunch of cookies * @return the corresponding bunch of Set-Cookie headers */ @Deprecated public static List<String> encode(Cookie... cookies) { return io.netty.handler.codec.http.cookie.ServerCookieEncoder.LAX.encode(cookies); }
/** * Batch encodes cookies into Set-Cookie header values. * * @param cookies a bunch of cookies * @return the corresponding bunch of Set-Cookie headers */ @Deprecated public static List<String> encode(Collection<Cookie> cookies) { return io.netty.handler.codec.http.cookie.ServerCookieEncoder.LAX.encode(cookies); }
/** * Encodes the specified cookie name-value pair into a Set-Cookie header value. * * @param name the cookie name * @param value the cookie value * @return a single Set-Cookie header value */ public String encode(String name, String value) { return encode(new DefaultCookie(name, value)); }
private void appendCookie(Response response, DefaultFullHttpResponse httpResponse) { for (io.netty.handler.codec.http.cookie.Cookie next : response.cookiesRaw()) { httpResponse.headers().add(HttpConst.SET_COOKIE, io.netty.handler.codec.http.cookie.ServerCookieEncoder.LAX.encode(next)); } }
private void appendCookie(Response response, DefaultFullHttpResponse httpResponse) { for (io.netty.handler.codec.http.cookie.Cookie next : response.cookiesRaw()) { httpResponse.headers().add(HttpConst.SET_COOKIE, io.netty.handler.codec.http.cookie.ServerCookieEncoder.LAX.encode(next)); } }
@Override public MutableHttpResponse<B> cookie(Cookie cookie) { if (cookie instanceof NettyCookie) { NettyCookie nettyCookie = (NettyCookie) cookie; String value = ServerCookieEncoder.LAX.encode(nettyCookie.getNettyCookie()); headers.add(HttpHeaderNames.SET_COOKIE, value); } else { throw new IllegalArgumentException("Argument is not a Netty compatible Cookie"); } return this; }
public String encodeCookie(final String key, final String value, final CookieAttribute... options) { Cookie cookie = new DefaultCookie(key, value); for (CookieAttribute option : options) { ((ActualCookieAttribute) option).visit(cookie); } return ServerCookieEncoder.STRICT.encode(cookie); } }
/** * Batch encodes cookies into Set-Cookie header values. * * @param cookies a bunch of cookies * @return the corresponding bunch of Set-Cookie headers */ public List<String> encode(Collection<? extends Cookie> cookies) { if (checkNotNull(cookies, "cookies").isEmpty()) { return Collections.emptyList(); } List<String> encoded = new ArrayList<String>(cookies.size()); Map<String, Integer> nameToIndex = strict && cookies.size() > 1 ? new HashMap<String, Integer>() : null; int i = 0; boolean hasDupdName = false; for (Cookie c : cookies) { encoded.add(encode(c)); if (nameToIndex != null) { hasDupdName |= nameToIndex.put(c.name(), i++) != null; } } return hasDupdName ? dedup(encoded, nameToIndex) : encoded; }
/** * Batch encodes cookies into Set-Cookie header values. * * @param cookies a bunch of cookies * @return the corresponding bunch of Set-Cookie headers */ public List<String> encode(Iterable<? extends Cookie> cookies) { Iterator<? extends Cookie> cookiesIt = checkNotNull(cookies, "cookies").iterator(); if (!cookiesIt.hasNext()) { return Collections.emptyList(); } List<String> encoded = new ArrayList<String>(); Cookie firstCookie = cookiesIt.next(); Map<String, Integer> nameToIndex = strict && cookiesIt.hasNext() ? new HashMap<String, Integer>() : null; int i = 0; encoded.add(encode(firstCookie)); boolean hasDupdName = nameToIndex != null && nameToIndex.put(firstCookie.name(), i++) != null; while (cookiesIt.hasNext()) { Cookie c = cookiesIt.next(); encoded.add(encode(c)); if (nameToIndex != null) { hasDupdName |= nameToIndex.put(c.name(), i++) != null; } } return hasDupdName ? dedup(encoded, nameToIndex) : encoded; } }
/** * Batch encodes cookies into Set-Cookie header values. * * @param cookies a bunch of cookies * @return the corresponding bunch of Set-Cookie headers */ public List<String> encode(Cookie... cookies) { if (checkNotNull(cookies, "cookies").length == 0) { return Collections.emptyList(); } List<String> encoded = new ArrayList<String>(cookies.length); Map<String, Integer> nameToIndex = strict && cookies.length > 1 ? new HashMap<String, Integer>() : null; boolean hasDupdName = false; for (int i = 0; i < cookies.length; i++) { Cookie c = cookies[i]; encoded.add(encode(c)); if (nameToIndex != null) { hasDupdName |= nameToIndex.put(c.name(), i) != null; } } return hasDupdName ? dedup(encoded, nameToIndex) : encoded; }
@POST @Path("/logout") public Response logout() { Response response = redirect(rootPath); Cookie cookie = makeDefaultSessionCookie("", 0); response.headers().add(SET_COOKIE, ServerCookieEncoder.STRICT.encode(cookie)); return response; }
private void setCookies(HttpResponse response, DefaultFullHttpResponse fullHttpResponse) { if (response.getCookieList() != null) { List<Cookie> cookieValues = new ArrayList<Cookie>(); for (org.mockserver.model.Cookie cookie : response.getCookieList()) { if (!cookieHeaderAlreadyExists(response, cookie)) { cookieValues.add(new DefaultCookie(cookie.getName().getValue(), cookie.getValue().getValue())); } } for (Cookie cookieValue : cookieValues) { fullHttpResponse.headers().add(SET_COOKIE, ServerCookieEncoder.LAX.encode(cookieValue)); } } }
CookieBasedSsoHandler(String cookieName, String cookieValue) { requireNonNull(cookieName, "cookieName"); requireNonNull(cookieValue, "cookieValue"); final Cookie cookie = new DefaultCookie(cookieName, cookieValue); cookie.setDomain(spHostname); cookie.setPath("/"); cookie.setHttpOnly(true); setCookie = ServerCookieEncoder.STRICT.encode(cookie); }
private void setCookies(HttpResponse httpResponse, HttpServletResponse httpServletResponse) { if (httpResponse.getCookieList() != null) { for (Cookie cookie : httpResponse.getCookieList()) { if (!cookieHeaderAlreadyExists(httpResponse, cookie)) { httpServletResponse.addHeader(SET_COOKIE.toString(), ServerCookieEncoder.LAX.encode(new DefaultCookie(cookie.getName().getValue(), cookie.getValue().getValue()))); } } } }
/** * Invoked when the SAML authentication process is finished and a user is authenticated. You can get * information about the authenticated user from the {@link Response}, especially his or her login name. * In this example, an email address is used as a login name. The login name is transferred to a web * browser via {@code Set-Cookie} header. */ @Override public HttpResponse loginSucceeded(ServiceRequestContext ctx, AggregatedHttpMessage req, MessageContext<Response> message, @Nullable String sessionIndex, @Nullable String relayState) { final String username = getNameId(message.getMessage(), SamlNameIdFormat.EMAIL).map(NameIDType::getValue) .orElse(null); if (username == null) { return HttpResponse.of(HttpStatus.UNAUTHORIZED, MediaType.HTML_UTF_8, "<html><body>Username is not found.</body></html>"); } logger.info("{} user '{}' has been logged in.", ctx, username); final Cookie cookie = new DefaultCookie("username", username); cookie.setHttpOnly(true); cookie.setDomain("localhost"); cookie.setMaxAge(60); cookie.setPath("/"); return HttpResponse.of( HttpHeaders.of(HttpStatus.OK) .contentType(MediaType.HTML_UTF_8) .add(HttpHeaderNames.SET_COOKIE, ServerCookieEncoder.LAX.encode(cookie)), HttpData.ofUtf8("<html><body onLoad=\"window.location.href='/welcome'\"></body></html>")); }
@POST @Consumes(value = MediaType.APPLICATION_FORM_URLENCODED) @Path("/login") public Response login(@FormParam("email") String email, @FormParam("password") String password) { if (email == null || password == null) { return redirect(rootPath); } User user = userDao.getByName(email, AppNameUtil.BLYNK); if (user == null || !user.isSuperAdmin) { return redirect(rootPath); } if (!password.equals(user.pass)) { return redirect(rootPath); } Response response = redirect(rootPath); log.debug("Admin login is successful. Redirecting to {}", rootPath); Cookie cookie = makeDefaultSessionCookie(sessionDao.generateNewSession(user), COOKIE_EXPIRE_TIME); response.headers().add(SET_COOKIE, ServerCookieEncoder.STRICT.encode(cookie)); return response; }
@Override public String encode() { return ServerCookieEncoder.STRICT.encode(nettyCookie); }