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.i18n.I18n;
26 import org.apache.directory.api.ldap.extras.extended.startTls.StartTlsRequest;
27 import org.apache.directory.api.ldap.model.exception.LdapException;
28 import org.apache.directory.api.ldap.model.message.BindRequest;
29 import org.apache.directory.api.ldap.model.message.BindResponse;
30 import org.apache.directory.api.ldap.model.message.ExtendedRequest;
31 import org.apache.directory.api.ldap.model.message.ExtendedResponse;
32 import org.apache.directory.api.ldap.model.name.Dn;
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 de )
51 {
52 throw new IllegalStateException( I18n.err( I18n.ERR_04161_START_TLS_EXT_NOT_VALID_OID ), de );
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
67
68
69 public boolean bindCalled()
70 {
71 return bindCalled;
72 }
73
74
75
76
77
78 public void resetMonitors()
79 {
80 bindCalled = false;
81 startTlsCalled = false;
82 }
83
84
85
86
87
88 public boolean startTlsCalled()
89 {
90 return startTlsCalled;
91 }
92
93
94
95
96
97 @Override
98 public void bind() throws LdapException
99 {
100 connection.bind();
101 bindCalled = true;
102 }
103
104
105
106
107
108 @Override
109 public void anonymousBind() throws LdapException
110 {
111 connection.anonymousBind();
112 bindCalled = true;
113 }
114
115
116
117
118
119 @Override
120 public void bind( String name ) throws LdapException
121 {
122 connection.bind( name );
123 bindCalled = true;
124 }
125
126
127
128
129
130 @Override
131 public void bind( String name, String credentials ) throws LdapException
132 {
133 connection.bind( name, credentials );
134 bindCalled = true;
135 }
136
137
138
139
140
141 @Override
142 public void bind( Dn name ) throws LdapException
143 {
144 connection.bind( name );
145 bindCalled = true;
146 }
147
148
149
150
151
152 @Override
153 public void bind( Dn name, String credentials ) throws LdapException
154 {
155 connection.bind( name, credentials );
156 bindCalled = true;
157 }
158
159
160
161
162
163 @Override
164 public BindResponse bind( BindRequest bindRequest ) throws LdapException
165 {
166 BindResponse response = connection.bind( bindRequest );
167 bindCalled = true;
168 return response;
169 }
170
171
172
173
174
175 @Override
176 public ExtendedResponse extended( String oid ) throws LdapException
177 {
178 if ( StartTlsRequest.EXTENSION_OID.equals( oid ) )
179 {
180 startTlsCalled = true;
181 }
182 return connection.extended( oid );
183 }
184
185
186
187
188
189 @Override
190 public ExtendedResponse extended( String oid, byte[] value ) throws LdapException
191 {
192 if ( StartTlsRequest.EXTENSION_OID.equals( oid ) )
193 {
194 startTlsCalled = true;
195 }
196 return connection.extended( oid, value );
197 }
198
199
200
201
202
203 @Override
204 public ExtendedResponse extended( Oid oid ) throws LdapException
205 {
206 if ( START_TLS_OID.equals( oid ) )
207 {
208 startTlsCalled = true;
209 }
210 return connection.extended( oid );
211 }
212
213
214
215
216
217 @Override
218 public ExtendedResponse extended( Oid oid, byte[] value ) throws LdapException
219 {
220 if ( START_TLS_OID.equals( oid ) )
221 {
222 startTlsCalled = true;
223 }
224 return connection.extended( oid, value );
225 }
226
227
228
229
230
231 @Override
232 public ExtendedResponse extended( ExtendedRequest extendedRequest ) throws LdapException
233 {
234 if ( extendedRequest.hasControl( StartTlsRequest.EXTENSION_OID ) )
235 {
236 startTlsCalled = true;
237 }
238 return connection.extended( extendedRequest );
239 }
240 }