@Override public Object consume( KerberosAuthenticationProvider authenticationProvider ) throws AuthenticationConsumptionException { return delegate.consume( authenticationProvider ); } }
@Override public Object consume( UsernamePasswordAuthenticationProvider authenticationProvider ) throws AuthenticationConsumptionException { return delegate.consume( authenticationProvider ); } }
@Override public Object consume( KerberosAuthenticationProviderProxyInterface authenticationProvider ) throws AuthenticationConsumptionException { return delegate.consume( authenticationProvider ); } }
@Override public ReturnType perform( CreateArgType consumerCreateArg ) throws AuthenticationConsumptionException { AuthenticationConsumer<ReturnType, T> consumer = authenticationConsumerFactory.create( consumerCreateArg ); return consumer.consume( provider ); }
@Override public Object consume( NoAuthenticationAuthenticationProvider authenticationProvider ) throws AuthenticationConsumptionException { return delegate.consume( authenticationProvider ); } }
@SuppressWarnings( "unchecked" ) @Override public ReturnType perform( CreateArgType consumerCreateArg ) throws AuthenticationConsumptionException { AuthenticationConsumer<ReturnType, ConsumedType> consumer = authenticationConsumerFactory.create( consumerCreateArg ); ConsumedType providerProxy = (ConsumedType) Proxy.newProxyInstance( consumer.getClass().getClassLoader(), new Class[] { authenticationConsumerFactory.getConsumedType() }, new AuthenticationConsumerInvocationHandler( provider ) ); return consumer.consume( providerProxy ); }
@SuppressWarnings( "unchecked" ) @Test public void testNoAuthProviderAndConsumer() throws AuthenticationConsumptionException, AuthenticationFactoryException { manager.registerConsumerClass( DelegatingNoAuthConsumer.class ); AuthenticationConsumer<Object, NoAuthenticationAuthenticationProvider> consumer = mock( AuthenticationConsumer.class ); manager.getAuthenticationPerformer( Object.class, AuthenticationConsumer.class, NoAuthenticationAuthenticationProvider.NO_AUTH_ID ).perform( consumer ); verify( consumer ).consume( noAuthenticationAuthenticationProvider ); }
@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 ); }
@SuppressWarnings( "unchecked" ) @Test public void testKerberosProviderConsumer() throws AuthenticationConsumptionException, AuthenticationFactoryException { manager.registerConsumerClass( DelegatingNoAuthConsumer.class ); manager.registerConsumerClass( DelegatingUsernamePasswordConsumer.class ); manager.registerConsumerClass( DelegatingKerberosConsumer.class ); KerberosAuthenticationProvider kerberosAuthenticationProvider = new KerberosAuthenticationProvider( "kerb", "kerb", true, "pass", true, "none" ); manager.registerAuthenticationProvider( kerberosAuthenticationProvider ); AuthenticationConsumer<Object, KerberosAuthenticationProvider> consumer = mock( AuthenticationConsumer.class ); manager.getAuthenticationPerformer( Object.class, AuthenticationConsumer.class, kerberosAuthenticationProvider.getId() ).perform( consumer ); verify( consumer ).consume( kerberosAuthenticationProvider ); }
@SuppressWarnings( "unchecked" ) @Test public void testUsernamePasswordProviderConsumer() throws AuthenticationConsumptionException, AuthenticationFactoryException { manager.registerConsumerClass( DelegatingNoAuthConsumer.class ); manager.registerConsumerClass( DelegatingUsernamePasswordConsumer.class ); UsernamePasswordAuthenticationProvider usernamePasswordAuthenticationProvider = new UsernamePasswordAuthenticationProvider( "upass", "u", "pass" ); manager.registerAuthenticationProvider( usernamePasswordAuthenticationProvider ); AuthenticationConsumer<Object, UsernamePasswordAuthenticationProvider> consumer = mock( AuthenticationConsumer.class ); manager.getAuthenticationPerformer( Object.class, AuthenticationConsumer.class, usernamePasswordAuthenticationProvider.getId() ).perform( consumer ); verify( consumer ).consume( usernamePasswordAuthenticationProvider ); }
verify( consumer ).consume( captor.capture() ); assertEquals( kerberosAuthenticationProvider.getId(), captor.getValue().getId() ); assertEquals( kerberosAuthenticationProvider.getDisplayName(), captor.getValue().getDisplayName() );