Search in sources :

Example 1 with AsyncProcess

use of org.wso2.carbon.identity.application.authentication.framework.AsyncProcess 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)1 AsyncProcess (org.wso2.carbon.identity.application.authentication.framework.AsyncProcess)1 AsyncReturn (org.wso2.carbon.identity.application.authentication.framework.AsyncReturn)1