53 lines
1.8 KiB
Java
53 lines
1.8 KiB
Java
package com.nubisware.oidc.lr62;
|
|
|
|
import java.io.IOException;
|
|
|
|
import javax.servlet.http.HttpSession;
|
|
|
|
import com.liferay.portal.kernel.events.ActionException;
|
|
import com.liferay.portal.kernel.events.SessionAction;
|
|
import com.liferay.portal.kernel.log.Log;
|
|
import com.liferay.portal.kernel.log.LogFactoryUtil;
|
|
import com.liferay.portal.model.User;
|
|
import com.nubisware.oidc.rest.JWTToken;
|
|
import com.nubisware.oidc.rest.OpenIdConnectRESTHelper;
|
|
|
|
public class SessionDestroyAction extends SessionAction {
|
|
|
|
protected static final Log log = LogFactoryUtil.getLog(SessionDestroyAction.class);
|
|
|
|
@Override
|
|
public void run(HttpSession session) throws ActionException {
|
|
if (log.isTraceEnabled()) {
|
|
log.trace("Session details: id=" + session.getId() + ", instance=" + session);
|
|
}
|
|
LiferayOpenIdConnectConfiguration configuration = LiferayOpenIdConnectConfiguration.getConfiguration();
|
|
if (configuration.logoutOnPortalLogout()) {
|
|
JWTToken token = JWTTokenUtil.getOIDCFromSession(session);
|
|
if (token != null) {
|
|
if (log.isDebugEnabled()) {
|
|
log.debug("Performing logout on OIDC server due to session destroy");
|
|
}
|
|
try {
|
|
OpenIdConnectRESTHelper.logout(token, configuration.getLogoutUrl(), configuration.getClientId());
|
|
} catch (IOException e) {
|
|
throw new ActionException("Performing logut on OIDC server", e);
|
|
}
|
|
} else {
|
|
log.error("Cannot find the OIDC token in session");
|
|
}
|
|
} else {
|
|
if (log.isDebugEnabled()) {
|
|
log.debug("Don't performing OIDC logout according to configuration");
|
|
}
|
|
}
|
|
if (log.isDebugEnabled()) {
|
|
log.debug("Removing OIDC tokens from cache proxy");
|
|
}
|
|
User user = (User) session.getAttribute("USER");
|
|
OIDCTokenProxy.getInstance().removeOIDCToken(user, session);
|
|
OIDCTokenProxy.getInstance().removeUMAToken(user, session);
|
|
}
|
|
|
|
}
|