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 public final class MonitoringLdapConnection extends LdapConnectionWrapper
40 {
41 private static final Oid START_TLS_OID;
42
43 static
44 {
45 try
46 {
47 START_TLS_OID = Oid.fromString( StartTlsRequest.EXTENSION_OID );
48 }
49 catch ( DecoderException de )
50 {
51 throw new IllegalStateException( "StartTlsRequest.EXTENSION_OID is not a valid oid... This cant happen", de );
52 }
53 }
54
55 private boolean bindCalled = false;
56 private boolean startTlsCalled = false;
57
58
59 MonitoringLdapConnection( LdapConnection connection )
60 {
61 super( connection );
62 }
63
64
65
66
67
68 public boolean bindCalled()
69 {
70 return bindCalled;
71 }
72
73
74
75
76
77 public void resetMonitors()
78 {
79 bindCalled = false;
80 startTlsCalled = false;
81 }
82
83
84
85
86
87 public boolean startTlsCalled()
88 {
89 return startTlsCalled;
90 }
91
92
93 @Override
94 public void bind() throws LdapException
95 {
96 connection.bind();
97 bindCalled = true;
98 }
99
100
101 @Override
102 public void anonymousBind() throws LdapException
103 {
104 connection.anonymousBind();
105 bindCalled = true;
106 }
107
108
109 @Override
110 public void bind( String name ) throws LdapException
111 {
112 connection.bind( name );
113 bindCalled = true;
114 }
115
116
117 @Override
118 public void bind( String name, String credentials ) throws LdapException
119 {
120 connection.bind( name, credentials );
121 bindCalled = true;
122 }
123
124
125 @Override
126 public void bind( Dn name ) throws LdapException
127 {
128 connection.bind( name );
129 bindCalled = true;
130 }
131
132
133 @Override
134 public void bind( Dn name, String credentials ) throws LdapException
135 {
136 connection.bind( name, credentials );
137 bindCalled = true;
138 }
139
140
141 @Override
142 public BindResponse bind( BindRequest bindRequest ) throws LdapException
143 {
144 BindResponse response = connection.bind( bindRequest );
145 bindCalled = true;
146 return response;
147 }
148
149
150 @Override
151 public ExtendedResponse extended( String oid ) throws LdapException
152 {
153 if ( StartTlsRequest.EXTENSION_OID.equals( oid ) )
154 {
155 startTlsCalled = true;
156 }
157 return connection.extended( oid );
158 }
159
160
161 @Override
162 public ExtendedResponse extended( String oid, byte[] value ) throws LdapException
163 {
164 if ( StartTlsRequest.EXTENSION_OID.equals( oid ) )
165 {
166 startTlsCalled = true;
167 }
168 return connection.extended( oid, value );
169 }
170
171
172 @Override
173 public ExtendedResponse extended( Oid oid ) throws LdapException
174 {
175 if ( START_TLS_OID.equals( oid ) )
176 {
177 startTlsCalled = true;
178 }
179 return connection.extended( oid );
180 }
181
182
183 @Override
184 public ExtendedResponse extended( Oid oid, byte[] value ) throws LdapException
185 {
186 if ( START_TLS_OID.equals( oid ) )
187 {
188 startTlsCalled = true;
189 }
190 return connection.extended( oid, value );
191 }
192
193
194 @Override
195 public ExtendedResponse extended( ExtendedRequest extendedRequest ) throws LdapException
196 {
197 if ( extendedRequest.hasControl( StartTlsRequest.EXTENSION_OID ) )
198 {
199 startTlsCalled = true;
200 }
201 return connection.extended( extendedRequest );
202 }
203 }