// Path: shared/src/main/java/org/pac4j/play/context/PlayContextFactory.java
// public class PlayContextFactory implements WebContextFactory {
// 
//     public static final PlayContextFactory INSTANCE = new PlayContextFactory();
// 
//     protected PlayContextFactory() {}
// 
//     @Override
//     public PlayWebContext newContext(final Object... parameters) {
//         return new PlayWebContext((Http.Request) parameters[0]);
//     }
// }
// 
// Path: shared/src/main/java/org/pac4j/play/http/PlayHttpActionAdapter.java
// public class PlayHttpActionAdapter implements HttpActionAdapter {
// 
//     protected final Logger logger = LoggerFactory.getLogger(getClass());
// 
//     public static final PlayHttpActionAdapter INSTANCE = new PlayHttpActionAdapter();
// 
//     protected Map<Integer, Result> results = new HashMap<>();
// 
//     @Override
//     public Result adapt(final HttpAction action, final WebContext context) {
//         if (action != null) {
//             final int code = action.getCode();
//             logger.debug("requires HTTP action: {}", code);
// 
//             final Result predefinedResult = results.get(code);
//             if (predefinedResult != null) {
//                 logger.debug("using pre-defined result for code: {}", code);
//                 return ((PlayWebContext) context).supplementResponse(predefinedResult);
//             }
// 
//             Map<String, String> headers = new HashMap<>();
//             HttpEntity httpEntity = HttpEntity.NO_ENTITY;
// 
//             if (action instanceof WithLocationAction) {
//                 final WithLocationAction withLocationAction = (WithLocationAction) action;
//                 headers.put(HttpConstants.LOCATION_HEADER, withLocationAction.getLocation());
//             } else if (action instanceof WithContentAction) {
//                 final WithContentAction withContentAction = (WithContentAction) action;
//                 final String content = withContentAction.getContent();
// 
//                 if (content != null) {
//                     logger.debug("render: {}", content);
//                     httpEntity = HttpEntity.fromString(content, "UTF-8");
//                 }
//             }
// 
//             return ((PlayWebContext) context).supplementResponse(new Result(code, headers, httpEntity));
//         }
// 
//         throw new TechnicalException("No action provided");
//     }
// 
//     public Map<Integer, Result> getResults() {
//         return results;
//     }
// 
//     public void setResults(final Map<Integer, Result> results) {
//         CommonHelper.assertNotNull("results", results);
//         this.results = results;
//     }
// }


import org.pac4j.core.config.Config;
import org.pac4j.core.context.WebContext;
import org.pac4j.core.context.session.SessionStore;
import org.pac4j.core.engine.CallbackLogic;
import org.pac4j.core.engine.DefaultCallbackLogic;
import org.pac4j.core.http.adapter.HttpActionAdapter;
import org.pac4j.core.util.FindBest;
import org.pac4j.play.context.PlayContextFactory;
import org.pac4j.play.http.PlayHttpActionAdapter;
import play.mvc.Controller;
import play.mvc.Http;
import play.mvc.Result;
import play.libs.concurrent.HttpExecutionContext;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
import javax.inject.Inject;
package org.pac4j.play;




/**
 * <p>This filter finishes the login process for an indirect client.</p>
 *
 * @author Jerome Leleu
 * @author Michael Remond
 * @since 1.5.0
 */
public class CallbackController extends Controller {

    private CallbackLogic callbackLogic;

    private String defaultUrl;

    private Boolean renewSession;

    private String defaultClient;

    @Inject
    protected Config config;
    @Inject
    protected SessionStore sessionStore;
    @Inject
    protected HttpExecutionContext ec;

    public CompletionStage<Result> callback(final Http.Request request) {

        final HttpActionAdapter bestAdapter = FindBest.httpActionAdapter(null, config, PlayHttpActionAdapter.INSTANCE);
        final CallbackLogic bestLogic = FindBest.callbackLogic(callbackLogic, config, DefaultCallbackLogic.INSTANCE);

// Path: shared/src/main/java/org/pac4j/play/context/PlayContextFactory.java
// public class PlayContextFactory implements WebContextFactory {
// 
//     public static final PlayContextFactory INSTANCE = new PlayContextFactory();
// 
//     protected PlayContextFactory() {}
// 
//     @Override
//     public PlayWebContext newContext(final Object... parameters) {
//         return new PlayWebContext((Http.Request) parameters[0]);
//     }
// }
// 
// Path: shared/src/main/java/org/pac4j/play/http/PlayHttpActionAdapter.java
// public class PlayHttpActionAdapter implements HttpActionAdapter {
// 
//     protected final Logger logger = LoggerFactory.getLogger(getClass());
// 
//     public static final PlayHttpActionAdapter INSTANCE = new PlayHttpActionAdapter();
// 
//     protected Map<Integer, Result> results = new HashMap<>();
// 
//     @Override
//     public Result adapt(final HttpAction action, final WebContext context) {
//         if (action != null) {
//             final int code = action.getCode();
//             logger.debug("requires HTTP action: {}", code);
// 
//             final Result predefinedResult = results.get(code);
//             if (predefinedResult != null) {
//                 logger.debug("using pre-defined result for code: {}", code);
//                 return ((PlayWebContext) context).supplementResponse(predefinedResult);
//             }
// 
//             Map<String, String> headers = new HashMap<>();
//             HttpEntity httpEntity = HttpEntity.NO_ENTITY;
// 
//             if (action instanceof WithLocationAction) {
//                 final WithLocationAction withLocationAction = (WithLocationAction) action;
//                 headers.put(HttpConstants.LOCATION_HEADER, withLocationAction.getLocation());
//             } else if (action instanceof WithContentAction) {
//                 final WithContentAction withContentAction = (WithContentAction) action;
//                 final String content = withContentAction.getContent();
// 
//                 if (content != null) {
//                     logger.debug("render: {}", content);
//                     httpEntity = HttpEntity.fromString(content, "UTF-8");
//                 }
//             }
// 
//             return ((PlayWebContext) context).supplementResponse(new Result(code, headers, httpEntity));
//         }
// 
//         throw new TechnicalException("No action provided");
//     }
// 
//     public Map<Integer, Result> getResults() {
//         return results;
//     }
// 
//     public void setResults(final Map<Integer, Result> results) {
//         CommonHelper.assertNotNull("results", results);
//         this.results = results;
//     }
// }


// Path: shared/src/main/java/org/pac4j/play/CallbackController.java
import org.pac4j.core.config.Config;
import org.pac4j.core.context.WebContext;
import org.pac4j.core.context.session.SessionStore;
import org.pac4j.core.engine.CallbackLogic;
import org.pac4j.core.engine.DefaultCallbackLogic;
import org.pac4j.core.http.adapter.HttpActionAdapter;
import org.pac4j.core.util.FindBest;
import org.pac4j.play.context.PlayContextFactory;
import org.pac4j.play.http.PlayHttpActionAdapter;
import play.mvc.Controller;
import play.mvc.Http;
import play.mvc.Result;
import play.libs.concurrent.HttpExecutionContext;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
import javax.inject.Inject;

package org.pac4j.play;




/**
 * <p>This filter finishes the login process for an indirect client.</p>
 *
 * @author Jerome Leleu
 * @author Michael Remond
 * @since 1.5.0
 */
public class CallbackController extends Controller {

    private CallbackLogic callbackLogic;

    private String defaultUrl;

    private Boolean renewSession;

    private String defaultClient;

    @Inject
    protected Config config;
    @Inject
    protected SessionStore sessionStore;
    @Inject
    protected HttpExecutionContext ec;

    public CompletionStage<Result> callback(final Http.Request request) {

        final HttpActionAdapter bestAdapter = FindBest.httpActionAdapter(null, config, PlayHttpActionAdapter.INSTANCE);
        final CallbackLogic bestLogic = FindBest.callbackLogic(callbackLogic, config, DefaultCallbackLogic.INSTANCE);

        final WebContext context = FindBest.webContextFactory(null, config, PlayContextFactory.INSTANCE).newContext(request);