@Override public void beforeCommit(HttpServerExchange exchange) { Map<String, Cookie> cookies = exchange.getResponseCookiesInternal(); if (cookies != null) { for (Map.Entry<String, Cookie> cookie : exchange.getResponseCookies().entrySet()) { cookie.getValue().setSecure(true); } } } }
/** * impl of dumping response cookies to result * @param result A map you want to put dump information to */ @Override public void dumpResponse(Map<String, Object> result) { Map<String, Cookie> cookiesMap = exchange.getResponseCookies(); dumpCookies(cookiesMap, "responseCookies"); this.putDumpInfoTo(result); }
@Override public void start(StartContext context) throws StartException { pathHandler.clearPaths(); SecureRandomSessionIdGenerator generator = new SecureRandomSessionIdGenerator(); pathHandler.addPrefixPath(AFFINITY_PATH, exchange -> { String resolved = exchange.getResolvedPath(); int index = resolved.lastIndexOf(AFFINITY_PATH); if(index > 0) { resolved = resolved.substring(0, index); } exchange.getResponseCookies().put("JSESSIONID", new CookieImpl("JSESSIONID", generator.createSessionId()).setPath(resolved)); }); }
@Override public void beforeCommit(HttpServerExchange exchange) { Map<String, Cookie> cookies = exchange.getResponseCookiesInternal(); if (cookies != null) { for (Map.Entry<String, Cookie> cookie : exchange.getResponseCookies().entrySet()) { cookie.getValue().setSecure(true); } } } }
private void clearSsoCookie(HttpServerExchange exchange) { exchange.getResponseCookies().put(cookieName, new CookieImpl(cookieName).setMaxAge(0).setHttpOnly(httpOnly).setSecure(secure).setDomain(domain).setPath(path)); }
@Override public void beforeCommit(HttpServerExchange exchange) { Map<String, Cookie> cookies = exchange.getResponseCookiesInternal(); if (cookies != null) { for (Map.Entry<String, Cookie> cookie : exchange.getResponseCookies().entrySet()) { cookie.getValue().setSecure(true); } } } }
Map<String, Cookie> cookies = exchange.getResponseCookies(); if (cookies != null) { for (Cookie cookie : cookies.values()) {
@Override protected void applyCookies() { for (String name : getCookies().keySet()) { for (ResponseCookie httpCookie : getCookies().get(name)) { Cookie cookie = new CookieImpl(name, httpCookie.getValue()); if (!httpCookie.getMaxAge().isNegative()) { cookie.setMaxAge((int) httpCookie.getMaxAge().getSeconds()); } 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.exchange.getResponseCookies().putIfAbsent(name, cookie); } } }
private HttpHandler setupRoutes(HttpHandler handler) { final SimpleSessionIdentifierCodec codec = new SimpleSessionIdentifierCodec(new SimpleRoutingSupport(), this.host.getValue().getServer().getRoute()); return exchange -> { exchange.addResponseCommitListener(ex -> { Cookie cookie = ex.getResponseCookies().get(JSESSIONID); if(cookie != null ) { cookie.setValue(codec.encode(cookie.getValue())); } }); handler.handleRequest(exchange); }; }
@Override public StreamSinkConduit wrap(ConduitFactory<StreamSinkConduit> factory, HttpServerExchange exchange) { SecurityContext sc = exchange.getSecurityContext(); Account account = sc.getAuthenticatedAccount(); if (account != null) { try (SingleSignOn sso = singleSignOnManager.createSingleSignOn(account, sc.getMechanismName())) { Session session = getSession(exchange); registerSessionIfRequired(sso, session); exchange.getResponseCookies().put(cookieName, new CookieImpl(cookieName, sso.getId()).setHttpOnly(httpOnly).setSecure(secure).setDomain(domain).setPath(path)); } } return factory.create(); } }
@Override protected void applyCookies() { for (String name : getCookies().keySet()) { for (ResponseCookie httpCookie : getCookies().get(name)) { Cookie cookie = new CookieImpl(name, httpCookie.getValue()); if (!httpCookie.getMaxAge().isNegative()) { cookie.setMaxAge((int) httpCookie.getMaxAge().getSeconds()); } 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.exchange.getResponseCookies().putIfAbsent(name, cookie); } } }
public Exchange cookie(Cookie cookie) { if (cookie != null) { exchange.getResponseCookies().put(cookie.getName(), cookie); } return this; }
@Override public void addCookie(Cookie cookie) { io.undertow.server.handlers.Cookie undertowCookie = UndertowCookieHelper.convertNinjaCookieToUndertowCookie(cookie); exchange.getResponseCookies().put(undertowCookie.getName(), undertowCookie); }
@Override public void start(StartContext context) throws StartException { pathHandler.clearPaths(); SecureRandomSessionIdGenerator generator = new SecureRandomSessionIdGenerator(); pathHandler.addPrefixPath(AFFINITY_PATH, exchange -> { String resolved = exchange.getResolvedPath(); int index = resolved.lastIndexOf(AFFINITY_PATH); if(index > 0) { resolved = resolved.substring(0, index); } exchange.getResponseCookies().put("JSESSIONID", new CookieImpl("JSESSIONID", generator.createSessionId()).setPath(resolved)); }); }
@Override public void start(StartContext context) throws StartException { pathHandler.clearPaths(); SecureRandomSessionIdGenerator generator = new SecureRandomSessionIdGenerator(); pathHandler.addPrefixPath(AFFINITY_PATH, exchange -> { String resolved = exchange.getResolvedPath(); int index = resolved.lastIndexOf(AFFINITY_PATH); if(index > 0) { resolved = resolved.substring(0, index); } exchange.getResponseCookies().put("JSESSIONID", new CookieImpl("JSESSIONID", generator.createSessionId()).setPath(resolved)); }); }
private HttpHandler setupRoutes(HttpHandler handler) { final SimpleSessionIdentifierCodec codec = new SimpleSessionIdentifierCodec(new SimpleRoutingSupport(), this.host.getValue().getServer().getRoute()); return exchange -> { exchange.addResponseCommitListener(ex -> { Cookie cookie = ex.getResponseCookies().get(JSESSIONID); if(cookie != null ) { cookie.setValue(codec.encode(cookie.getValue())); } }); handler.handleRequest(exchange); }; }
private HttpHandler setupRoutes(HttpHandler handler) { final SimpleSessionIdentifierCodec codec = new SimpleSessionIdentifierCodec(new SimpleRoutingSupport(), this.host.getValue().getServer().getRoute()); return exchange -> { exchange.addResponseCommitListener(ex -> { Cookie cookie = ex.getResponseCookies().get(JSESSIONID); if(cookie != null ) { cookie.setValue(codec.encode(cookie.getValue())); } }); handler.handleRequest(exchange); }; }
protected void processAudit(HttpServerExchange exchange) throws Exception{ if (oauth_config.isEnableAudit() ) { AuditInfo auditInfo = new AuditInfo(); auditInfo.setServiceId(Oauth2Service.USER); auditInfo.setEndpoint(exchange.getHostName() + exchange.getRelativePath()); auditInfo.setRequestHeader(exchange.getRequestHeaders().toString()); auditInfo.setRequestBody(Config.getInstance().getMapper().writeValueAsString(exchange.getAttachment(BodyHandler.REQUEST_BODY))); auditInfo.setResponseCode(exchange.getStatusCode()); auditInfo.setResponseHeader(exchange.getResponseHeaders().toString()); auditInfo.setResponseBody(Config.getInstance().getMapper().writeValueAsString(exchange.getResponseCookies())); saveAudit(auditInfo); } }
protected void processAudit(HttpServerExchange exchange) throws Exception{ if (oauth_config.isEnableAudit() ) { AuditInfo auditInfo = new AuditInfo(); auditInfo.setServiceId(Oauth2Service.SERVICE); auditInfo.setEndpoint(exchange.getHostName() + exchange.getRelativePath()); auditInfo.setRequestHeader(exchange.getRequestHeaders().toString()); auditInfo.setRequestBody(Config.getInstance().getMapper().writeValueAsString(exchange.getAttachment(BodyHandler.REQUEST_BODY))); auditInfo.setResponseCode(exchange.getStatusCode()); auditInfo.setResponseHeader(exchange.getResponseHeaders().toString()); auditInfo.setResponseBody(Config.getInstance().getMapper().writeValueAsString(exchange.getResponseCookies())); saveAudit(auditInfo); } }
protected void processAudit(HttpServerExchange exchange) throws Exception{ if (oauth_config.isEnableAudit() ) { AuditInfo auditInfo = new AuditInfo(); auditInfo.setServiceId(Oauth2Service.CLIENT); auditInfo.setEndpoint(exchange.getHostName() + exchange.getRelativePath()); auditInfo.setRequestHeader(exchange.getRequestHeaders().toString()); auditInfo.setRequestBody(Config.getInstance().getMapper().writeValueAsString(exchange.getAttachment(BodyHandler.REQUEST_BODY))); auditInfo.setResponseCode(exchange.getStatusCode()); auditInfo.setResponseHeader(exchange.getResponseHeaders().toString()); auditInfo.setResponseBody(Config.getInstance().getMapper().writeValueAsString(exchange.getResponseCookies())); saveAudit(auditInfo); } }