@@ -120,6 +120,11 @@ public class DefaultAttributeValidationPolicy implements AttributeValidationPoli
120
120
121
121
private static final String BASE64_STRING = "(" + BASE64_CHAR + "*)" ;
122
122
123
+ //UTF8 Definitions
124
+ private static final String UTF8_CHAR = "[\\ p{L}|[0-9]|\\ s]" ; // \p{L} for any kind of letter from any language, including spaces and digits
125
+
126
+ private static final String UTF8_STRING = "(" + UTF8_CHAR + "+)" ;
127
+
123
128
//URL Components
124
129
private static final String USER = "[" + UCHAR + "\\ x3B\\ x3F\\ x26\\ x3D]*" ; //UCHAR|;|?|&|=
125
130
@@ -242,13 +247,17 @@ public class DefaultAttributeValidationPolicy implements AttributeValidationPoli
242
247
243
248
private static final String URL_ATTRIBUTE_EXPRESSION = "^" + ATTRIBUTE_DESCRIPTION + ATTRIBUTE_SEPARATOR + URL_INDICATOR + FILL + URL + "$" ; //URL
244
249
250
+ private static final String UTF8_ATTRIBUTE_EXPRESSION = "^" + ATTRIBUTE_DESCRIPTION + ATTRIBUTE_SEPARATOR + FILL + UTF8_STRING ;
251
+
245
252
//Pattern Declarations
246
253
private static final Pattern ATTRIBUTE_PATTERN = Pattern .compile (ATTRIBUTE_EXPRESSION );
247
254
248
255
private static final Pattern BASE64_ATTRIBUTE_PATTERN = Pattern .compile (BASE64_ATTRIBUTE_EXPRESSION );
249
256
250
257
private static final Pattern URL_ATTRIBUTE_PATTERN = Pattern .compile (URL_ATTRIBUTE_EXPRESSION );
251
-
258
+
259
+ private static final Pattern UTF8_ATTRIBUTE_PATTERN = Pattern .compile (UTF8_ATTRIBUTE_EXPRESSION );
260
+
252
261
private boolean ordered = false ;
253
262
254
263
/**
@@ -279,11 +288,12 @@ public void setOrdered(boolean ordered) {
279
288
/**
280
289
* Validates attribute contained in the buffer and returns an LdapAttribute.
281
290
* <p>
282
- * Ensures attributes meets one of three prescribed patterns for valid attributes:
291
+ * Ensures attributes meets one of four prescribed patterns for valid attributes:
283
292
* <ol>
284
293
* <li>A standard attribute pattern of the form: ATTR_ID[;options]: VALUE</li>
285
294
* <li>A Base64 attribute pattern of the form: ATTR_ID[;options]:: BASE64_VALUE</li>
286
295
* <li>A url attribute pattern of the form: ATTR_ID[;options]:< URL_VALUE</li>
296
+ * <li>A UTF8 attribute pattern of the form: ATTR_ID[;options]: UTF8_VALUE</li>
287
297
* </ol>
288
298
* <p>
289
299
* Upon success an LdapAttribute object is returned.
@@ -314,6 +324,12 @@ public Attribute parse(String buffer) {
314
324
return parseUrlAttribute (matcher );
315
325
}
316
326
327
+ matcher = UTF8_ATTRIBUTE_PATTERN .matcher (buffer );
328
+ if (matcher .matches ()) {
329
+ //Is a UTF8 attribute...
330
+ return parseUtf8Attribute (matcher );
331
+ }
332
+
317
333
//default: no match.
318
334
throw new InvalidAttributeFormatException ("Not a valid attribute: [" + buffer + "]" );
319
335
}
@@ -363,5 +379,16 @@ private LdapAttribute parseUrlAttribute(Matcher matcher) {
363
379
throw new InvalidAttributeFormatException (e );
364
380
}
365
381
}
366
-
382
+
383
+ private LdapAttribute parseUtf8Attribute (Matcher matcher ) {
384
+ String id = matcher .group (1 );
385
+ String value = matcher .group (3 );
386
+ List <String > options = Arrays .asList ((!StringUtils .hasLength (matcher .group (2 )) ? new String [] {} : matcher .group (2 ).replaceFirst (";" ,"" ).split (OPTION_SEPARATOR )));
387
+
388
+ if (options .isEmpty ()) {
389
+ return new LdapAttribute (id , value , ordered );
390
+ } else {
391
+ return new LdapAttribute (id , value , options , ordered );
392
+ }
393
+ }
367
394
}
0 commit comments