core/cas-server-core-webflow/src/main/java/org/apereo/cas/web/flow/AbstractMultifactorTrustedDeviceWebflowConfigurer.java
/**
     * Register multifactor trusted authentication into webflow.
     */
Register multifactor trusted authentication into webflow.
Register multifactor trusted authentication into webflow .
protected void registerMultifactorTrustedAuthentication() {
        if (flowDefinitionRegistry.getFlowDefinitionCount() <= 0) {
            throw new IllegalArgumentException("Flow definition registry has no flow definitions");
        }
        logger.debug("Flow definitions found in the registry are {}", (Object[]) flowDefinitionRegistry.getFlowDefinitionIds());
        final String flowId = Arrays.stream(flowDefinitionRegistry.getFlowDefinitionIds()).findFirst().get();
        logger.debug("Processing flow definition {}", flowId);
        final Flow flow = (Flow) flowDefinitionRegistry.getFlowDefinition(flowId);
        final ActionState state = (ActionState) flow.getState(CasWebflowConstants.STATE_ID_INIT_LOGIN_FORM);
        final Transition transition = (Transition) state.getTransition(CasWebflowConstants.TRANSITION_ID_SUCCESS);
        final String targetStateId = transition.getTargetStateId();
        transition.setTargetStateResolver(new DefaultTargetStateResolver(CasWebflowConstants.STATE_ID_VERIFY_TRUSTED_DEVICE));
        final ActionState verifyAction = createActionState(flow,
                CasWebflowConstants.STATE_ID_VERIFY_TRUSTED_DEVICE,
                createEvaluateAction("mfaVerifyTrustAction"));
        if (enableDeviceRegistration) {
            createTransitionForState(verifyAction, CasWebflowConstants.TRANSITION_ID_YES, "finishMfaTrustedAuth");
        } else {
            createTransitionForState(verifyAction, CasWebflowConstants.TRANSITION_ID_YES, CasWebflowConstants.TRANSITION_ID_REAL_SUBMIT);
        }
        createTransitionForState(verifyAction, CasWebflowConstants.TRANSITION_ID_NO, targetStateId);
        createDecisionState(flow, CasWebflowConstants.DECISION_STATE_REQUIRE_REGISTRATION,
                isDeviceRegistrationRequired(),
                CasWebflowConstants.VIEW_ID_REGISTER_DEVICE, CasWebflowConstants.TRANSITION_ID_REAL_SUBMIT);
        final ActionState submit = (ActionState) flow.getState(CasWebflowConstants.TRANSITION_ID_REAL_SUBMIT);
        final Transition success = (Transition) submit.getTransition(CasWebflowConstants.TRANSITION_ID_SUCCESS);
        if (enableDeviceRegistration) {
            success.setTargetStateResolver(new DefaultTargetStateResolver(CasWebflowConstants.VIEW_ID_REGISTER_DEVICE));
        } else {
            success.setTargetStateResolver(new DefaultTargetStateResolver(CasWebflowConstants.STATE_ID_REGISTER_TRUSTED_DEVICE));
        }
        final ViewState viewRegister = createViewState(flow, CasWebflowConstants.VIEW_ID_REGISTER_DEVICE, "casMfaRegisterDeviceView");
        viewRegister.getTransitionSet().add(createTransition(CasWebflowConstants.TRANSITION_ID_SUBMIT,
                CasWebflowConstants.STATE_ID_REGISTER_TRUSTED_DEVICE));
        final ActionState registerAction = createActionState(flow, CasWebflowConstants.STATE_ID_REGISTER_TRUSTED_DEVICE, 
                createEvaluateAction("mfaSetTrustAction"));
        createStateDefaultTransition(registerAction, CasWebflowConstants.STATE_ID_SUCCESS);
        if (submit.getActionList().size() == 0) {
            throw new IllegalArgumentException("There are no actions defined for the final submission event of " + flowId);
        }
        final Action act = submit.getActionList().iterator().next();
        final ActionState finishMfaTrustedAuth = createActionState(flow, "finishMfaTrustedAuth", act);
        finishMfaTrustedAuth.getTransitionSet().add(
                createTransition(CasWebflowConstants.TRANSITION_ID_SUCCESS, CasWebflowConstants.STATE_ID_SUCCESS));
        createStateDefaultTransition(finishMfaTrustedAuth, CasWebflowConstants.STATE_ID_SUCCESS);
    }
protected void registerMultifactorTrustedAuthentication ( ) { if ( flowDefinitionRegistry . getFlowDefinitionCount ( ) <= 0 ) { throw new IllegalArgumentException ( "Flow definition registry has no flow definitions" ) ; } logger . debug ( "Flow definitions found in the registry are {}" , ( Object [ ] ) flowDefinitionRegistry . getFlowDefinitionIds ( ) ) ; final String flowId = Arrays . stream ( flowDefinitionRegistry . getFlowDefinitionIds ( ) ) . findFirst ( ) . get ( ) ; logger . debug ( "Processing flow definition {}" , flowId ) ; final Flow flow = ( Flow ) flowDefinitionRegistry . getFlowDefinition ( flowId ) ; final ActionState state = ( ActionState ) flow . getState ( CasWebflowConstants . STATE_ID_INIT_LOGIN_FORM ) ; final Transition transition = ( Transition ) state . getTransition ( CasWebflowConstants . TRANSITION_ID_SUCCESS ) ; final String targetStateId = transition . getTargetStateId ( ) ; transition . setTargetStateResolver ( new DefaultTargetStateResolver ( CasWebflowConstants . STATE_ID_VERIFY_TRUSTED_DEVICE ) ) ; final ActionState verifyAction = createActionState ( flow , CasWebflowConstants . STATE_ID_VERIFY_TRUSTED_DEVICE , createEvaluateAction ( "mfaVerifyTrustAction" ) ) ; if ( enableDeviceRegistration ) { createTransitionForState ( verifyAction , CasWebflowConstants . TRANSITION_ID_YES , "finishMfaTrustedAuth" ) ; } else { createTransitionForState ( verifyAction , CasWebflowConstants . TRANSITION_ID_YES , CasWebflowConstants . TRANSITION_ID_REAL_SUBMIT ) ; } createTransitionForState ( verifyAction , CasWebflowConstants . TRANSITION_ID_NO , targetStateId ) ; createDecisionState ( flow , CasWebflowConstants . DECISION_STATE_REQUIRE_REGISTRATION , isDeviceRegistrationRequired ( ) , CasWebflowConstants . VIEW_ID_REGISTER_DEVICE , CasWebflowConstants . TRANSITION_ID_REAL_SUBMIT ) ; final ActionState submit = ( ActionState ) flow . getState ( CasWebflowConstants . TRANSITION_ID_REAL_SUBMIT ) ; final Transition success = ( Transition ) submit . getTransition ( CasWebflowConstants . TRANSITION_ID_SUCCESS ) ; if ( enableDeviceRegistration ) { success . setTargetStateResolver ( new DefaultTargetStateResolver ( CasWebflowConstants . VIEW_ID_REGISTER_DEVICE ) ) ; } else { success . setTargetStateResolver ( new DefaultTargetStateResolver ( CasWebflowConstants . STATE_ID_REGISTER_TRUSTED_DEVICE ) ) ; } final ViewState viewRegister = createViewState ( flow , CasWebflowConstants . VIEW_ID_REGISTER_DEVICE , "casMfaRegisterDeviceView" ) ; viewRegister . getTransitionSet ( ) . add ( createTransition ( CasWebflowConstants . TRANSITION_ID_SUBMIT , CasWebflowConstants . STATE_ID_REGISTER_TRUSTED_DEVICE ) ) ; final ActionState registerAction = createActionState ( flow , CasWebflowConstants . STATE_ID_REGISTER_TRUSTED_DEVICE , createEvaluateAction ( "mfaSetTrustAction" ) ) ; createStateDefaultTransition ( registerAction , CasWebflowConstants . STATE_ID_SUCCESS ) ; if ( submit . getActionList ( ) . size ( ) == 0 ) { throw new IllegalArgumentException ( "There are no actions defined for the final submission event of " + flowId ) ; } final Action act = submit . getActionList ( ) . iterator ( ) . next ( ) ; final ActionState finishMfaTrustedAuth = createActionState ( flow , "finishMfaTrustedAuth" , act ) ; finishMfaTrustedAuth . getTransitionSet ( ) . add ( createTransition ( CasWebflowConstants . TRANSITION_ID_SUCCESS , CasWebflowConstants . STATE_ID_SUCCESS ) ) ; createStateDefaultTransition ( finishMfaTrustedAuth , CasWebflowConstants . STATE_ID_SUCCESS ) ; }
Register multifactor trusted authentication into webflow.
Register multifactor trusted authentication into webflow .
// Set the verify action // handle device registration