public static Optional<MultifactorAuthenticationProvider> getMultifactorAuthenticationProviderById(final String providerId,
                                                                                                       final ApplicationContext context) {
        return getAvailableMultifactorAuthenticationProviders(context).values()
            .stream()
            .filter(p -> p.matches(providerId))
            .findFirst();
    }
public static Optional < MultifactorAuthenticationProvider > getMultifactorAuthenticationProviderById ( final String providerId , final ApplicationContext context ) { return getAvailableMultifactorAuthenticationProviders ( context ) . values ( ) . stream ( ) . filter ( p -> p . matches ( providerId ) ) . findFirst ( ) ; }
Method returns an Optional that will contain a {@link MultifactorAuthenticationProvider} that has the
same id as the passed providerId parameter.

@param providerId - the id to match
@param context    - ApplicationContext
@return - Optional