1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.directory.ldap.client.api;
22
23
24 import java.util.ArrayList;
25 import java.util.Arrays;
26 import java.util.List;
27
28 import org.apache.directory.api.ldap.model.constants.SaslQoP;
29 import org.apache.directory.api.ldap.model.constants.SaslSecurityStrength;
30 import org.apache.directory.api.ldap.model.message.Control;
31 import org.apache.directory.api.util.Strings;
32
33
34
35
36
37
38
39 public abstract class AbstractSaslRequest implements SaslRequest
40 {
41
42 protected String saslMechanism;
43
44
45 protected List<Control> controls = new ArrayList<>();
46
47
48 protected String username;
49
50
51 protected byte[] credentials;
52
53
54 protected String realmName;
55
56
57 protected String authorizationId;
58
59
60 protected SaslQoP qualityOfProtection;
61
62
63 protected SaslSecurityStrength securityStrength;
64
65
66 protected boolean mutualAuthentication = false;
67
68
69
70
71
72
73
74 protected AbstractSaslRequest( String saslMechanism )
75 {
76 this.saslMechanism = saslMechanism;
77 }
78
79
80
81
82
83
84
85 public void addAllControls( Control[] controls )
86 {
87 this.controls.addAll( Arrays.asList( controls ) );
88 }
89
90
91
92
93
94
95
96 public void addControl( Control control )
97 {
98 this.controls.add( control );
99 }
100
101
102
103
104
105 @Override
106 public String getAuthorizationId()
107 {
108 return authorizationId;
109 }
110
111
112
113
114
115 @Override
116 public Control[] getControls()
117 {
118 return controls.toArray( new Control[0] );
119 }
120
121
122
123
124
125 @Override
126 public byte[] getCredentials()
127 {
128 if ( credentials != null )
129 {
130 return credentials;
131 }
132 else
133 {
134 return Strings.EMPTY_BYTES;
135 }
136 }
137
138
139
140
141
142 @Override
143 public SaslQoP getQualityOfProtection()
144 {
145 return qualityOfProtection;
146 }
147
148
149
150
151
152 @Override
153 public String getRealmName()
154 {
155 return realmName;
156 }
157
158
159
160
161
162 @Override
163 public String getSaslMechanism()
164 {
165 return saslMechanism;
166 }
167
168
169
170
171
172 @Override
173 public SaslSecurityStrength getSecurityStrength()
174 {
175 return securityStrength;
176 }
177
178
179
180
181
182 @Override
183 public String getUsername()
184 {
185 return username;
186 }
187
188
189
190
191
192 @Override
193 public boolean isMutualAuthentication()
194 {
195 return mutualAuthentication;
196 }
197
198
199
200
201
202
203
204 public void setAuthorizationId( String authorizationId )
205 {
206 this.authorizationId = authorizationId;
207 }
208
209
210
211
212
213
214
215 public void setCredentials( byte[] credentials )
216 {
217 this.credentials = credentials;
218 }
219
220
221
222
223
224
225
226 public void setCredentials( String credentials )
227 {
228 this.credentials = Strings.getBytesUtf8( credentials );
229 }
230
231
232
233
234
235
236
237 public void setMutualAuthentication( boolean mutualAuthentication )
238 {
239 this.mutualAuthentication = mutualAuthentication;
240 }
241
242
243
244
245
246
247
248 public void setQualityOfProtection( SaslQoP qualityOfProtection )
249 {
250 this.qualityOfProtection = qualityOfProtection;
251 }
252
253
254
255
256
257
258
259 protected void setRealmName( String realmName )
260 {
261 this.realmName = realmName;
262 }
263
264
265
266
267
268
269
270 protected void setSaslMechanism( String saslMechanism )
271 {
272 this.saslMechanism = saslMechanism;
273 }
274
275
276
277
278
279
280
281 public void setSecurityStrength( SaslSecurityStrength securityStrength )
282 {
283 this.securityStrength = securityStrength;
284 }
285
286
287
288
289
290
291
292 public void setUsername( String username )
293 {
294 this.username = username;
295 }
296 }