public <ReturnType, CreateArgType, ConsumedType> void registerConsumerFactory(
      AuthenticationConsumerFactory<ReturnType, CreateArgType, ConsumedType> factory ) throws AuthenticationFactoryException {
    if ( !factory.getConsumedType().isInterface()
        && !AuthenticationProvider.class.isAssignableFrom( factory.getConsumedType() ) ) {
      throw new AuthenticationFactoryException( BaseMessages.getString( PKG, "AuthenticationManager.ConsumedTypeError",
          factory ) );
    }

    Map<Class<?>, AuthenticationConsumerFactory<?, ?, ?>> createTypeMap =
        getRelevantConsumerFactoryMap( factory.getReturnType(), factory.getCreateArgType() );
    synchronized ( createTypeMap ) {
      createTypeMap.put( factory.getConsumedType(), factory );
    }
  }
@SuppressWarnings( { "rawtypes", "unchecked" } )
  @Test
  public void testRegisterConsumerFactory() throws AuthenticationConsumptionException, AuthenticationFactoryException {
    AuthenticationConsumer<Object, KerberosAuthenticationProvider> authConsumer = mock( AuthenticationConsumer.class );
    AuthenticationConsumerFactory<Object, AuthenticationConsumer, KerberosAuthenticationProvider> factory =
        mock( AuthenticationConsumerFactory.class );
    when( factory.getReturnType() ).thenReturn( Object.class );
    when( factory.getCreateArgType() ).thenReturn( AuthenticationConsumer.class );
    when( factory.getConsumedType() ).thenReturn( KerberosAuthenticationProvider.class );
    when( factory.create( authConsumer ) ).thenReturn( authConsumer );
    KerberosAuthenticationProvider kerberosAuthenticationProvider =
        new KerberosAuthenticationProvider( "kerb", "kerb", true, "pass", true, "none" );
    manager.registerAuthenticationProvider( kerberosAuthenticationProvider );
    manager.registerConsumerFactory( factory );
    manager.getAuthenticationPerformer( Object.class, AuthenticationConsumer.class,
        kerberosAuthenticationProvider.getId() ).perform( authConsumer );
    verify( authConsumer ).consume( kerberosAuthenticationProvider );
  }