| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
package org.ietf.ldap; |
| 39 |
|
| 40 |
import java.io.Serializable; |
| 41 |
import java.util.Enumeration; |
| 42 |
import java.util.Hashtable; |
| 43 |
import java.util.StringTokenizer; |
| 44 |
import java.util.Vector; |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
public abstract class LDAPSchemaElement implements Serializable { |
| 101 |
|
| 102 |
static final long serialVersionUID = -3972153461950418863L; |
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
protected LDAPSchemaElement() { |
| 108 |
} |
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
protected LDAPSchemaElement( String[] names, |
| 118 |
String oid, |
| 119 |
String description ) { |
| 120 |
if ( oid == null ) { |
| 121 |
throw new IllegalArgumentException( "OID required" ); |
| 122 |
} |
| 123 |
this.names = names; |
| 124 |
this.oid = oid; |
| 125 |
this.description = description; |
| 126 |
} |
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
public String getDescription() { |
| 135 |
return description; |
| 136 |
} |
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
public String getID() { |
| 145 |
return oid; |
| 146 |
} |
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
public String[] getNames() { |
| 154 |
return names; |
| 155 |
} |
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
public String[] getQualifier( String name ) { |
| 164 |
if ( properties == null ) { |
| 165 |
return null; |
| 166 |
} |
| 167 |
Object o = properties.get( name ); |
| 168 |
if ( o == null ) { |
| 169 |
return null; |
| 170 |
} |
| 171 |
if ( o instanceof Vector ) { |
| 172 |
Vector<String> v = (Vector<String>)o; |
| 173 |
String[] vals = new String[v.size()]; |
| 174 |
v.copyInto( vals ); |
| 175 |
return vals; |
| 176 |
} |
| 177 |
String s = (String)o; |
| 178 |
if ( s.length() < 1 ) { |
| 179 |
return new String[0]; |
| 180 |
} else { |
| 181 |
return new String[] { s }; |
| 182 |
} |
| 183 |
} |
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
public Enumeration<String> getQualifierNames() { |
| 190 |
return properties.keys(); |
| 191 |
} |
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
public boolean isObsolete() { |
| 198 |
return properties == null ? false : properties.containsKey(OBSOLETE); |
| 199 |
} |
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
public void setQualifier( String name, String value ) { |
| 208 |
if ( properties == null ) { |
| 209 |
properties = new Hashtable<String, Object>(); |
| 210 |
} |
| 211 |
if ( value != null ) { |
| 212 |
properties.put( name, value ); |
| 213 |
} else { |
| 214 |
properties.remove( name ); |
| 215 |
} |
| 216 |
} |
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
public void setQualifier( String name, String[] values ) { |
| 224 |
if ( values == null ) { |
| 225 |
return; |
| 226 |
} |
| 227 |
if ( properties == null ) { |
| 228 |
properties = new Hashtable<String, Object>(); |
| 229 |
} |
| 230 |
Vector<String> v = new Vector<>(); |
| 231 |
for( int i = 0; i < values.length; i++ ) { |
| 232 |
v.addElement( values[i] ); |
| 233 |
} |
| 234 |
properties.put( name, v ); |
| 235 |
} |
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
public abstract String toString(); |
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
protected void parseValue( String raw ) { |
| 253 |
names = null; |
| 254 |
if ( properties == null ) { |
| 255 |
properties = new Hashtable<String, Object>(); |
| 256 |
} |
| 257 |
int l = raw.length(); |
| 258 |
|
| 259 |
char[] ch = new char[l]; |
| 260 |
raw.getChars( 0, l, ch, 0 ); |
| 261 |
|
| 262 |
l--; |
| 263 |
while( ch[l] == ' ' ) { |
| 264 |
l--; |
| 265 |
} |
| 266 |
int start = 0; |
| 267 |
while( ch[start] == ' ' ) { |
| 268 |
start++; |
| 269 |
} |
| 270 |
|
| 271 |
start += 2; |
| 272 |
|
| 273 |
int ind = start + 1; |
| 274 |
while( ch[ind] != ' ' ) { |
| 275 |
ind++; |
| 276 |
} |
| 277 |
oid = new String( ch, start, ind - start ); |
| 278 |
|
| 279 |
ind = ind + 1; |
| 280 |
String s; |
| 281 |
String val; |
| 282 |
while ( ind < l ) { |
| 283 |
|
| 284 |
while( ch[ind] == ' ' ) { |
| 285 |
ind++; |
| 286 |
} |
| 287 |
|
| 288 |
int last = ind + 1; |
| 289 |
while( (last < l) && (ch[last] != ' ') ) |
| 290 |
last++; |
| 291 |
if ( last < l ) { |
| 292 |
|
| 293 |
s = new String( ch, ind, last-ind ); |
| 294 |
ind = last; |
| 295 |
if ( novalsTable.containsKey( s ) ) { |
| 296 |
properties.put( s, "" ); |
| 297 |
continue; |
| 298 |
} |
| 299 |
} else { |
| 300 |
|
| 301 |
s = ""; |
| 302 |
ind = l; |
| 303 |
break; |
| 304 |
} |
| 305 |
|
| 306 |
|
| 307 |
while( (ind < l) && (ch[ind] == ' ') ) { |
| 308 |
ind++; |
| 309 |
} |
| 310 |
last = ind + 1; |
| 311 |
if ( ind >= l ) { |
| 312 |
break; |
| 313 |
} |
| 314 |
|
| 315 |
boolean quoted = false; |
| 316 |
boolean list = false; |
| 317 |
if ( ch[ind] == '\'' ) { |
| 318 |
|
| 319 |
quoted = true; |
| 320 |
ind++; |
| 321 |
while( (last < l) && (ch[last] != '\'') ) { |
| 322 |
last++; |
| 323 |
} |
| 324 |
} else if ( ch[ind] == '(' ) { |
| 325 |
|
| 326 |
list = true; |
| 327 |
ind++; |
| 328 |
while( (last < l) && (ch[last] != ')') ) { |
| 329 |
last++; |
| 330 |
} |
| 331 |
} else { |
| 332 |
|
| 333 |
while( (last < l) && (ch[last] != ' ') ) { |
| 334 |
last++; |
| 335 |
} |
| 336 |
} |
| 337 |
if ( (ind < last) && (last <= l) ) { |
| 338 |
if ( list ) { |
| 339 |
Vector<String> v = new Vector<>(); |
| 340 |
if ( ch[ind] == ' ' ) { |
| 341 |
ind++; |
| 342 |
} |
| 343 |
val = new String( ch, ind, last-ind-1 ); |
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
String delim = (val.indexOf( '\'' ) >= 0) ? "'" : " "; |
| 351 |
StringTokenizer st = new StringTokenizer( val, delim ); |
| 352 |
while ( st.hasMoreTokens() ) { |
| 353 |
String tok = st.nextToken().trim(); |
| 354 |
if ( (tok.length() > 0) && !tok.equals( "$" ) ) { |
| 355 |
v.addElement( tok ); |
| 356 |
} |
| 357 |
} |
| 358 |
properties.put( s, v ); |
| 359 |
} else { |
| 360 |
val = new String( ch, ind, last-ind ); |
| 361 |
if ( s.equals( "NAME" ) ) { |
| 362 |
names = new String[] { val }; |
| 363 |
} else if ( s.equals( "DESC" ) ) { |
| 364 |
description = val; |
| 365 |
} else { |
| 366 |
properties.put( s, val ); |
| 367 |
} |
| 368 |
if ( quoted ) { |
| 369 |
last++; |
| 370 |
} |
| 371 |
} |
| 372 |
} |
| 373 |
ind = last + 1; |
| 374 |
} |
| 375 |
if ( names == null ) { |
| 376 |
names = getQualifier( "NAME" ); |
| 377 |
if ( names == null ) { |
| 378 |
names = new String[0]; |
| 379 |
} |
| 380 |
} |
| 381 |
} |
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
String getAttributeName() { |
| 389 |
return null; |
| 390 |
} |
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
String getValue() { |
| 410 |
return getValue( false ); |
| 411 |
} |
| 412 |
|
| 413 |
String getValue( boolean quotingBug ) { |
| 414 |
return null; |
| 415 |
} |
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
String getValuePrefix() { |
| 425 |
String s = "( " + oid + ' '; |
| 426 |
s += getNameField(); |
| 427 |
if ( description != null ) { |
| 428 |
s += "DESC \'" + description + "\' "; |
| 429 |
} |
| 430 |
if ( isObsolete() ) { |
| 431 |
s += OBSOLETE + ' '; |
| 432 |
} |
| 433 |
return s; |
| 434 |
} |
| 435 |
|
| 436 |
String getNameField() { |
| 437 |
String s = ""; |
| 438 |
if ( (names != null) && (names.length > 0) ) { |
| 439 |
s += "NAME "; |
| 440 |
if ( names.length > 1 ) { |
| 441 |
s += "( "; |
| 442 |
} |
| 443 |
for( int i = 0; i < names.length; i++ ) { |
| 444 |
s += '\'' + names[i] + "\' "; |
| 445 |
} |
| 446 |
if ( names.length > 1 ) { |
| 447 |
s += ") "; |
| 448 |
} |
| 449 |
} |
| 450 |
return s; |
| 451 |
} |
| 452 |
|
| 453 |
|
| 454 |
|
| 455 |
|
| 456 |
|
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
|
| 461 |
protected String getOptionalValues( String[] names ) { |
| 462 |
String s = ""; |
| 463 |
for( int i = 0; i < names.length; i++ ) { |
| 464 |
String[] vals = getQualifier( names[i] ); |
| 465 |
if ( (vals != null) && (vals.length > 0) ) { |
| 466 |
s += names[i] + ' ' + vals[0]; |
| 467 |
} |
| 468 |
} |
| 469 |
return s; |
| 470 |
} |
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
protected String getCustomValues() { |
| 479 |
String s = ""; |
| 480 |
Enumeration<String> en = properties.keys(); |
| 481 |
while( en.hasMoreElements() ) { |
| 482 |
String key = en.nextElement(); |
| 483 |
if ( !key.startsWith( "X-" ) ) { |
| 484 |
continue; |
| 485 |
} |
| 486 |
s += getValue( key, true, false ) + ' '; |
| 487 |
} |
| 488 |
|
| 489 |
if ( (s.length() > 0) && (s.charAt( s.length() - 1 ) == ' ') ) { |
| 490 |
s = s.substring( 0, s.length() - 1 ); |
| 491 |
} |
| 492 |
return s; |
| 493 |
} |
| 494 |
|
| 495 |
|
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
|
| 505 |
|
| 506 |
|
| 507 |
String getValue( String key, boolean doQuote, boolean doDollar ) { |
| 508 |
String s = ""; |
| 509 |
Object o = properties.get( key ); |
| 510 |
if ( o == null ) { |
| 511 |
return s; |
| 512 |
} |
| 513 |
if ( o instanceof String ) { |
| 514 |
if ( ((String)o).length() > 0 ) { |
| 515 |
s += key + ' '; |
| 516 |
if ( doQuote ) { |
| 517 |
s += '\''; |
| 518 |
} |
| 519 |
s += (String)o; |
| 520 |
if ( doQuote ) { |
| 521 |
s += '\''; |
| 522 |
} |
| 523 |
} |
| 524 |
} else { |
| 525 |
s += key + " ( "; |
| 526 |
Vector<String> v = (Vector<String>)o; |
| 527 |
for( int i = 0; i < v.size(); i++ ) { |
| 528 |
if ( doQuote ) { |
| 529 |
s += '\''; |
| 530 |
} |
| 531 |
s += v.elementAt(i); |
| 532 |
if ( doQuote ) { |
| 533 |
s += '\''; |
| 534 |
} |
| 535 |
s += ' '; |
| 536 |
if ( doDollar && (i < (v.size() - 1)) ) { |
| 537 |
s += "$ "; |
| 538 |
} |
| 539 |
} |
| 540 |
s += ')'; |
| 541 |
} |
| 542 |
|
| 543 |
return s; |
| 544 |
} |
| 545 |
|
| 546 |
|
| 547 |
|
| 548 |
|
| 549 |
|
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
String getValue( String key, boolean doQuote ) { |
| 557 |
return getValue( key, doQuote, true ); |
| 558 |
} |
| 559 |
|
| 560 |
|
| 561 |
|
| 562 |
|
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
String getQualifierString( String[] ignore ) { |
| 567 |
Hashtable<String, Object> toIgnore = null; |
| 568 |
if ( ignore != null ) { |
| 569 |
toIgnore = new Hashtable<>(); |
| 570 |
for( int i = 0; i < ignore.length; i++ ) { |
| 571 |
toIgnore.put( ignore[i], ignore[i] ); |
| 572 |
} |
| 573 |
} |
| 574 |
String s = ""; |
| 575 |
Enumeration<String> en = getQualifierNames(); |
| 576 |
while( en.hasMoreElements() ) { |
| 577 |
String qualifier = en.nextElement(); |
| 578 |
if ( (toIgnore != null) && toIgnore.containsKey( qualifier ) ) { |
| 579 |
continue; |
| 580 |
} |
| 581 |
s += "; " + qualifier; |
| 582 |
String[] vals = getQualifier( qualifier ); |
| 583 |
if ( vals == null ) { |
| 584 |
s += ' '; |
| 585 |
continue; |
| 586 |
} |
| 587 |
s += ": "; |
| 588 |
for( int i = 0; i < vals.length; i++ ) { |
| 589 |
s += vals[i] + ' '; |
| 590 |
} |
| 591 |
} |
| 592 |
|
| 593 |
if ( (s.length() > 0) && (s.charAt( s.length() - 1 ) == ' ') ) { |
| 594 |
s = s.substring( 0, s.length() - 1 ); |
| 595 |
} |
| 596 |
return s; |
| 597 |
} |
| 598 |
|
| 599 |
|
| 600 |
public static final int unknown = 0; |
| 601 |
public static final int cis = 1; |
| 602 |
public static final int binary = 2; |
| 603 |
public static final int telephone = 3; |
| 604 |
public static final int ces = 4; |
| 605 |
public static final int dn = 5; |
| 606 |
public static final int integer = 6; |
| 607 |
|
| 608 |
protected static final String cisString = |
| 609 |
"1.3.6.1.4.1.1466.115.121.1.15"; |
| 610 |
protected static final String binaryString = |
| 611 |
"1.3.6.1.4.1.1466.115.121.1.5"; |
| 612 |
protected static final String telephoneString = |
| 613 |
"1.3.6.1.4.1.1466.115.121.1.50"; |
| 614 |
protected static final String cesString = |
| 615 |
"1.3.6.1.4.1.1466.115.121.1.26"; |
| 616 |
protected static final String intString = |
| 617 |
"1.3.6.1.4.1.1466.115.121.1.27"; |
| 618 |
protected static final String dnString = |
| 619 |
"1.3.6.1.4.1.1466.115.121.1.12"; |
| 620 |
|
| 621 |
public static final String OBSOLETE = "OBSOLETE"; |
| 622 |
public static final String SUPERIOR = "SUP"; |
| 623 |
|
| 624 |
|
| 625 |
public static final String SYNTAX = "SYNTAX"; |
| 626 |
|
| 627 |
|
| 628 |
protected String oid = null; |
| 629 |
protected String description = ""; |
| 630 |
protected String attrName = null; |
| 631 |
protected String rawValue = null; |
| 632 |
protected String[] names = new String[0]; |
| 633 |
|
| 634 |
protected Hashtable<String, Object> properties = null; |
| 635 |
|
| 636 |
static protected Hashtable<String, String> novalsTable = new Hashtable<>(); |
| 637 |
} |