forked from community/device-mgt-core
but has to manually add the backchannel logout endpointasgardeo_logout_issue
parent
dc8c0bf90a
commit
867c5c5b94
@ -0,0 +1,42 @@
|
||||
package io.entgra.ui.request.interceptor;
|
||||
|
||||
import com.nimbusds.jwt.SignedJWT;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import javax.servlet.http.HttpSession;
|
||||
import java.text.ParseException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class SessionIdStore {
|
||||
private static Log log = LogFactory.getLog(SessionIdStore.class);
|
||||
private static Map<String, HttpSession> sessionMap = new HashMap();
|
||||
|
||||
public SessionIdStore() {
|
||||
}
|
||||
|
||||
public static void storeSession(String sid, HttpSession session) {
|
||||
log.info("Storing session: " + session.getId() + " against the sid: " + sid);
|
||||
sessionMap.put(sid, session);
|
||||
}
|
||||
|
||||
public static String getSid(String idToken) throws ParseException {
|
||||
String sid = (String) SignedJWT.parse(idToken).getJWTClaimsSet().getClaim("sid");
|
||||
return sid;
|
||||
}
|
||||
|
||||
public static HttpSession getSession(String sid) {
|
||||
if (sid != null && sessionMap.get(sid) != null) {
|
||||
log.info("Retrieving session: " + ((HttpSession) sessionMap.get(sid)).getId() + " for the sid: " + sid);
|
||||
return (HttpSession) sessionMap.get(sid);
|
||||
} else {
|
||||
log.error("No session found for the sid: " + sid);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static void removeSession(String sid) {
|
||||
sessionMap.remove(sid);
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
package io.entgra.ui.request.interceptor;
|
||||
|
||||
import com.nimbusds.jwt.SignedJWT;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import javax.servlet.annotation.MultipartConfig;
|
||||
import javax.servlet.annotation.WebServlet;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpSession;
|
||||
import java.text.ParseException;
|
||||
|
||||
@MultipartConfig
|
||||
@WebServlet("/ssoLogoutCallback")
|
||||
public class SsoLogoutCallbackHandler extends HttpServlet {
|
||||
|
||||
private static final Log log = LogFactory.getLog(SsoLogoutCallbackHandler.class);
|
||||
|
||||
@Override
|
||||
public void doGet(HttpServletRequest req, HttpServletResponse resp) {
|
||||
this.doPost(req, resp);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doPost(HttpServletRequest req, HttpServletResponse resp) {
|
||||
log.info("BackChannel Logout Invoked");
|
||||
try {
|
||||
String sid = (String) SignedJWT.parse(req.getParameter("logout_token")).getJWTClaimsSet().getClaim("sid");
|
||||
HttpSession session = SessionIdStore.getSession(sid);
|
||||
if (session != null) {
|
||||
session.invalidate();
|
||||
SessionIdStore.removeSession(sid);
|
||||
log.info("Session invalidated successfully for sid: " + sid);
|
||||
} else {
|
||||
log.info("Cannot find corresponding session for sid: " + sid);
|
||||
}
|
||||
} catch (ParseException e) {
|
||||
log.error("Error in generating Logout Token.", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in new issue