summaryrefslogtreecommitdiffstats
path: root/base/common/src/com/netscape/cmscore/ldapconn/LdapAnonConnection.java
blob: 4be6bc33bbc2f7badbdaca4ed98b23ab96c78b5e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// --- BEGIN COPYRIGHT BLOCK ---
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; version 2 of the License.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
//
// (C) 2007 Red Hat, Inc.
// All rights reserved.
// --- END COPYRIGHT BLOCK ---
package com.netscape.cmscore.ldapconn;


import netscape.ldap.*;
import com.netscape.certsrv.ldap.*;


/**
 * A LDAP connection that is bound to a server host, port and secure type.
 * Makes a LDAP connection when instantiated.
 * Cannot establish another LDAP connection after construction. 
 * LDAPConnection connect methods are overridden to prevent this.
 */
public class LdapAnonConnection extends LDAPConnection {

    /**
     * instantiates a connection to a ldap server
     */
    public LdapAnonConnection(LdapConnInfo connInfo)
        throws LDAPException {
        super(connInfo.getSecure() ? new LdapJssSSLSocketFactory() : null);

        // Set option to automatically follow referrals. 
        // rebind info is also anonymous.
        boolean followReferrals = connInfo.getFollowReferrals();

        setOption(LDAPv2.REFERRALS, new Boolean(followReferrals));

        super.connect(connInfo.getVersion(), 
            connInfo.getHost(), connInfo.getPort(), null, null);
    }

    /**
     * instantiates a connection to a ldap server
     */
    public LdapAnonConnection(String host, int port, int version, 
        LDAPSocketFactory fac)
        throws LDAPException {
        super(fac);
        super.connect(version, host, port, null, null);
    }

    /**
     * instantiates a non-secure connection to a ldap server
     */
    public LdapAnonConnection(String host, int port, int version)
        throws LDAPException {
        super();
        super.connect(version, host, port, null, null);
    }

    /**
     * overrides superclass connect. 
     * does not allow reconnect.
     */
    public void connect(String host, int port) throws LDAPException {
        throw new RuntimeException(
                "this LdapAnonConnection already connected: connect(h,p)");
    }

    /**
     * overrides superclass connect.
     * does not allow reconnect.
     */
    public void connect(int version, String host, int port, 
        String dn, String pw) throws LDAPException {
        throw new RuntimeException(
                "this LdapAnonConnection already connected: connect(v,h,p)");
    }
}