Java Code Examples for io.undertow.server.handlers.CookieImpl#setMaxAge()
The following examples show how to use
io.undertow.server.handlers.CookieImpl#setMaxAge() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Cookies.java From quarkus-http with Apache License 2.0 | 6 votes |
private static void handleValue(CookieImpl cookie, String key, String value) { if (key.equalsIgnoreCase("path")) { cookie.setPath(value); } else if (key.equalsIgnoreCase("domain")) { cookie.setDomain(value); } else if (key.equalsIgnoreCase("max-age")) { cookie.setMaxAge(Integer.parseInt(value)); } else if (key.equalsIgnoreCase("expires")) { cookie.setExpires(DateUtils.parseDate(value)); } else if (key.equalsIgnoreCase("discard")) { cookie.setDiscard(true); } else if (key.equalsIgnoreCase("secure")) { cookie.setSecure(true); } else if (key.equalsIgnoreCase("httpOnly")) { cookie.setHttpOnly(true); } else if (key.equalsIgnoreCase("version")) { cookie.setVersion(Integer.parseInt(value)); } else if (key.equalsIgnoreCase("comment")) { cookie.setComment(value); } else if (key.equalsIgnoreCase("samesite")) { cookie.setSameSite(true); cookie.setSameSiteMode(value); } //otherwise ignore this key-value pair }
Example 2
Source File: Cookies.java From lams with GNU General Public License v2.0 | 6 votes |
private static void handleValue(CookieImpl cookie, String key, String value) { if (key.equalsIgnoreCase("path")) { cookie.setPath(value); } else if (key.equalsIgnoreCase("domain")) { cookie.setDomain(value); } else if (key.equalsIgnoreCase("max-age")) { cookie.setMaxAge(Integer.parseInt(value)); } else if (key.equalsIgnoreCase("expires")) { cookie.setExpires(DateUtils.parseDate(value)); } else if (key.equalsIgnoreCase("discard")) { cookie.setDiscard(true); } else if (key.equalsIgnoreCase("secure")) { cookie.setSecure(true); } else if (key.equalsIgnoreCase("httpOnly")) { cookie.setHttpOnly(true); } else if (key.equalsIgnoreCase("version")) { cookie.setVersion(Integer.parseInt(value)); } else if (key.equalsIgnoreCase("comment")) { cookie.setComment(value); } else if (key.equalsIgnoreCase("samesite")) { cookie.setSameSite(true); cookie.setSameSiteMode(value); } //otherwise ignore this key-value pair }
Example 3
Source File: TwitterStartAuthFlowPath.java From PYX-Reloaded with Apache License 2.0 | 6 votes |
@Override public void handleRequest(HttpServerExchange exchange) throws Exception { exchange.startBlocking(); if (exchange.isInIoThread()) { exchange.dispatch(this); return; } try { OAuth1RequestToken token = helper.requestToken(); CookieImpl cookie = new CookieImpl("PYX-Twitter-Token", token.getRawResponse()); cookie.setMaxAge(COOKIE_MAX_AGE); exchange.setResponseCookie(cookie); exchange.getResponseHeaders().add(Headers.LOCATION, helper.authorizationUrl(token) + "&force_login=false"); exchange.setStatusCode(StatusCodes.TEMPORARY_REDIRECT); } catch (Throwable ex) { logger.error("Failed processing the request." + exchange, ex); throw ex; } }
Example 4
Source File: GithubCallbackPath.java From PYX-Reloaded with Apache License 2.0 | 5 votes |
@Override public void handleRequest(HttpServerExchange exchange) throws Exception { exchange.startBlocking(); if (exchange.isInIoThread()) { exchange.dispatch(this); return; } String code = Utils.extractParam(exchange, "code"); if (code == null) { exchange.setStatusCode(StatusCodes.BAD_REQUEST); return; } try { String accessToken = githubHelper.exchangeCode(code); CookieImpl cookie = new CookieImpl("PYX-Github-Token", accessToken); cookie.setMaxAge(COOKIE_MAX_AGE); exchange.setResponseCookie(cookie); exchange.getResponseHeaders().add(Headers.LOCATION, REDIRECT_LOCATION); exchange.setStatusCode(StatusCodes.TEMPORARY_REDIRECT); } catch (Throwable ex) { logger.error("Failed processing the request: " + exchange, ex); throw ex; } }
Example 5
Source File: TwitterCallbackPath.java From PYX-Reloaded with Apache License 2.0 | 5 votes |
@Override public void handleRequest(HttpServerExchange exchange) throws Exception { exchange.startBlocking(); if (exchange.isInIoThread()) { exchange.dispatch(this); return; } try { String token = Utils.extractParam(exchange, "oauth_token"); String verifier = Utils.extractParam(exchange, "oauth_verifier"); if (token == null || verifier == null) throw new IllegalArgumentException("Missing token or verifier!"); Cookie tokensCookie = exchange.getRequestCookies().get("PYX-Twitter-Token"); if (tokensCookie == null) throw new IllegalArgumentException("Missing 'PYX-Twitter-Token' cookie!"); List<NameValuePair> tokens = URLEncodedUtils.parse(tokensCookie.getValue(), Charset.forName("UTF-8")); if (!Objects.equals(token, Utils.get(tokens, "oauth_token"))) throw new IllegalStateException("Missing token in cookie or tokens don't match!"); String secret = Utils.get(tokens, "oauth_token_secret"); if (secret == null) throw new IllegalArgumentException("Missing token secret in cookie!"); OAuth1AccessToken accessToken = helper.accessToken(new OAuth1RequestToken(token, secret), verifier); CookieImpl cookie = new CookieImpl("PYX-Twitter-Token", accessToken.getRawResponse()); cookie.setMaxAge(COOKIE_MAX_AGE); exchange.setResponseCookie(cookie); exchange.getResponseHeaders().add(Headers.LOCATION, REDIRECT_LOCATION); exchange.setStatusCode(StatusCodes.TEMPORARY_REDIRECT); } catch (Throwable ex) { logger.error("Failed processing the request: " + exchange, ex); throw ex; } }
Example 6
Source File: UndertowHttpFacade.java From keycloak with Apache License 2.0 | 5 votes |
@Override public void resetCookie(String name, String path) { CookieImpl cookie = new CookieImpl(name, ""); cookie.setMaxAge(0); cookie.setPath(path); exchange.setResponseCookie(cookie); }
Example 7
Source File: UndertowHttpFacade.java From keycloak with Apache License 2.0 | 5 votes |
@Override public void setCookie(String name, String value, String path, String domain, int maxAge, boolean secure, boolean httpOnly) { CookieImpl cookie = new CookieImpl(name, value); cookie.setPath(path); cookie.setDomain(domain); cookie.setMaxAge(maxAge); cookie.setSecure(secure); cookie.setHttpOnly(httpOnly); exchange.setResponseCookie(cookie); }