@Override public void servletRequestLogout() { logout(); }
@Override public InputStream getInputStream() { return getInputStream(false); }
@Override public void logout() throws ServletException { servletRequestLogout(); }
@Override public void logout() { HttpSession httpSession = request.getSession(false); if (httpSession != null) { SerializableKeycloakAccount account = (SerializableKeycloakAccount) httpSession.getAttribute(KeycloakAccount.class.getName()); if (account != null) { account.getKeycloakSecurityContext().logout(deployment); } cleanSession(httpSession); } }
@Override public Map<String, String[]> getParameterMap() { if (!needRequestRestore) return super.getParameterMap(); MultivaluedHashMap<String, String> formParams = getParams(); if (formParams == null) { return super.getParameterMap(); } Map<String, String[]> map = new HashMap<>(); Enumeration<String> names = getParameterNames(); while (names.hasMoreElements()) { String name = names.nextElement(); String[] values = getParameterValues(name); if (values != null) { map.put(name, values); } } return map; }
@Override public String getCharacterEncoding() { if (!needRequestRestore) return super.getCharacterEncoding(); return getCharsetFromContentType(getContentType()); }
MultivaluedHashMap<String, String> getParams() { if (parameters != null) return parameters; if (body == null) return new MultivaluedHashMap<String, String>(); String contentType = getContentType(); if (contentType != null && contentType.toLowerCase().startsWith("application/x-www-form-urlencoded")) { ByteArrayInputStream is = new ByteArrayInputStream(body); try { parameters = parseForm(is); } catch (IOException e) { throw new RuntimeException(e); } } return parameters; } @Override
@Override public void handle(Context context) { OIDCFilterSessionStore.SerializableKeycloakAccount account = context.removeSession(KeycloakAccount.class.getName()); if (account != null) { // Logout of the Keycloak server KeycloakDeployment deployment = account.getKeycloakSecurityContext().getDeployment(); account.getKeycloakSecurityContext().logout(deployment); } // Cleanup the session of Keycloak metadata context.removeSession(KeycloakSecurityContext.class.getName()); context.removeSession(REDIRECT_URI); context.removeSession(SAVED_METHOD); context.removeSession(SAVED_HEADERS); context.removeSession(SAVED_BODY); super.handle(context); } }
@Override public String getContentType() { if (!needRequestRestore) return super.getContentType(); return getHeader("content-type"); }
@Override public String[] getParameterValues(String name) { if (!needRequestRestore) return super.getParameterValues(name); MultivaluedHashMap<String, String> formParams = getParams(); if (formParams == null) { return super.getParameterValues(name); } String[] values = request.getParameterValues(name); List<String> list = new LinkedList<>(); if (values != null) { for (String val : values) list.add(val); } List<String> vals = formParams.get(name); if (vals != null) list.addAll(vals); return list.toArray(new String[list.size()]); }
@Override public void resetCookie(String name, String path) { setCookie(name, "", path, null, 0, false, false); }
public boolean isEnded() { return responseFacade.isEnded(); }
protected void cleanSession(HttpSession session) { session.removeAttribute(KeycloakAccount.class.getName()); session.removeAttribute(KeycloakSecurityContext.class.getName()); clearSavedRequest(session); }
public HttpServletRequestWrapper buildWrapper() { HttpSession session = request.getSession(false); KeycloakAccount account = null; if (session != null) { account = (KeycloakAccount) session.getAttribute(KeycloakAccount.class.getName()); if (account == null) { account = (KeycloakAccount) request.getAttribute(KeycloakAccount.class.getName()); } } if (account == null) { account = (KeycloakAccount) request.getAttribute(KeycloakAccount.class.getName()); } return buildWrapper(session, account); }
@Override public BufferedReader getReader() throws IOException { if (!needRequestRestore) return super.getReader(); return new BufferedReader(new InputStreamReader(getInputStream())); }
@Override public void checkCurrentToken() { HttpSession httpSession = request.getSession(false); if (httpSession == null) return; SerializableKeycloakAccount account = (SerializableKeycloakAccount)httpSession.getAttribute(KeycloakAccount.class.getName()); if (account == null) { return; } RefreshableKeycloakSecurityContext session = account.getKeycloakSecurityContext(); if (session == null) return; // just in case session got serialized if (session.getDeployment() == null) session.setCurrentRequestInfo(deployment, this); if (session.isActive() && !session.getDeployment().isAlwaysRefreshToken()) return; // FYI: A refresh requires same scope, so same roles will be set. Otherwise, refresh will fail and token will // not be updated boolean success = session.refreshExpiredToken(false); if (success && session.isActive()) return; // Refresh failed, so user is already logged out from keycloak. Cleanup and expire our session //log.fine("Cleanup and expire session " + httpSession.getId() + " after failed refresh"); cleanSession(httpSession); httpSession.invalidate(); }
@Override public int getIntHeader(String name) { if (!needRequestRestore) return super.getIntHeader(name); String value = getHeader(name); if (value == null) return -1; return Integer.valueOf(value); }
@Override public void logout() throws ServletException { servletRequestLogout(); }
@Override public String getParameter(String name) { if (!needRequestRestore) return super.getParameter(name); String param = super.getParameter(name); if (param != null) return param; MultivaluedHashMap<String, String> formParams = getParams(); if (formParams == null) { return null; } return formParams.getFirst(name); }
@Override public int getContentLength() { if (!needRequestRestore) return super.getContentLength(); String header = getHeader("content-length"); if (header == null) return -1; return Integer.valueOf(header); }