WIP: Asgardeo Login Issue #57
Draft
deenath
wants to merge 4 commits from deenath/device-mgt-core:asgardeo_logout_issue
into master
@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright (c) 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
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,62 @@
|
||||
/*
|
||||
* Copyright (c) 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||
*
|
||||
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
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