/** {@inheritDoc} */ @Override protected void doExecute(@Nonnull final ProfileRequestContext profileRequestContext, @Nonnull final ProfileInterceptorContext interceptorContext) { final ProfileInterceptorFlowDescriptor flow = selectUnattemptedFlow(profileRequestContext, interceptorContext); if (flow == null) { log.debug("{} No flows available to choose from", getLogPrefix()); return; } log.debug("{} Selecting flow {}", getLogPrefix(), flow.getId()); ActionSupport.buildEvent(profileRequestContext, flow.getId()); }
/** * Select the first potential flow not found in the completed flows collection, and that is applicable to the * context. * * @param profileRequestContext the current IdP profile request context * @param interceptorContext the current profile interceptor context * @return an eligible flow, or null */ @Nullable private ProfileInterceptorFlowDescriptor selectUnattemptedFlow( @Nonnull final ProfileRequestContext profileRequestContext, @Nonnull final ProfileInterceptorContext interceptorContext) { for (final ProfileInterceptorFlowDescriptor flow : interceptorContext.getAvailableFlows().values()) { log.debug("{} Checking flow {} for applicability...", getLogPrefix(), flow.getId()); if (flow.apply(profileRequestContext)) { interceptorContext.setAttemptedFlow(flow); return flow; } log.debug("{} Flow {} was not applicable to this request", getLogPrefix(), flow.getId()); // Note that we don't exclude this flow from possible future selection, since one flow // could in theory do partial work and change the context such that this flow then applies. } return null; }
/** {@inheritDoc} */ @Override protected boolean doPreExecute(@Nonnull final ProfileRequestContext profileRequestContext, @Nonnull final ProfileInterceptorContext interceptorContext) { if (!super.doPreExecute(profileRequestContext, interceptorContext)) { return false; } // Detect a previous attempted flow, and move it to the intermediate collection. // This will prevent re-selecting the same flow again. if (interceptorContext.getAttemptedFlow() != null) { log.debug("{} Moving completed flow {} to completed set, selecting next one", getLogPrefix(), interceptorContext.getAttemptedFlow().getId()); interceptorContext.getAvailableFlows().remove(interceptorContext.getAttemptedFlow().getId()); interceptorContext.setAttemptedFlow(null); } return true; }