BeforeLogout.groovy 783 Bytes
import org.keycloak.adapters.KeycloakDeploymentBuilder
import org.keycloak.adapters.servlet.OIDCServletHttpFacade
import org.keycloak.adapters.servlet.OIDCFilterSessionStore

ec.logger.info("moqui-keycloak:before-logout")


def cache = ec.getCache().getCache('moqui-keycloak:deployment')

def keycloakJsonUrl = 'component://moqui-keycloak/config/moqui-keycloak.json'
def configStream = ec.getResource().getLocationStream(keycloakJsonUrl)
def keycloakDeployment = KeycloakDeploymentBuilder.build(configStream)

def idMapper = cache.get('SessionIdMapper')
if (idMapper == null) return

def facade = new OIDCServletHttpFacade(ec.web.request, ec.web.response)
def tokenStore = new OIDCFilterSessionStore(ec.web.request, facade, 100000, keycloakDeployment, idMapper)

tokenStore.logout()