package org.pac4j.play.cas.logout;

import org.pac4j.cas.logout.NoLogoutHandler;
import org.pac4j.core.context.Pac4jConstants;
import org.pac4j.core.context.WebContext;
import org.pac4j.core.profile.ProfileManager;
import org.pac4j.core.util.CommonHelper;
import org.pac4j.play.PlayWebContext;
import org.pac4j.play.store.PlayCacheStore;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import play.cache.CacheApi;

import javax.inject.Inject;

/**
 * This class handles logout requests from a CAS server using the Play Cache.
 * 
 * @author Jerome Leleu
 * @since 1.1.0
 */
public class PlayCacheLogoutHandler extends NoLogoutHandler {

    protected final Logger logger = LoggerFactory.getLogger(getClass());


    private final CacheApi cache;

    @Inject
    public PlayCacheLogoutHandler(CacheApi cacheApi) {
        this.cache = cacheApi;
    }

    public void destroySession(WebContext context) {
        final PlayWebContext webContext = (PlayWebContext) context;
        final String logoutRequest = context.getRequestParameter("logoutRequest");
        logger.debug("logoutRequest: {}", logoutRequest);
        final String ticket = CommonHelper.substringBetween(logoutRequest, "SessionIndex>", "</");
        logger.debug("extract ticket: {}", ticket);
        final String sessionId = cache.get(ticket);
        cache.remove(ticket);
        webContext.getJavaSession().put(Pac4jConstants.SESSION_ID, sessionId);
        final ProfileManager profileManager = new ProfileManager(webContext);
        profileManager.remove(true);
    }

    public void recordSession(WebContext context, String ticket) {
        logger.debug("ticket: {}", ticket);
        final PlayWebContext webContext = (PlayWebContext) context;
        final PlayCacheStore playCacheStore = (PlayCacheStore) webContext.getSessionStore();
        final String sessionId = playCacheStore.getOrCreateSessionId(webContext);
        logger.debug("save sessionId: {}", sessionId);
        cache.set(ticket, sessionId, playCacheStore.getProfileTimeout());
    }
}

@@ -29,16 +29,51 @@
 ogout;%0A%0A
+import com.google.inject.Provider;%0A
 import o
@@ -782,16 +782,71 @@
 i cache;
+%0A    private final Provider%3CCacheApi%3E cacheApiProvider;
 %0A%0A    @I
@@ -885,16 +885,22 @@
 Handler(
+final 
 CacheApi
@@ -934,26 +934,332 @@
 ache
- = cacheApi;%0A    %7D
+ApiProvider = null;%0A        this.cache = cacheApi;%0A    %7D%0A%0A    public PlayCacheLogoutHandler(final Provider%3CCacheApi%3E cacheApiProvider) %7B%0A        this.cache = null;%0A        this.cacheApiProvider = cacheApiProvider;%0A    %7D%0A%0A    private CacheApi getCache() %7B%0A        return cache != null ? cache : cacheApiProvider.get();%0A    %7D%0A
 %0A%0A  
@@ -1702,21 +1702,26 @@
 ionId = 
-c
+getC
 ache
+()
 .get(tic
@@ -1734,21 +1734,26 @@
         
-c
+getC
 ache
+()
 .remove(
@@ -2379,21 +2379,26 @@
         
-c
+getC
 ache
+()
 .set(tic

Create another constructor where the cache API is injected via a provider.