Search in sources :

Example 1 with SequenceConfig

use of org.wso2.carbon.identity.application.authentication.framework.config.model.SequenceConfig in project carbon-identity-framework by wso2.

the class FileBasedConfigurationBuilder method processSequenceElement.

/**
 * Create SequenceDOs for each sequence entry
 *
 * @param sequenceElem
 * @return
 */
private SequenceConfig processSequenceElement(OMElement sequenceElem) {
    SequenceConfig sequenceConfig = new SequenceConfig();
    String applicationId = "default";
    OMAttribute appIdAttr = sequenceElem.getAttribute(new QName(FrameworkConstants.Config.ATTR_APPLICATION_ID));
    if (appIdAttr != null) {
        applicationId = appIdAttr.getAttributeValue();
    }
    sequenceConfig.setApplicationId(applicationId);
    OMAttribute forceAuthnAttr = sequenceElem.getAttribute(new QName(FrameworkConstants.Config.ATTR_FORCE_AUTHENTICATE));
    if (forceAuthnAttr != null) {
        sequenceConfig.setForceAuthn(Boolean.valueOf(forceAuthnAttr.getAttributeValue()));
    }
    OMAttribute checkAuthnAttr = sequenceElem.getAttribute(new QName(FrameworkConstants.Config.ATTR_CHECK_AUTHENTICATE));
    if (checkAuthnAttr != null) {
        sequenceConfig.setCheckAuthn(Boolean.valueOf(checkAuthnAttr.getAttributeValue()));
    }
    // RequestPathAuthenticators
    OMElement reqPathAuthenticatorsElem = sequenceElem.getFirstChildWithName(IdentityApplicationManagementUtil.getQNameWithIdentityApplicationNS(FrameworkConstants.Config.ELEM_REQ_PATH_AUTHENTICATOR));
    if (reqPathAuthenticatorsElem != null) {
        for (Iterator reqPathAuthenticatorElems = reqPathAuthenticatorsElem.getChildElements(); reqPathAuthenticatorElems.hasNext(); ) {
            OMElement reqPathAuthenticatorElem = (OMElement) reqPathAuthenticatorElems.next();
            String authenticatorName = reqPathAuthenticatorElem.getAttributeValue(IdentityApplicationManagementUtil.getQNameWithIdentityApplicationNS(FrameworkConstants.Config.ATTR_AUTHENTICATOR_NAME));
            AuthenticatorConfig authenticatorConfig = authenticatorConfigMap.get(authenticatorName);
            sequenceConfig.getReqPathAuthenticators().add(authenticatorConfig);
        }
    }
    // for each step defined, create a StepDO instance
    for (Iterator stepElements = sequenceElem.getChildrenWithLocalName(FrameworkConstants.Config.ELEM_STEP); stepElements.hasNext(); ) {
        StepConfig stepConfig = processStepElement((OMElement) stepElements.next());
        if (stepConfig != null) {
            sequenceConfig.getStepMap().put(stepConfig.getOrder(), stepConfig);
        }
    }
    return sequenceConfig;
}
Also used : AuthenticatorConfig(org.wso2.carbon.identity.application.authentication.framework.config.model.AuthenticatorConfig) QName(javax.xml.namespace.QName) Iterator(java.util.Iterator) StepConfig(org.wso2.carbon.identity.application.authentication.framework.config.model.StepConfig) SequenceConfig(org.wso2.carbon.identity.application.authentication.framework.config.model.SequenceConfig) OMElement(org.apache.axiom.om.OMElement) OMAttribute(org.apache.axiom.om.OMAttribute)

Example 2 with SequenceConfig

use of org.wso2.carbon.identity.application.authentication.framework.config.model.SequenceConfig in project carbon-identity-framework by wso2.

the class UIBasedConfigurationLoader method getSequenceConfig.

@Override
public SequenceConfig getSequenceConfig(AuthenticationContext context, Map<String, String[]> parameterMap, ServiceProvider serviceProvider) throws FrameworkException {
    String tenantDomain = context.getTenantDomain();
    AuthenticationStep[] authenticationSteps = null;
    LocalAndOutboundAuthenticationConfig localAndOutboundAuthenticationConfig = serviceProvider.getLocalAndOutBoundAuthenticationConfig();
    if (localAndOutboundAuthenticationConfig.getAuthenticationSteps() != null && localAndOutboundAuthenticationConfig.getAuthenticationSteps().length > 0) {
        // Use the default steps when there are no chains configured.
        authenticationSteps = localAndOutboundAuthenticationConfig.getAuthenticationSteps();
    }
    SequenceConfig sequenceConfig = getSequence(serviceProvider, tenantDomain, authenticationSteps);
    // Use script based evaluation if script is present.
    if (isAuthenticationScriptBasedSequence(localAndOutboundAuthenticationConfig)) {
        // Clear the sequenceConfig step map, so that it will be re-populated by Dynamic execution
        Map<Integer, StepConfig> originalStepConfigMap = new HashMap<>(sequenceConfig.getStepMap());
        Map<Integer, StepConfig> stepConfigMapCopy = new HashMap<>();
        originalStepConfigMap.forEach((k, v) -> stepConfigMapCopy.put(k, new StepConfig(v)));
        sequenceConfig.getStepMap().clear();
        JsGraphBuilderFactory jsGraphBuilderFactory = FrameworkServiceDataHolder.getInstance().getJsGraphBuilderFactory();
        JsGraphBuilder jsGraphBuilder = jsGraphBuilderFactory.createBuilder(context, stepConfigMapCopy);
        context.setServiceProviderName(serviceProvider.getApplicationName());
        AuthenticationGraph graph = jsGraphBuilder.createWith(localAndOutboundAuthenticationConfig.getAuthenticationScriptConfig().getContent()).build();
        graph.setEnabled(localAndOutboundAuthenticationConfig.getAuthenticationScriptConfig().isEnabled());
        sequenceConfig.setAuthenticationGraph(graph);
        graph.setStepMap(originalStepConfigMap);
    }
    return sequenceConfig;
}
Also used : JsGraphBuilderFactory(org.wso2.carbon.identity.application.authentication.framework.config.model.graph.JsGraphBuilderFactory) LocalAndOutboundAuthenticationConfig(org.wso2.carbon.identity.application.common.model.LocalAndOutboundAuthenticationConfig) HashMap(java.util.HashMap) AuthenticationStep(org.wso2.carbon.identity.application.common.model.AuthenticationStep) StepConfig(org.wso2.carbon.identity.application.authentication.framework.config.model.StepConfig) JsGraphBuilder(org.wso2.carbon.identity.application.authentication.framework.config.model.graph.JsGraphBuilder) SequenceConfig(org.wso2.carbon.identity.application.authentication.framework.config.model.SequenceConfig) AuthenticationGraph(org.wso2.carbon.identity.application.authentication.framework.config.model.graph.AuthenticationGraph)

Example 3 with SequenceConfig

use of org.wso2.carbon.identity.application.authentication.framework.config.model.SequenceConfig in project carbon-identity-framework by wso2.

the class UIBasedConfigurationLoader method loadRequestPathAuthenticators.

protected void loadRequestPathAuthenticators(SequenceConfig sequenceConfig, ServiceProvider serviceProvider) {
    if (serviceProvider.getRequestPathAuthenticatorConfigs() != null && serviceProvider.getRequestPathAuthenticatorConfigs().length > 0) {
        List<AuthenticatorConfig> requestPathAuthenticators = new ArrayList<AuthenticatorConfig>();
        RequestPathAuthenticatorConfig[] reqAuths = serviceProvider.getRequestPathAuthenticatorConfigs();
        // for each request path authenticator
        for (RequestPathAuthenticatorConfig reqAuth : reqAuths) {
            AuthenticatorConfig authConfig = new AuthenticatorConfig();
            String authenticatorName = reqAuth.getName();
            authConfig.setName(authenticatorName);
            authConfig.setEnabled(true);
            // iterate through each system authentication config
            for (ApplicationAuthenticator appAuthenticator : FrameworkServiceComponent.getAuthenticators()) {
                if (authenticatorName.equalsIgnoreCase(appAuthenticator.getName())) {
                    authConfig.setApplicationAuthenticator(appAuthenticator);
                    break;
                }
            }
            requestPathAuthenticators.add(authConfig);
        }
        sequenceConfig.setReqPathAuthenticators(requestPathAuthenticators);
    }
}
Also used : RequestPathAuthenticatorConfig(org.wso2.carbon.identity.application.common.model.RequestPathAuthenticatorConfig) AuthenticatorConfig(org.wso2.carbon.identity.application.authentication.framework.config.model.AuthenticatorConfig) FederatedAuthenticatorConfig(org.wso2.carbon.identity.application.common.model.FederatedAuthenticatorConfig) LocalAuthenticatorConfig(org.wso2.carbon.identity.application.common.model.LocalAuthenticatorConfig) ApplicationAuthenticator(org.wso2.carbon.identity.application.authentication.framework.ApplicationAuthenticator) ArrayList(java.util.ArrayList) RequestPathAuthenticatorConfig(org.wso2.carbon.identity.application.common.model.RequestPathAuthenticatorConfig)

Example 4 with SequenceConfig

use of org.wso2.carbon.identity.application.authentication.framework.config.model.SequenceConfig in project carbon-identity-framework by wso2.

the class FrameworkUtils method isStepBasedSequenceHandlerExecuted.

/**
 * @deprecated This method is a temporary solution and might get changed in the future.
 * It is recommended not use this method.
 *
 * @param context AuthenticationContext.
 * @return true if the handlers need to be executed, otherwise false.
 */
@Deprecated
public static boolean isStepBasedSequenceHandlerExecuted(AuthenticationContext context) {
    boolean isNeeded = true;
    SequenceConfig sequenceConfig = context.getSequenceConfig();
    AuthenticatedUser authenticatedUser = sequenceConfig.getAuthenticatedUser();
    Object isDefaultStepBasedSequenceHandlerTriggered = context.getProperty(FrameworkConstants.STEP_BASED_SEQUENCE_HANDLER_TRIGGERED);
    // If authenticated user is null or if step based sequence handler is not trigged, exit the flow.
    if (authenticatedUser == null || isDefaultStepBasedSequenceHandlerTriggered == null || !(boolean) isDefaultStepBasedSequenceHandlerTriggered) {
        isNeeded = false;
    }
    return isNeeded;
}
Also used : SequenceConfig(org.wso2.carbon.identity.application.authentication.framework.config.model.SequenceConfig) JSONObject(org.json.JSONObject) AuthenticatedUser(org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser)

Example 5 with SequenceConfig

use of org.wso2.carbon.identity.application.authentication.framework.config.model.SequenceConfig in project carbon-identity-framework by wso2.

the class DefaultAuthenticationRequestHandlerTest method addSequence.

private void addSequence(AuthenticationContext context, boolean isCompleted) {
    SequenceConfig sequenceConfig = new SequenceConfig();
    sequenceConfig.setCompleted(isCompleted);
    context.setSequenceConfig(sequenceConfig);
}
Also used : SequenceConfig(org.wso2.carbon.identity.application.authentication.framework.config.model.SequenceConfig)

Aggregations

SequenceConfig (org.wso2.carbon.identity.application.authentication.framework.config.model.SequenceConfig)67 AuthenticationContext (org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext)31 Test (org.testng.annotations.Test)28 StepConfig (org.wso2.carbon.identity.application.authentication.framework.config.model.StepConfig)24 ServiceProvider (org.wso2.carbon.identity.application.common.model.ServiceProvider)23 AuthenticatorConfig (org.wso2.carbon.identity.application.authentication.framework.config.model.AuthenticatorConfig)19 HttpServletRequest (javax.servlet.http.HttpServletRequest)18 HttpServletResponse (javax.servlet.http.HttpServletResponse)18 FrameworkException (org.wso2.carbon.identity.application.authentication.framework.exception.FrameworkException)18 AuthenticatedUser (org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser)17 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)14 HashMap (java.util.HashMap)13 ApplicationAuthenticator (org.wso2.carbon.identity.application.authentication.framework.ApplicationAuthenticator)13 AuthHistory (org.wso2.carbon.identity.application.authentication.framework.context.AuthHistory)11 ApplicationConfig (org.wso2.carbon.identity.application.authentication.framework.config.model.ApplicationConfig)10 FederatedApplicationAuthenticator (org.wso2.carbon.identity.application.authentication.framework.FederatedApplicationAuthenticator)9 Map (java.util.Map)8 ExternalIdPConfig (org.wso2.carbon.identity.application.authentication.framework.config.model.ExternalIdPConfig)7 AuthGraphNode (org.wso2.carbon.identity.application.authentication.framework.config.model.graph.AuthGraphNode)7 ArrayList (java.util.ArrayList)6