Search in sources :

Example 1 with AsyncCaller

use of org.wso2.carbon.identity.application.authentication.framework.AsyncCaller in project carbon-identity-framework by wso2.

the class AsyncSequenceExecutor method exec.

public void exec(AsyncCaller caller, AsyncReturn returnFunction, AuthenticationContext authenticationContext) throws FrameworkException {
    if (returnFunction == null) {
        throw new FrameworkException("Can not execute the async process, as no callback function registered on " + "returnFunction.");
    }
    AsyncReturn wrappedReturn = (ctx, m, r) -> {
        this.execReturn(returnFunction, ctx, m, r);
    };
    executorService.submit(new AsyncCallerTask(new ObservingAsyncProcess(caller, wrappedReturn, authenticationContext)));
}
Also used : LongWaitStatusStoreService(org.wso2.carbon.identity.application.authentication.framework.store.LongWaitStatusStoreService) AuthenticationContext(org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext) LongWaitStatus(org.wso2.carbon.identity.application.authentication.framework.model.LongWaitStatus) Executors(java.util.concurrent.Executors) AsyncReturn(org.wso2.carbon.identity.application.authentication.framework.AsyncReturn) AsyncCaller(org.wso2.carbon.identity.application.authentication.framework.AsyncCaller) FrameworkServiceDataHolder(org.wso2.carbon.identity.application.authentication.framework.internal.FrameworkServiceDataHolder) Map(java.util.Map) IdentityUtil(org.wso2.carbon.identity.core.util.IdentityUtil) FrameworkException(org.wso2.carbon.identity.application.authentication.framework.exception.FrameworkException) Log(org.apache.commons.logging.Log) LogFactory(org.apache.commons.logging.LogFactory) FrameworkUtils(org.wso2.carbon.identity.application.authentication.framework.util.FrameworkUtils) ExecutorService(java.util.concurrent.ExecutorService) FrameworkException(org.wso2.carbon.identity.application.authentication.framework.exception.FrameworkException) AsyncReturn(org.wso2.carbon.identity.application.authentication.framework.AsyncReturn)

Example 2 with AsyncCaller

use of org.wso2.carbon.identity.application.authentication.framework.AsyncCaller in project carbon-identity-framework by wso2.

the class GraphBasedSequenceHandler method callExternalSystem.

private boolean callExternalSystem(HttpServletRequest request, HttpServletResponse response, AuthenticationContext context, SequenceConfig sequenceConfig, LongWaitNode longWaitNode) throws FrameworkException {
    AsyncProcess asyncProcess = longWaitNode.getAsyncProcess();
    if (asyncProcess == null) {
        return false;
    }
    AsyncCaller caller = asyncProcess.getAsyncCaller();
    AsyncReturn asyncReturn = rethrowTriConsumer((authenticationContext, data, result) -> {
        authenticationContext.setProperty(FrameworkConstants.JSAttributes.JS_CALL_AND_WAIT_STATUS, result);
        authenticationContext.setProperty(FrameworkConstants.JSAttributes.JS_CALL_AND_WAIT_DATA, data);
        if (!promptOnLongWait()) {
            synchronized (context) {
                context.notify();
            }
        }
    });
    if (caller != null) {
        FrameworkServiceDataHolder.getInstance().getAsyncSequenceExecutor().exec(caller, asyncReturn, context);
        if (!promptOnLongWait()) {
            int waitTimeout = getLongWaitTimeout();
            synchronized (context) {
                try {
                    context.wait(waitTimeout);
                } catch (InterruptedException e) {
                    Thread.currentThread().interrupt();
                    log.error("Thread interrupted while waiting for the external call to complete for session " + "data key: " + context.getContextIdentifier() + ". ", e);
                }
            }
            resumeLongWait(request, response, context);
        }
        return true;
    }
    return false;
}
Also used : AsyncCaller(org.wso2.carbon.identity.application.authentication.framework.AsyncCaller) AsyncReturn(org.wso2.carbon.identity.application.authentication.framework.AsyncReturn) AsyncProcess(org.wso2.carbon.identity.application.authentication.framework.AsyncProcess)

Aggregations

AsyncCaller (org.wso2.carbon.identity.application.authentication.framework.AsyncCaller)2 AsyncReturn (org.wso2.carbon.identity.application.authentication.framework.AsyncReturn)2 Map (java.util.Map)1 ExecutorService (java.util.concurrent.ExecutorService)1 Executors (java.util.concurrent.Executors)1 Log (org.apache.commons.logging.Log)1 LogFactory (org.apache.commons.logging.LogFactory)1 AsyncProcess (org.wso2.carbon.identity.application.authentication.framework.AsyncProcess)1 AuthenticationContext (org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext)1 FrameworkException (org.wso2.carbon.identity.application.authentication.framework.exception.FrameworkException)1 FrameworkServiceDataHolder (org.wso2.carbon.identity.application.authentication.framework.internal.FrameworkServiceDataHolder)1 LongWaitStatus (org.wso2.carbon.identity.application.authentication.framework.model.LongWaitStatus)1 LongWaitStatusStoreService (org.wso2.carbon.identity.application.authentication.framework.store.LongWaitStatusStoreService)1 FrameworkUtils (org.wso2.carbon.identity.application.authentication.framework.util.FrameworkUtils)1 IdentityUtil (org.wso2.carbon.identity.core.util.IdentityUtil)1