| | |
| | | private final LDAPConnectionFactory connectionFactory; |
| | | private final Connection connection; |
| | | private final InitialLdapContext ldapContext; |
| | | private final HostPort hostPort; |
| | | private final int connectTimeout; |
| | | private final TrustManager trustManager; |
| | | private final KeyManager keyManager; |
| | |
| | | public ConnectionWrapper(HostPort hostPort, PreferredConnection.Type connectionType, String bindDn, String bindPwd, |
| | | int connectTimeout, TrustManager trustManager, KeyManager keyManager) throws NamingException |
| | | { |
| | | this.hostPort = hostPort; |
| | | this.connectTimeout = connectTimeout; |
| | | this.trustManager = trustManager; |
| | | this.keyManager = keyManager; |
| | | |
| | | final Options options = toOptions(connectionType, bindDn, bindPwd, connectTimeout, trustManager, keyManager); |
| | | ldapContext = createAdministrativeContext(hostPort, options); |
| | | connectionFactory = buildConnectionFactory(options, hostPort); |
| | | ldapContext = createAdministrativeContext(options); |
| | | connectionFactory = new LDAPConnectionFactory(hostPort.getHost(), hostPort.getPort(), options); |
| | | connection = buildConnection(); |
| | | } |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | private InitialLdapContext createAdministrativeContext(HostPort hostPort, Options options) throws NamingException |
| | | private InitialLdapContext createAdministrativeContext(Options options) throws NamingException |
| | | { |
| | | final InitialLdapContext ctx = createAdministrativeContext0(hostPort, options); |
| | | final InitialLdapContext ctx = createAdministrativeContext0(options); |
| | | if (!connectedAsAdministrativeUser(ctx)) |
| | | { |
| | | throw new NoPermissionException(ERR_NOT_ADMINISTRATIVE_USER.get().toString()); |
| | |
| | | return ctx; |
| | | } |
| | | |
| | | private InitialLdapContext createAdministrativeContext0(HostPort hostPort, Options options) throws NamingException |
| | | private InitialLdapContext createAdministrativeContext0(Options options) throws NamingException |
| | | { |
| | | SSLContext sslContext = options.get(SSL_CONTEXT); |
| | | boolean useSSL = sslContext != null; |
| | |
| | | SimpleBindRequest bindRequest = (SimpleBindRequest) options.get(AUTHN_BIND_REQUEST); |
| | | String bindDn = bindRequest.getName(); |
| | | String bindPwd = new String(bindRequest.getPassword()); |
| | | final String ldapUrl = getLDAPUrl(hostPort, useSSL); |
| | | final String ldapUrl = getLDAPUrl(getHostPort(), useSSL); |
| | | if (useSSL) |
| | | { |
| | | return createLdapsContext(ldapUrl, bindDn, bindPwd, connectTimeout, null, trustManager, keyManager); |
| | |
| | | } |
| | | } |
| | | |
| | | private LDAPConnectionFactory buildConnectionFactory(Options options, HostPort hostPort) |
| | | { |
| | | return new LDAPConnectionFactory(hostPort.getHost(), hostPort.getPort(), options); |
| | | } |
| | | |
| | | private Connection buildConnection() throws NamingException |
| | | { |
| | | try |
| | |
| | | } |
| | | |
| | | /** |
| | | * Returns the host name and port number of this connection. |
| | | * |
| | | * @return the hostPort of this connection |
| | | */ |
| | | public HostPort getHostPort() |
| | | { |
| | | return hostPort; |
| | | } |
| | | |
| | | /** |
| | | * Returns the root configuration client by using the inrnal Connection. |
| | | * |
| | | * @return the root configuration client |