Register multifactor trusted authentication into webflow.

@param flowDefinitionRegistry the flow definition registry
508642
protected void registerMultifactorTrustedAuthentication(final FlowDefinitionRegistry flowDefinitionRegistry) {
        validateFlowDefinitionConfiguration(flowDefinitionRegistry);

        LOGGER.debug("Flow definitions found in the registry are [{}]", (Object[]) flowDefinitionRegistry.getFlowDefinitionIds());
        val flowId = Arrays.stream(flowDefinitionRegistry.getFlowDefinitionIds()).findFirst().get();
        LOGGER.debug("Processing flow definition [{}]", flowId);

        val flow = (Flow) flowDefinitionRegistry.getFlowDefinition(flowId);

        val state = getState(flow, CasWebflowConstants.STATE_ID_INIT_LOGIN_FORM, ActionState.class);
        val transition = (Transition) state.getTransition(CasWebflowConstants.TRANSITION_ID_SUCCESS);
        val targetStateId = transition.getTargetStateId();
        transition.setTargetStateResolver(new DefaultTargetStateResolver(CasWebflowConstants.STATE_ID_VERIFY_TRUSTED_DEVICE));
        val verifyAction = createActionState(flow,
            CasWebflowConstants.STATE_ID_VERIFY_TRUSTED_DEVICE,
            createEvaluateAction(MFA_VERIFY_TRUST_ACTION_BEAN_ID));

        if (enableDeviceRegistration) {
            createTransitionForState(verifyAction, CasWebflowConstants.TRANSITION_ID_YES, CasWebflowConstants.STATE_ID_FINISH_MFA_TRUSTED_AUTH);
        } else {
            createTransitionForState(verifyAction, CasWebflowConstants.TRANSITION_ID_YES, CasWebflowConstants.STATE_ID_REAL_SUBMIT);
        }
        createTransitionForState(verifyAction, CasWebflowConstants.TRANSITION_ID_NO, targetStateId);

        createDecisionState(flow, CasWebflowConstants.DECISION_STATE_REQUIRE_REGISTRATION,
            isDeviceRegistrationRequired(),
            CasWebflowConstants.VIEW_ID_REGISTER_DEVICE, CasWebflowConstants.STATE_ID_REAL_SUBMIT);

        val submit = getState(flow, CasWebflowConstants.STATE_ID_REAL_SUBMIT, ActionState.class);
        val 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));
        }
        val viewRegister = createViewState(flow, CasWebflowConstants.VIEW_ID_REGISTER_DEVICE, "casMfaRegisterDeviceView");
        val viewRegisterTransition = createTransition(CasWebflowConstants.TRANSITION_ID_SUBMIT,
            CasWebflowConstants.STATE_ID_REGISTER_TRUSTED_DEVICE);
        viewRegister.getTransitionSet().add(viewRegisterTransition);

        val registerAction = createActionState(flow,
            CasWebflowConstants.STATE_ID_REGISTER_TRUSTED_DEVICE, createEvaluateAction(MFA_SET_TRUST_ACTION_BEAN_ID));
        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);
        }
        val act = submit.getActionList().iterator().next();
        val finishMfaTrustedAuth = createActionState(flow, CasWebflowConstants.STATE_ID_FINISH_MFA_TRUSTED_AUTH, act);
        val finishedTransition = createTransition(CasWebflowConstants.TRANSITION_ID_SUCCESS, CasWebflowConstants.STATE_ID_SUCCESS);
        finishMfaTrustedAuth.getTransitionSet().add(finishedTransition);
        createStateDefaultTransition(finishMfaTrustedAuth, CasWebflowConstants.STATE_ID_SUCCESS);
    }
698331
private <T> void authenticateExecuteAndProcessResults(Supplier<String> authenticator, Function<String, CompletableFuture<T>> call,
                                                          final StreamObserver<T> streamObserver, RequestTag requestTag) {
        try {
            String delegationToken;
            delegationToken = authenticator.get();
            CompletableFuture<T> result = call.apply(delegationToken);
            result.whenComplete(
                    (value, ex) -> {
                        log.debug("result =  {}", value);
                        logAndUntrackRequestTag(requestTag);
                        if (ex != null) {
                            Throwable cause = Exceptions.unwrap(ex);
                            log.error("Controller api failed with error: ", ex);
                            String errorDescription = replyWithStackTraceOnError ? "controllerStackTrace=" + Throwables.getStackTraceAsString(ex) : cause.getMessage();
                            streamObserver.onError(Status.INTERNAL
                                    .withCause(cause)
                                    .withDescription(errorDescription)
                                    .asRuntimeException());
                        } else if (value != null) {
                            streamObserver.onNext(value);
                            streamObserver.onCompleted();
                        }
                    });
        } catch (Exception e) {
            log.error("Controller api failed with authenticator error");
            logAndUntrackRequestTag(requestTag);
            streamObserver.onError(Status.UNAUTHENTICATED
                    .withDescription("Authentication failed")
                    .asRuntimeException());
        }
    }
569569
public void verifyProcessDefinitionsDoNotShareKeys(
      Collection<ProcessDefinitionEntity> processDefinitions) {
    Set<String> keySet = new LinkedHashSet<String>();
    for (ProcessDefinitionEntity processDefinition : processDefinitions) {
      if (keySet.contains(processDefinition.getKey())) {
        throw new ActivitiException(
            "The deployment contains process definitions with the same key (process id attribute), this is not allowed");
      }
      keySet.add(processDefinition.getKey());
    }
  }
955245
<T> void findFlowDefinition(@Observes ProcessProducer<T, Flow> processProducer)
    {
        if (processProducer.getAnnotatedMember().isAnnotationPresent(FlowDefinition.class))
        {
            flowProducers.add(processProducer.getProducer());
        }
    }
611418
protected void createLoginFormView(final Flow flow) {
        val propertiesToBind = CollectionUtils.wrapList("username", "password", "source");
        val binder = createStateBinderConfiguration(propertiesToBind);

        casProperties.getView().getCustomLoginFormFields()
            .forEach((field, props) -> {
                val fieldName = String.format("customFields[%s]", field);
                binder.addBinding(new BinderConfiguration.Binding(fieldName, props.getConverter(), props.isRequired()));
            });

        val state = createViewState(flow, CasWebflowConstants.STATE_ID_VIEW_LOGIN_FORM, "casLoginView", binder);
        state.getRenderActionList().add(createEvaluateAction(CasWebflowConstants.ACTION_ID_RENDER_LOGIN_FORM));
        createStateModelBinding(state, CasWebflowConstants.VAR_ID_CREDENTIAL, UsernamePasswordCredential.class);

        val transition = createTransitionForState(state, CasWebflowConstants.TRANSITION_ID_SUBMIT, CasWebflowConstants.STATE_ID_REAL_SUBMIT);
        val attributes = transition.getAttributes();
        attributes.put("bind", Boolean.TRUE);
        attributes.put("validate", Boolean.TRUE);
        attributes.put("history", History.INVALIDATE);
    }
770175
public void setFlowProperties(Flow[] flows)
    throws SIIncorrectCallException
  {
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
      SibTr.entry(tc, "setFlowProperties", flows);

    try
    {
      // Take the Write Lock for classifications
      classificationWriteLock.lock();

      // Disallow null flows
      if(flows == null)
      {
        SIIncorrectCallException e =
          new SIIncorrectCallException(
            nls.getFormattedMessage(
                "NULL_FLOW_CLASSIFICATIONS_CWSIP0851",
                new Object[] {
                  "com.ibm.ws.sib.processor.impl.JSConsumerSet.setFlowProperties",
                  "1:877:1.16",
                  label },
                null));
        
        // FFDC
        FFDCFilter.processException(
          e,
          "com.ibm.ws.sib.processor.impl.JSConsumerSet.setFlowProperties",
          "1:885:1.16",
          this);
            
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) 
          SibTr.exit(tc, "setFlowProperties", "SIIncorrectCallException");
        throw e;
      }
    
      // Set up the new classifications for the ConsumerSet
      boolean weightChangeOnly = classifications.setClassifications(flows);
    
      // Need to notify registered keys of the change but only if the flow change is
      // substantive - i.e. more than just a change in the relative weightings of the 
      // current flows.
      if(!weightChangeOnly)
      {
        Iterator<DispatchableKey> it = keyRegistry.iterator();
        while (it.hasNext())
        {
          DispatchableKey key = (DispatchableKey)it.next();
          // Notify the appropriate key
          if(key instanceof LocalQPConsumerKey)
          {
            ((LocalQPConsumerKey)(key)).notifyResetFlowProperties();
          }
          else if(key instanceof LocalQPConsumerKeyGroup)
          {
            ((LocalQPConsumerKeyGroup)(key)).notifyResetFlowProperties();
          }
        }
      }
    }
    catch(InvalidFlowsException ife)
    {
      // FFDC
      FFDCFilter.processException(
        ife,
        "com.ibm.ws.sib.processor.impl.JSConsumerSet.setFlowProperties",
        "1:923:1.16",
        this);
      
      // Map the InvalidFlowsException to an SIIncorrectCallException
      SIIncorrectCallException e =
        new SIIncorrectCallException(
          nls.getFormattedMessage(
              "INVALID_FLOW_CLASSIFICATIONS_CWSIP0852",
              new Object[] {
                "com.ibm.ws.sib.processor.impl.JSConsumerSet.setFlowProperties",
                "1:933:1.16",
                label },
              null));
          
      if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) 
        SibTr.exit(tc, "setFlowProperties", "SIIncorrectCallException");
      throw e;
    }
    finally
    {
      // Free the write lock
      classificationWriteLock.unlock();
    }
    
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
      SibTr.exit(tc, "setFlowProperties");        
  }
522767
public FacesConfigFlowDefinitionType<FacesConfigType<T>> getOrCreateFlowDefinition()
   {
      List<Node> nodeList = childNode.get("flow-definition");
      if (nodeList != null &&  nodeList.size() > 0)
      {
         return new FacesConfigFlowDefinitionTypeImpl<FacesConfigType<T>>(this, "flow-definition", childNode, nodeList.get(0));
      }
      return createFlowDefinition();
   }
516672
protected void createServiceCheckDecisionState(final Flow flow) {
        createDecisionState(flow, CasWebflowConstants.STATE_ID_SERVICE_CHECK,
            "flowScope.service != null",
            CasWebflowConstants.STATE_ID_GENERATE_SERVICE_TICKET,
            CasWebflowConstants.STATE_ID_VIEW_GENERIC_LOGIN_SUCCESS);
    }
1112628
protected void validateCredentials(final UsernamePasswordCredentials credentials,
                                       final OAuthRegisteredService registeredService,
                                       final WebContext context) {
        if (!OAuth20Utils.checkClientSecret(registeredService, credentials.getPassword())) {
            throw new CredentialsException("Bad secret for client identifier: " + credentials.getPassword());
        }
    }
1031219
public static void writeFlowId(Message message, String flowId) {
        Map<String, List<String>> headers = getOrCreateProtocolHeader(message);
        headers.put(FLOWID_HTTP_HEADER_NAME, Collections.singletonList(flowId));
        if (LOG.isLoggable(Level.FINE)) {
            LOG.fine("HTTP header '" + FLOWID_HTTP_HEADER_NAME + "' set to: " + flowId);
        }
    }
965216
public FacesConfigFlowDefinitionType<WebFacesConfigDescriptor> getOrCreateFlowDefinition()
   {
      List<Node> nodeList = model.get("flow-definition");
      if (nodeList != null &&  nodeList.size() > 0)
      {
         return new FacesConfigFlowDefinitionTypeImpl<WebFacesConfigDescriptor>(this, "flow-definition", model, nodeList.get(0));
      }
      return createFlowDefinition();
   }
1131391
protected void createDefaultEndStates(final Flow flow) {
        createRedirectUnauthorizedServiceUrlEndState(flow);
        createServiceErrorEndState(flow);
        createRedirectEndState(flow);
        createPostEndState(flow);
        createInjectHeadersActionState(flow);
        createGenericLoginSuccessEndState(flow);
        createServiceWarningViewState(flow);
        createEndWebflowEndState(flow);
    }
373844
protected void createDefaultActionStates(final Flow flow) {
        createRealSubmitAction(flow);
        createInitialAuthenticationRequestValidationCheckAction(flow);
        createCreateTicketGrantingTicketAction(flow);
        createSendTicketGrantingTicketAction(flow);
        createGenerateServiceTicketAction(flow);
        createGatewayServicesMgmtAction(flow);
        createServiceAuthorizationCheckAction(flow);
        createRedirectToServiceActionState(flow);
        createHandleAuthenticationFailureAction(flow);
        createTerminateSessionAction(flow);
        createTicketGrantingTicketCheckAction(flow);
    }
1371017
public void execute() {
        OrderComparator.sortIfNecessary(webflowConfigurers);
        webflowConfigurers.forEach(c -> {
            LOGGER.trace("Registering webflow configurer [{}]", c.getName());
            c.initialize();
        });
    }
668915
public void registerAuthenticationProvider(Class<? extends AuthenticationProvider> providerClass) {
    AuthenticationProvider provider = instantiateProvider(providerClass);
    authenticationProviders.put(provider.getName(), providerClass);  
    credentialAuths.put(provider.getName(), provider.requiresCredentials());
  }
1362190
protected void createRedirectUnauthorizedServiceUrlEndState(final Flow flow) {
        val state = createEndState(flow, CasWebflowConstants.STATE_ID_VIEW_REDIR_UNAUTHZ_URL, "flowScope.unauthorizedRedirectUrl", true);
        state.getEntryActionList().add(createEvaluateAction("redirectUnauthorizedServiceUrlAction"));
    }
606035
@Override
    public void setAuthConfigFactory(AuthConfigFactory factory) {
        this.registry = factory;
        if (tc.isDebugEnabled())
            Tr.debug(tc, "AuthConfigFactory = " + factory);
    }