Java Code Examples for org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext#setReturning()

The following examples show how to use org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext#setReturning() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GraphBasedSequenceHandler.java    From carbon-identity-framework with Apache License 2.0 4 votes vote down vote up
private boolean handleLongWait(HttpServletRequest request, HttpServletResponse response,
                               AuthenticationContext context, SequenceConfig sequenceConfig,
                               LongWaitNode longWaitNode) throws FrameworkException {

    boolean isWaiting;
    LongWaitStatusStoreService longWaitStatusStoreService =
            FrameworkServiceDataHolder.getInstance().getLongWaitStatusStoreService();
    LongWaitStatus longWaitStatus = longWaitStatusStoreService.getWait(context.getContextIdentifier());
    if (longWaitStatus == null || longWaitStatus.getStatus() == LongWaitStatus.Status.UNKNOWN) {
        //This is a initiation of long wait
        longWaitStatus = new LongWaitStatus();
        int tenantId = IdentityTenantUtil.getTenantId(context.getTenantDomain());
        longWaitStatusStoreService.addWait(tenantId, context.getContextIdentifier(), longWaitStatus);
        isWaiting = callExternalSystem(request, response, context, sequenceConfig, longWaitNode);
        if (promptOnLongWait()) {
            if (isWaiting) {
                displayLongWait(context, request, response);
            }
        }
    } else {
        context.setReturning(false);
        // This is a continuation of long wait
        isWaiting = LongWaitStatus.Status.COMPLETED != longWaitStatus.getStatus();
        longWaitStatusStoreService.removeWait(context.getContextIdentifier());
        String outcomeName = (String) context.getProperty(FrameworkConstants.JSAttributes.JS_CALL_AND_WAIT_STATUS);
        Map<String, Object> data = (Map<String, Object>) context.getProperty(
                FrameworkConstants.JSAttributes.JS_CALL_AND_WAIT_DATA);
        context.removeProperty(FrameworkConstants.JSAttributes.JS_CALL_AND_WAIT_STATUS);
        context.removeProperty(FrameworkConstants.JSAttributes.JS_CALL_AND_WAIT_DATA);
        AuthGraphNode nextNode;
        if (outcomeName != null) {
            executeFunction(outcomeName, longWaitNode, context, data);
            nextNode = longWaitNode.getDefaultEdge();
            if (nextNode == null) {
                log.error("Authentication script does not have applicable event handler for outcome "
                        + outcomeName + " from the long wait process : " + context.getContextIdentifier()
                        + ". So ending the authentication flow. Add the correspoding event handler to the script");
                nextNode = new FailNode();
            }
        } else {
            log.error("The outcome from the long wait process " + context.getContextIdentifier()
                    + " is null. Because asyncReturn.accept() has not been used properly in the async process flow"
                    + " of the custom function. So ending the authentication flow. Check the flow in the async"
                    + " process flow of the custom function and add asyncReturn.accept() with the corresponding"
                    + " outcome.");
            nextNode = new FailNode();
        }
        context.setProperty(FrameworkConstants.JSAttributes.PROP_CURRENT_NODE, nextNode);
    }
    return isWaiting;
}
 
Example 2
Source File: DefaultRequestCoordinator.java    From carbon-identity with Apache License 2.0 4 votes vote down vote up
@Override
public void handle(HttpServletRequest request, HttpServletResponse response) throws IOException {

    try {
        AuthenticationContext context;
        AuthenticationRequestCacheEntry authRequest = null;
        String sessionDataKey = request.getParameter("sessionDataKey");

        boolean returning = false;
        // Check whether this is the start of the authentication flow.
        // 'type' parameter should be present if so. This parameter contains
        // the request type (e.g. samlsso) set by the calling servlet.
        // TODO: use a different mechanism to determine the flow start.
        if (request.getParameter("type") != null) {
            // Retrieve AuthenticationRequestCache Entry which is stored stored from servlet.
            if (sessionDataKey != null) {
                if (log.isDebugEnabled()) {
                    log.debug("retrieving authentication request from cache..");
                }

                authRequest = getAuthenticationRequest(request, sessionDataKey);

                if (authRequest == null) {
                    // authRequest cannot be retrieved from cache. Cache
                    throw new FrameworkException("Invalid authentication request. Session data key : " + sessionDataKey);
                }

            } else if (!Boolean.parseBoolean(request.getParameter(FrameworkConstants.LOGOUT))) {

                // sessionDataKey is null and not a logout request
                if (log.isDebugEnabled()) {
                    log.debug("Session data key is null in the request and not a logout request.");
                }

                FrameworkUtils.sendToRetryPage(request, response);
            }

            // if there is a cache entry, wrap the original request with params in cache entry
            if (authRequest != null) {
                request = FrameworkUtils.getCommonAuthReqWithParams(request, authRequest);
                FrameworkUtils.removeAuthenticationRequestFromCache(sessionDataKey);
            }
            context = initializeFlow(request, response);
        } else {
            returning = true;
            context = FrameworkUtils.getContextData(request);
        }

        if (context != null) {
            context.setReturning(returning);

            // if this is the flow start, store the original request in the context
            if (!context.isReturning() && authRequest != null) {
                context.setAuthenticationRequest(authRequest.getAuthenticationRequest());
            }


            if (!context.isLogoutRequest()) {
                FrameworkUtils.getAuthenticationRequestHandler().handle(request, response,
                                                                        context);
            } else {
                FrameworkUtils.getLogoutRequestHandler().handle(request, response, context);
            }
        } else {
            if (log.isDebugEnabled()) {
                String key = request.getParameter("sessionDataKey");
                if (key == null) {
                    log.debug("Session data key is null in the request");
                } else {
                    log.debug("Session data key  :  " + key);
                }
            }
            log.error("Context does not exist. Probably due to invalidated cache");
            FrameworkUtils.sendToRetryPage(request, response);
        }
    } catch (Throwable e) {
        log.error("Exception in Authentication Framework", e);
        FrameworkUtils.sendToRetryPage(request, response);
    }
}