/** * Gets the active session, returning null if one is not present. * @param exchange The exchange * @return The session */ public static Session getSession(final HttpServerExchange exchange) { return getSession(exchange, false); }
/** * Gets the active session, creating a new one if one does not exist * @param exchange The exchange * @return The session */ public static Session getOrCreateSession(final HttpServerExchange exchange) { return getSession(exchange, true); }
protected void handleRedirectBack(final HttpServerExchange exchange) { final Session session = Sessions.getSession(exchange); if (session != null) { final String location = (String) session.removeAttribute(LOCATION_ATTRIBUTE); if(location != null) { exchange.addDefaultResponseListener(new DefaultResponseListener() { @Override public boolean handleDefaultResponse(final HttpServerExchange exchange) { exchange.getResponseHeaders().put(Headers.LOCATION, location); exchange.setStatusCode(StatusCodes.FOUND); exchange.endExchange(); return true; } }); } } }
/** * Gets the active session, returning null if one is not present. * @param exchange The exchange * @return The session */ public static Session getSession(final HttpServerExchange exchange) { return getSession(exchange, false); }
/** * Gets the active session, creating a new one if one does not exist * @param exchange The exchange * @return The session */ public static Session getOrCreateSession(final HttpServerExchange exchange) { return getSession(exchange, true); }
/** * Gets the active session, returning null if one is not present. * @param exchange The exchange * @return The session */ public static Session getSession(final HttpServerExchange exchange) { return getSession(exchange, false); }
/** * Gets the active session, creating a new one if one does not exist * @param exchange The exchange * @return The session */ public static Session getOrCreateSession(final HttpServerExchange exchange) { return getSession(exchange, true); }
@Override public void logout() { Session session = Sessions.getSession(exchange); if (session == null) return; KeycloakUndertowAccount account = (KeycloakUndertowAccount)session.getAttribute(KeycloakUndertowAccount.class.getName()); if (account == null) return; session.removeAttribute(KeycloakUndertowAccount.class.getName()); session.removeAttribute(KeycloakSecurityContext.class.getName()); }
@Override public void logout() { Session session = Sessions.getSession(exchange); if (session == null) return; KeycloakUndertowAccount account = (KeycloakUndertowAccount)session.getAttribute(KeycloakUndertowAccount.class.getName()); if (account == null) return; session.removeAttribute(KeycloakUndertowAccount.class.getName()); session.removeAttribute(KeycloakSecurityContext.class.getName()); }
protected void handleRedirectBack(final HttpServerExchange exchange) { final Session session = Sessions.getSession(exchange); if (session != null) { final String location = (String) session.removeAttribute(LOCATION_ATTRIBUTE); if(location != null) { exchange.addDefaultResponseListener(new DefaultResponseListener() { @Override public boolean handleDefaultResponse(final HttpServerExchange exchange) { exchange.getResponseHeaders().put(Headers.LOCATION, location); exchange.setStatusCode(StatusCodes.FOUND); exchange.endExchange(); return true; } }); } } }
protected void handleRedirectBack(final HttpServerExchange exchange) { final Session session = Sessions.getSession(exchange); if (session != null) { final String location = (String) session.removeAttribute(LOCATION_ATTRIBUTE); if(location != null) { exchange.addDefaultResponseListener(new DefaultResponseListener() { @Override public boolean handleDefaultResponse(final HttpServerExchange exchange) { exchange.getResponseHeaders().put(Headers.LOCATION, location); exchange.setStatusCode(StatusCodes.FOUND); exchange.endExchange(); return true; } }); } } }
@Override protected String changeHttpSessionId(boolean create) { if (create) { Session session = Sessions.getOrCreateSession(exchange); return session.getId(); } else { Session session = Sessions.getSession(exchange); return session != null ? session.getId() : null; } }
@Override protected String changeHttpSessionId(boolean create) { if (create) { Session session = Sessions.getOrCreateSession(exchange); return session.getId(); } else { Session session = Sessions.getSession(exchange); return session != null ? session.getId() : null; } }
@Override public boolean isCached(RequestAuthenticator authenticator) { Session session = Sessions.getSession(exchange); if (session == null) { log.debug("session was null, returning null"); return false; } KeycloakUndertowAccount account = (KeycloakUndertowAccount)session.getAttribute(KeycloakUndertowAccount.class.getName()); if (account == null) { log.debug("Account was not in session, returning null"); return false; } if (!deployment.getRealm().equals(account.getKeycloakSecurityContext().getRealm())) { log.debug("Account in session belongs to a different realm than for this request."); return false; } account.setCurrentRequestInfo(deployment, this); if (account.checkActive()) { log.debug("Cached account found"); securityContext.authenticationComplete(account, "KEYCLOAK", false); ((AbstractUndertowRequestAuthenticator)authenticator).propagateKeycloakContext(account); return true; } else { log.debug("Account was not active, returning false"); session.removeAttribute(KeycloakUndertowAccount.class.getName()); session.removeAttribute(KeycloakSecurityContext.class.getName()); session.invalidate(exchange); return false; } }
@Override public boolean isCached(RequestAuthenticator authenticator) { Session session = Sessions.getSession(exchange); if (session == null) { log.debug("session was null, returning null"); return false; } KeycloakUndertowAccount account = (KeycloakUndertowAccount)session.getAttribute(KeycloakUndertowAccount.class.getName()); if (account == null) { log.debug("Account was not in session, returning null"); return false; } if (!deployment.getRealm().equals(account.getKeycloakSecurityContext().getRealm())) { log.debug("Account in session belongs to a different realm than for this request."); return false; } account.setCurrentRequestInfo(deployment, this); if (account.checkActive()) { log.debug("Cached account found"); securityContext.authenticationComplete(account, "KEYCLOAK", false); ((AbstractUndertowRequestAuthenticator)authenticator).propagateKeycloakContext(account); return true; } else { log.debug("Account was not active, returning false"); session.removeAttribute(KeycloakUndertowAccount.class.getName()); session.removeAttribute(KeycloakSecurityContext.class.getName()); session.invalidate(exchange); return false; } }