1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.directory.ldap.client.api;
21
22
23 import org.apache.directory.api.asn1.DecoderException;
24 import org.apache.directory.api.asn1.util.Oid;
25 import org.apache.directory.api.ldap.extras.extended.startTls.StartTlsRequest;
26 import org.apache.directory.api.ldap.model.exception.LdapException;
27 import org.apache.directory.api.ldap.model.message.BindRequest;
28 import org.apache.directory.api.ldap.model.message.BindResponse;
29 import org.apache.directory.api.ldap.model.message.ExtendedRequest;
30 import org.apache.directory.api.ldap.model.message.ExtendedResponse;
31 import org.apache.directory.api.ldap.model.name.Dn;
32
33
34
35
36
37
38
39
40 public final class MonitoringLdapConnection extends LdapConnectionWrapper
41 {
42 private static final Oid START_TLS_OID;
43
44 static
45 {
46 try
47 {
48 START_TLS_OID = Oid.fromString( StartTlsRequest.EXTENSION_OID );
49 }
50 catch ( DecoderException e )
51 {
52 throw new IllegalStateException( "StartTlsRequest.EXTENSION_OID is not a valid oid... This cant happen" );
53 }
54 }
55
56 private boolean bindCalled = false;
57 private boolean startTlsCalled = false;
58
59
60 MonitoringLdapConnection( LdapConnection connection )
61 {
62 super( connection );
63 }
64
65
66 public boolean bindCalled()
67 {
68 return bindCalled;
69 }
70
71
72 public void resetMonitors()
73 {
74 bindCalled = false;
75 startTlsCalled = false;
76 }
77
78
79 public boolean startTlsCalled()
80 {
81 return startTlsCalled;
82 }
83
84
85 @Override
86 public void bind() throws LdapException
87 {
88 connection.bind();
89 bindCalled = true;
90 }
91
92
93 @Override
94 public void anonymousBind() throws LdapException
95 {
96 connection.anonymousBind();
97 bindCalled = true;
98 }
99
100
101 @Override
102 public void bind( String name ) throws LdapException
103 {
104 connection.bind( name );
105 bindCalled = true;
106 }
107
108
109 @Override
110 public void bind( String name, String credentials ) throws LdapException
111 {
112 connection.bind( name, credentials );
113 bindCalled = true;
114 }
115
116
117 @Override
118 public void bind( Dn name ) throws LdapException
119 {
120 connection.bind( name );
121 bindCalled = true;
122 }
123
124
125 @Override
126 public void bind( Dn name, String credentials ) throws LdapException
127 {
128 connection.bind( name, credentials );
129 bindCalled = true;
130 }
131
132
133 @Override
134 public BindResponse bind( BindRequest bindRequest ) throws LdapException
135 {
136 BindResponse response = connection.bind( bindRequest );
137 bindCalled = true;
138 return response;
139 }
140
141
142 @Override
143 public ExtendedResponse extended( String oid ) throws LdapException
144 {
145 if ( StartTlsRequest.EXTENSION_OID.equals( oid ) )
146 {
147 startTlsCalled = true;
148 }
149 return connection.extended( oid );
150 }
151
152
153 @Override
154 public ExtendedResponse extended( String oid, byte[] value ) throws LdapException
155 {
156 if ( StartTlsRequest.EXTENSION_OID.equals( oid ) )
157 {
158 startTlsCalled = true;
159 }
160 return connection.extended( oid, value );
161 }
162
163
164 @Override
165 public ExtendedResponse extended( Oid oid ) throws LdapException
166 {
167 if ( START_TLS_OID.equals( oid ) )
168 {
169 startTlsCalled = true;
170 }
171 return connection.extended( oid );
172 }
173
174
175 @Override
176 public ExtendedResponse extended( Oid oid, byte[] value ) throws LdapException
177 {
178 if ( START_TLS_OID.equals( oid ) )
179 {
180 startTlsCalled = true;
181 }
182 return connection.extended( oid, value );
183 }
184
185
186 @Override
187 public ExtendedResponse extended( ExtendedRequest extendedRequest ) throws LdapException
188 {
189 if ( extendedRequest.hasControl( StartTlsRequest.EXTENSION_OID ) )
190 {
191 startTlsCalled = true;
192 }
193 return connection.extended( extendedRequest );
194 }
195 }