Authenticator { public void close() { if (dnResolver instanceof ConnectionFactoryManager) { closeConnectionFactoryManagers((ConnectionFactoryManager) dnResolver); } else if (dnResolver instanceof AggregateDnResolver) { final Map<String, DnResolver> resolvers = ((AggregateDnResolver) dnResolver).getDnResolvers(); if (resolvers != null) { closeConnectionFactoryManagers(resolvers.values().toArray(new ConnectionFactoryManager[0])); } } if (authenticationHandler instanceof ConnectionFactoryManager) { closeConnectionFactoryManagers((ConnectionFactoryManager) authenticationHandler); } else if (authenticationHandler instanceof AggregateAuthenticationHandler) { final Map<String, AuthenticationHandler> handlers = ((AggregateAuthenticationHandler) authenticationHandler).getAuthenticationHandlers(); if (handlers != null) { closeConnectionFactoryManagers(handlers.values().toArray(new ConnectionFactoryManager[0])); } } if (entryResolver instanceof ConnectionFactoryManager) { closeConnectionFactoryManagers((ConnectionFactoryManager) entryResolver); } else if (entryResolver instanceof AggregateEntryResolver) { final Map<String, EntryResolver> resolvers = ((AggregateEntryResolver) entryResolver).getEntryResolvers(); if (resolvers != null) { closeConnectionFactoryManagers(resolvers.values().toArray(new ConnectionFactoryManager[0])); } } } Authenticator();  Authenticator(final DnResolver resolver, final AuthenticationHandler handler); DnResolver getDnResolver(); void setDnResolver(final DnResolver resolver); AuthenticationHandler getAuthenticationHandler(); void setAuthenticationHandler(final AuthenticationHandler handler); EntryResolver getEntryResolver(); void setEntryResolver(final EntryResolver resolver); boolean getResolveEntryOnFailure(); void setResolveEntryOnFailure(final boolean b); String[] getReturnAttributes(); void setReturnAttributes(final String... attrs); AuthenticationRequestHandler[] getRequestHandlers(); void setRequestHandlers(final AuthenticationRequestHandler... handlers); AuthenticationResponseHandler[] getResponseHandlers(); void setResponseHandlers(final AuthenticationResponseHandler... handlers); String resolveDn(final User user); AuthenticationResponse authenticate(final AuthenticationRequest request); void close(); @Override String toString(); static Builder builder();  }
@Test(groups = "auth") public void close() { final Authenticator auth = new Authenticator(); auth.setDnResolver(new SearchDnResolver(new MockConnectionFactory(new ConnectionConfig()))); auth.setAuthenticationHandler( new SimpleBindAuthenticationHandler(new MockConnectionFactory(new ConnectionConfig()))); auth.setEntryResolver(new SearchEntryResolver(new MockConnectionFactory(new ConnectionConfig()))); auth.close(); Assert.assertFalse( ((MockConnectionFactory) ((SearchDnResolver) auth.getDnResolver()).getConnectionFactory()).isOpen()); Assert.assertFalse( ((MockConnectionFactory) ((SimpleBindAuthenticationHandler) auth.getAuthenticationHandler()).getConnectionFactory()).isOpen()); Assert.assertFalse( ((MockConnectionFactory) ((SearchEntryResolver) auth.getEntryResolver()).getConnectionFactory()).isOpen()); }