|
|
|
@ -22,8 +22,13 @@ import io.entgra.ui.request.interceptor.util.HandlerConstants;
|
|
|
|
|
import io.entgra.ui.request.interceptor.util.HandlerUtil;
|
|
|
|
|
import org.apache.commons.logging.Log;
|
|
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
|
import org.apache.http.HttpHeaders;
|
|
|
|
|
import org.apache.http.HttpStatus;
|
|
|
|
|
import io.entgra.ui.request.interceptor.beans.ProxyResponse;
|
|
|
|
|
import org.apache.http.client.methods.HttpGet;
|
|
|
|
|
import org.apache.http.client.methods.HttpPost;
|
|
|
|
|
import org.apache.http.entity.ContentType;
|
|
|
|
|
import org.apache.http.entity.StringEntity;
|
|
|
|
|
|
|
|
|
|
import javax.servlet.annotation.MultipartConfig;
|
|
|
|
|
import javax.servlet.annotation.WebServlet;
|
|
|
|
@ -40,23 +45,55 @@ public class SsoLogoutHandler extends HttpServlet {
|
|
|
|
|
private static final Log log = LogFactory.getLog(SsoLogoutHandler.class);
|
|
|
|
|
|
|
|
|
|
protected void doPost(HttpServletRequest req, HttpServletResponse resp) {
|
|
|
|
|
for (String path : HandlerConstants.SSO_LOGOUT_COOKIE_PATHS) {
|
|
|
|
|
removeCookie(HandlerConstants.JSESSIONID_KEY, path, resp);
|
|
|
|
|
}
|
|
|
|
|
removeCookie(HandlerConstants.COMMON_AUTH_ID_KEY, "/", resp);
|
|
|
|
|
// for (String path : HandlerConstants.SSO_LOGOUT_COOKIE_PATHS) {
|
|
|
|
|
// removeCookie(HandlerConstants.JSESSIONID_KEY, path, resp);
|
|
|
|
|
// }
|
|
|
|
|
// removeCookie(HandlerConstants.COMMON_AUTH_ID_KEY, "/", resp);
|
|
|
|
|
ProxyResponse proxyResponse = new ProxyResponse();
|
|
|
|
|
proxyResponse.setStatus(ProxyResponse.Status.SUCCESS);
|
|
|
|
|
proxyResponse.setCode(HttpStatus.SC_OK);
|
|
|
|
|
|
|
|
|
|
HttpSession session = req.getSession(false);
|
|
|
|
|
String clientId = null;
|
|
|
|
|
String code = null;
|
|
|
|
|
if (session != null) {
|
|
|
|
|
session.invalidate();
|
|
|
|
|
clientId = (String) session.getAttribute("clientId");
|
|
|
|
|
code = (String) session.getAttribute("code");
|
|
|
|
|
System.out.println(code);
|
|
|
|
|
// session.invalidate();
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
HandlerUtil.handleSuccess(resp, proxyResponse);
|
|
|
|
|
// String redirect = "https://localhost:9443/oidc/logout?response_type=code&client_id=" + clientId +"&state&scope=openid&redirect_uri=" + "https://localhost:9443/commonauth";
|
|
|
|
|
String redirect = "https://localhost:9443/oidc/logout"+
|
|
|
|
|
"?code=" + code +
|
|
|
|
|
// "?id_token_hint=" + code +
|
|
|
|
|
"&post_logout_redirect_uri=" + "https://localhost:9443/commonauth";
|
|
|
|
|
System.out.println(redirect);
|
|
|
|
|
System.out.println("\n\n\n");
|
|
|
|
|
System.out.println(code);
|
|
|
|
|
if(session!=null){
|
|
|
|
|
session.invalidate();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// resp.sendRedirect("https://localhost:9443/oidc/logout"+
|
|
|
|
|
// "?id_token_hint=" + code+"&post_logout_redirect_uri=https://localhost:9443/commonauth");
|
|
|
|
|
// HttpGet getApplicationEndpoint = new HttpGet(redirect);
|
|
|
|
|
// ProxyResponse getApplicationResponse = HandlerUtil.execute(getApplicationEndpoint);
|
|
|
|
|
// System.out.println(getApplicationResponse.getCode());
|
|
|
|
|
// HttpGet getApplicationEndpoint2 = new HttpGet("https://api.asgardeo.io/t/noobie/oidc/logout");
|
|
|
|
|
// ProxyResponse getApplicationResponse2 = HandlerUtil.execute(getApplicationEndpoint2);
|
|
|
|
|
// System.out.println(getApplicationResponse2);
|
|
|
|
|
resp.sendRedirect(redirect);
|
|
|
|
|
return;
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
log.error("Error occurred when processing logout request.", e);
|
|
|
|
|
// } catch (Exception e) {
|
|
|
|
|
log.error("123 bumble bee");
|
|
|
|
|
}
|
|
|
|
|
// try {
|
|
|
|
|
// HandlerUtil.handleSuccess(resp, proxyResponse);
|
|
|
|
|
// } catch (IOException e) {
|
|
|
|
|
// log.error("Error occurred when processing logout request.", e);
|
|
|
|
|
// }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void removeCookie(String cookieName,String path, HttpServletResponse response) {
|
|
|
|
|