1 16 package com.sun.slamd.example; 17 18 19 20 import java.io.*; 21 import java.security.*; 22 import java.util.*; 23 import netscape.ldap.*; 24 import netscape.ldap.factory.*; 25 import com.sun.slamd.job.*; 26 import com.sun.slamd.parameter.*; 27 import com.sun.slamd.stat.*; 28 29 30 31 61 public class SiteMinderJobClass 62 extends JobClass 63 { 64 68 public static final char[] ALPHABET = 69 "abcdefghijklmnopqrstuvwxyz".toCharArray(); 70 71 72 73 77 public static final String DEFAULT_ATTR1 = "givenName"; 78 79 80 81 85 public static final String DEFAULT_ATTR2 = "sn"; 86 87 88 89 93 public static final String DEFAULT_ATTR3= "cn"; 94 95 96 97 100 public static final String DEFAULT_LOG_ID_ATTR = "uid"; 101 102 103 104 107 public static final String SSL_KEY_STORE_PROPERTY = 108 "javax.net.ssl.keyStore"; 109 110 111 112 115 public static final String SSL_KEY_PASSWORD_PROPERTY = 116 "javax.net.ssl.keyStorePassword"; 117 118 119 120 123 public static final String SSL_TRUST_STORE_PROPERTY = 124 "javax.net.ssl.trustStore"; 125 126 127 128 131 public static final String SSL_TRUST_PASSWORD_PROPERTY = 132 "javax.net.ssl.trustStorePassword"; 133 134 135 136 140 public static final String STAT_TRACKER_AUTHENTICATION_ATTEMPTS = 141 "Authentication Attempts"; 142 143 144 145 146 150 public static final String STAT_TRACKER_AUTHENTICATION_TIME = 151 "Authentication Time (ms)"; 152 153 154 155 159 public static final String STAT_TRACKER_BIND_TIME = "Bind Time (ms)"; 160 161 162 163 164 168 public static final String STAT_TRACKER_FAILED_AUTHENTICATIONS = 169 "Failed Authentications"; 170 171 172 173 177 public static final String STAT_TRACKER_FAIL_REASON = "Failure Reason"; 178 179 180 181 185 public static final String STAT_TRACKER_INITIAL_SEARCH_TIME = 186 "Initial Search Time (ms)"; 187 188 189 190 194 public static final String STAT_TRACKER_MOD_TIME = "Modify Time (ms)"; 195 196 197 198 202 public static final String STAT_TRACKER_NUM_BINDS = 203 "Bind Operations Performed"; 204 205 206 207 211 public static final String STAT_TRACKER_NUM_MODS = 212 "Modify Operations Performed"; 213 214 215 216 220 public static final String STAT_TRACKER_NUM_SEARCH = 221 "Search Operations Performed"; 222 223 224 225 230 public static final String STAT_TRACKER_SUBSEQUENT_SEARCH_TIME = 231 "Subsequent Search Time (ms)"; 232 233 234 235 239 public static final String STAT_TRACKER_SUCCESSFUL_AUTHENTICATIONS = 240 "Successful Authentications"; 241 242 243 244 247 public static final String [] DEFAULT_ATTRS_TO_MODIFY = new String [] 248 { 249 "description" 250 }; 251 252 253 254 static boolean blindTrust; 256 257 static boolean ignoreInvalidCredentials; 260 261 static boolean skipBind; 263 264 static boolean useDataFile; 267 268 static boolean useLoginIDRange; 270 271 static boolean useSequential; 273 274 static boolean useSharedConnections; 277 278 static boolean useSSL; 280 281 static int coolDownTime; 283 284 static int directoryPort; 286 287 static int loginIDMax; 289 290 static int loginIDMin; 292 293 static int loginIDSpan; 295 296 static int sequentialCounter; 298 299 static int timeLimit; 302 303 static int warmUpTime; 305 306 static long delay; 308 309 static LDAPConnection sharedAuthConnection; 311 312 static LDAPConnection sharedBindConnection; 314 315 static Random parentRandom; 318 319 static String bindDN; 322 323 static String bindPW; 325 326 static String directoryHost; 328 329 static String filter1; 331 332 static String filter2; 334 335 static String filter3; 337 338 static String loginIDAttr; 341 342 static String loginIDFinal; 344 345 static String loginIDInitial; 347 348 static String loginPassword; 350 351 static String searchAttr1; 353 354 static String searchAttr2; 356 357 static String searchAttr3; 359 360 static String searchBase; 363 364 static String sslKeyStore; 366 367 static String sslKeyPassword; 369 370 static String sslTrustStore; 372 373 static String sslTrustPassword; 375 376 static String [] loginIDs; 378 379 static String [] loginPasswords; 381 382 static String [] modAttrs; 384 385 static String [] returnAttrs1; 387 388 static String [] returnAttrs2; 390 391 static String [] returnAttrs3; 393 394 static String [] returnAttrsOC; 396 397 398 399 BooleanParameter blindTrustParameter = 401 new BooleanParameter("blind_trust", "Blindly Trust Any Certificate", 402 "Indicates whether the client should blindly trust " + 403 "any certificate presented by the server, or " + 404 "whether the key and trust stores should be used.", 405 true); 406 407 BooleanParameter ignoreInvCredParameter = 410 new BooleanParameter("ignore_49", "Ignore Invalid Credentials Errors", 411 "Indicates whether bind failures because of " + 412 "invalid credentials (err=49). This makes it " + 413 "possible to use this job without actually " + 414 "know user passwords.", false); 415 416 BooleanParameter shareConnsParameter = 418 new BooleanParameter("share_conns", "Share Connections between Threads", 419 "Indicates whether the connections to the " + 420 "directory server will be shared between threads " + 421 "or if each client thread will have its own " + 422 "connections.", true); 423 424 BooleanParameter skipBindParameter = 426 new BooleanParameter("skip_bind", "Skip Bind Operation", 427 "Indicates whether the bind attempt should be " + 428 "skipped as part of the authentication process.", 429 false); 430 431 BooleanParameter useSSLParameter = 433 new BooleanParameter("usessl", "Use SSL", 434 "Indicates whether to use SSL to encrypt the " + 435 "communication with the directory server", false); 436 437 FileURLParameter loginDataFileParameter = 439 new FileURLParameter("login_data_file", "Login Data File URL", 440 "The URL (FILE or HTTP) of the file containing " + 441 "the login IDs and passwords to use for the " + 442 "authentication.", null, false); 443 444 IntegerParameter coolDownParameter = 446 new IntegerParameter("cool_down", "Cool Down Time", 447 "The time in seconds that the job should " + 448 "continue searching after ending statistics " + 449 "collection.", true, 0, true, 0, false, 0); 450 451 IntegerParameter delayParameter = 454 new IntegerParameter("delay", "Time Between Authentications (ms)", 455 "Specifies the length of time in milliseconds " + 456 "each thread should wait between authentication " + 457 "attempts. Note that this delay will be " + 458 "between the starts of consecutive attempts and " + 459 "not between the end of one attempt and the " + 460 "beginning of the next. If an authentication " + 461 "takes longer than this length of time, then " + 462 "there will be no delay.", true, 0, true, 0, false, 463 0); 464 465 IntegerParameter portParameter = 467 new IntegerParameter("ldap_port", "Directory Server Port", 468 "The port number for the directory server.", true, 469 389, true, 1, true, 65535); 470 471 IntegerParameter timeLimitParameter = 474 new IntegerParameter("time_limit", "Operation Time Limit", 475 "The maximum length of time in seconds that any " + 476 "single LDAP operation will be allowed to take " + 477 "before it is cancelled.", true, 0, true, 0, false, 478 0); 479 480 IntegerParameter warmUpParameter = 482 new IntegerParameter("warm_up", "Warm Up Time", 483 "The time in seconds that the job should " + 484 "search before beginning statistics collection.", 485 true, 0, true, 0, false, 0); 486 487 MultiLineTextParameter modAttrsParameter = 489 new MultiLineTextParameter("mod_attrs", "Attributes to Modify", 490 "The set of attributes to modify.", 491 DEFAULT_ATTRS_TO_MODIFY, false); 492 493 PasswordParameter bindPWParameter = 495 new PasswordParameter("bindpw", "Directory Bind Password", 496 "The password to use when binding to the " + 497 "directory server to perform search and modify " + 498 "operations.", false, ""); 499 500 PasswordParameter keyPWParameter = 502 new PasswordParameter("sslkeypw", "SSL Key Store Password", 503 "The password for the JSSE key store", false, ""); 504 505 PasswordParameter loginPasswordParameter = 508 new PasswordParameter("login_id_pw", "Login Password", 509 "The password to use when authenticating to the " + 510 "directory for user authentications.", false, ""); 511 512 PasswordParameter trustPWParameter = 514 new PasswordParameter("ssltrustpw", "SSL Trust Store Password", 515 "The password for the JSSE trust store", false, ""); 516 517 PlaceholderParameter placeholder = new PlaceholderParameter(); 519 520 StringParameter attr1Parameter = 522 new StringParameter("attr1", "First Attribute to Retrieve", 523 "The first attribute to retrieve from the user's " + 524 "entry as part of the authentication process.", 525 true, DEFAULT_ATTR1); 526 527 StringParameter attr2Parameter = 529 new StringParameter("attr2", "Second Attribute to Retrieve", 530 "The second attribute to retrieve from the user's " + 531 "entry as part of the authentication process.", 532 true, DEFAULT_ATTR2); 533 534 StringParameter attr3Parameter = 536 new StringParameter("attr3", "Third Attribute to Retrieve", 537 "The third attribute to retrieve from the user's " + 538 "entry as part of the authentication process.", 539 true, DEFAULT_ATTR3); 540 541 StringParameter bindDNParameter = 543 new StringParameter("binddn", "Directory Bind DN", 544 "The DN to use when binding to the directory " + 545 "server to perform search and modify operations.", 546 false, ""); 547 548 StringParameter hostParameter = 550 new StringParameter("ldap_host", "Directory Server Address", 551 "The address for the directory server.", true, ""); 552 553 StringParameter keyStoreParameter = 555 new StringParameter("sslkeystore", "SSL Key Store", 556 "The path to the JSSE key store to use for an " + 557 "SSL-based connection", false, ""); 558 559 StringParameter loginIDParameter = 561 new StringParameter("login_id_attr", "Login ID Attribute", 562 "The attribute to use as the login ID to find the " + 563 "user's entry.", true, DEFAULT_LOG_ID_ATTR); 564 565 StringParameter loginIDValueParameter = 567 new StringParameter("login_id_value", "Login ID Value", 568 "The text to use as the value of the login ID " + 569 "attribute in search filters. The value may " + 570 "contain a range of numbers in square brackets.", 571 false, ""); 572 573 StringParameter searchBaseParameter = 575 new StringParameter("search_base", "User Search Base", 576 "The DN in the directory server under which user " + 577 "entries may be found.", true, ""); 578 579 StringParameter trustStoreParameter = 581 new StringParameter("ssltruststore", "SSL Trust Store", 582 "The path to the JSSE trust store to use for an " + 583 "SSL-based connection", false, ""); 584 585 CategoricalTracker failureReasonTracker; 587 588 IncrementalTracker attemptCounter; 590 591 IncrementalTracker bindCounter; 593 594 IncrementalTracker failureCounter; 596 597 IncrementalTracker modCounter; 599 600 IncrementalTracker searchCounter; 602 603 IncrementalTracker successCounter; 605 606 LDAPConnection authConnection; 609 610 LDAPConnection bindConnection; 612 613 LDAPConstraints authConstraints; 615 616 LDAPConstraints bindConstraints; 618 619 LDAPSearchConstraints authSearchConstraints; 621 622 Random random; 624 625 TimeTracker authTimer; 627 628 TimeTracker bindTimer; 630 631 TimeTracker initialSearchTimer; 634 635 TimeTracker modTimer; 637 638 TimeTracker subsequentSearchTimer; 641 642 643 644 648 public SiteMinderJobClass() 649 { 650 super(); 651 } 652 653 654 655 661 public String getJobName() 662 { 663 return "LDAP SiteMinder Load Simulator"; 664 } 665 666 667 668 674 public String getJobDescription() 675 { 676 return "This job simulates the load that SiteMinder can place on the " + 677 "directory server when it is performing authentications."; 678 } 679 680 681 682 688 public String getJobCategoryName() 689 { 690 return "LDAP"; 691 } 692 693 694 695 700 public ParameterList getParameterStubs() 701 { 702 Parameter[] parameterArray = new Parameter[] 703 { 704 placeholder, 705 hostParameter, 706 portParameter, 707 bindDNParameter, 708 bindPWParameter, 709 placeholder, 710 searchBaseParameter, 711 loginDataFileParameter, 712 loginIDValueParameter, 713 loginPasswordParameter, 714 loginIDParameter, 715 placeholder, 716 attr1Parameter, 717 attr2Parameter, 718 attr3Parameter, 719 modAttrsParameter, 720 placeholder, 721 warmUpParameter, 722 coolDownParameter, 723 timeLimitParameter, 724 delayParameter, 725 placeholder, 726 useSSLParameter, 727 blindTrustParameter, 728 keyStoreParameter, 729 keyPWParameter, 730 trustStoreParameter, 731 trustPWParameter, 732 placeholder, 733 skipBindParameter, 734 ignoreInvCredParameter, 735 shareConnsParameter 736 }; 737 738 return new ParameterList(parameterArray); 739 } 740 741 742 743 765 public StatTracker[] getStatTrackerStubs(String clientID, String threadID, 766 int collectionInterval) 767 { 768 return new StatTracker[] 769 { 770 new IncrementalTracker(clientID, threadID, 771 STAT_TRACKER_AUTHENTICATION_ATTEMPTS, 772 collectionInterval), 773 new IncrementalTracker(clientID, threadID, 774 STAT_TRACKER_SUCCESSFUL_AUTHENTICATIONS, 775 collectionInterval), 776 new IncrementalTracker(clientID, threadID, 777 STAT_TRACKER_FAILED_AUTHENTICATIONS, 778 collectionInterval), 779 new TimeTracker(clientID, threadID, STAT_TRACKER_AUTHENTICATION_TIME, 780 collectionInterval), 781 new IncrementalTracker(clientID, threadID, STAT_TRACKER_NUM_BINDS, 782 collectionInterval), 783 new TimeTracker(clientID, threadID, STAT_TRACKER_BIND_TIME, 784 collectionInterval), 785 new IncrementalTracker(clientID, threadID, STAT_TRACKER_NUM_MODS, 786 collectionInterval), 787 new TimeTracker(clientID, threadID, STAT_TRACKER_MOD_TIME, 788 collectionInterval), 789 new IncrementalTracker(clientID, threadID, STAT_TRACKER_NUM_SEARCH, 790 collectionInterval), 791 new TimeTracker(clientID, threadID, STAT_TRACKER_INITIAL_SEARCH_TIME, 792 collectionInterval), 793 new TimeTracker(clientID, threadID, STAT_TRACKER_SUBSEQUENT_SEARCH_TIME, 794 collectionInterval), 795 new CategoricalTracker(clientID, threadID, STAT_TRACKER_FAIL_REASON, 796 collectionInterval) 797 }; 798 } 799 800 801 802 807 public StatTracker[] getStatTrackers() 808 { 809 return new StatTracker[] 810 { 811 attemptCounter, 812 successCounter, 813 failureCounter, 814 authTimer, 815 bindCounter, 816 bindTimer, 817 modCounter, 818 modTimer, 819 searchCounter, 820 initialSearchTimer, 821 subsequentSearchTimer, 822 failureReasonTracker 823 }; 824 } 825 826 827 828 850 public void validateJobInfo(int numClients, int threadsPerClient, 851 int threadStartupDelay, Date startTime, 852 Date stopTime, int duration, 853 int collectionInterval, ParameterList parameters) 854 throws InvalidValueException 855 { 856 FileURLParameter loginDataURLParameter = 857 parameters.getFileURLParameter(loginDataFileParameter.getName()); 858 if ((loginDataURLParameter == null) || 859 (! loginDataURLParameter.hasValue())) 860 { 861 StringParameter loginValueParameter = 862 parameters.getStringParameter(loginIDValueParameter.getName()); 863 PasswordParameter loginPWParameter = 864 parameters.getPasswordParameter(loginPasswordParameter.getName()); 865 866 if ((loginValueParameter == null) || 867 (! loginValueParameter.hasValue()) || 868 (loginPWParameter == null) || 869 (! loginPWParameter.hasValue())) 870 { 871 throw new InvalidValueException("You must specify either a login " + 872 "data file URL or a login ID value " + 873 "and password"); 874 } 875 } 876 } 877 878 879 880 888 public boolean providesParameterTest() 889 { 890 return true; 891 } 892 893 894 895 922 public boolean testJobParameters(ParameterList parameters, 923 ArrayList outputMessages) 924 { 925 StringParameter hostParam = 927 parameters.getStringParameter(hostParameter.getName()); 928 if ((hostParam == null) || (! hostParam.hasValue())) 929 { 930 outputMessages.add("ERROR: No directory server address was provided."); 931 return false; 932 } 933 String host = hostParam.getStringValue(); 934 935 936 IntegerParameter portParam = 937 parameters.getIntegerParameter(portParameter.getName()); 938 if ((portParam == null) || (! hostParam.hasValue())) 939 { 940 outputMessages.add("ERROR: No directory server port was provided."); 941 return false; 942 } 943 int port = portParam.getIntValue(); 944 945 946 boolean useSSL = false; 947 BooleanParameter useSSLParam = 948 parameters.getBooleanParameter(useSSLParameter.getName()); 949 if (useSSLParam != null) 950 { 951 useSSL = useSSLParam.getBooleanValue(); 952 } 953 954 955 boolean blindTrust = true; 956 BooleanParameter blindTrustParam = 957 parameters.getBooleanParameter(blindTrustParameter.getName()); 958 if (blindTrustParam != null) 959 { 960 blindTrust = blindTrustParam.getBooleanValue(); 961 } 962 963 964 String keyStore = null; 965 StringParameter keyStoreParam = 966 parameters.getStringParameter(keyStoreParameter.getName()); 967 if ((keyStoreParam != null) && keyStoreParam.hasValue()) 968 { 969 keyStore = keyStoreParam.getStringValue(); 970 File keyStoreFile = new File(keyStore); 971 if (useSSL && (! blindTrust) && (! keyStoreFile.exists())) 972 { 973 outputMessages.add("WARNING: Key store file \"" + keyStore + 974 "\" not found on SLAMD server system. This test " + 975 "will blindly trust any SSL certificate " + 976 "presented by the directory server."); 977 outputMessages.add(""); 978 blindTrust = true; 979 } 980 else 981 { 982 System.setProperty(SSL_KEY_STORE_PROPERTY, keyStore); 983 } 984 } 985 986 987 String keyStorePassword = ""; 988 StringParameter keyPassParam = 989 parameters.getStringParameter(keyPWParameter.getName()); 990 if ((keyPassParam != null) && keyPassParam.hasValue()) 991 { 992 keyStorePassword = keyPassParam.getStringValue(); 993 System.setProperty(SSL_KEY_PASSWORD_PROPERTY, keyStorePassword); 994 } 995 996 997 String trustStore = null; 998 StringParameter trustStoreParam = 999 parameters.getStringParameter(trustStoreParameter.getName()); 1000 if ((trustStoreParam != null) && trustStoreParam.hasValue()) 1001 { 1002 trustStore = trustStoreParam.getStringValue(); 1003 File trustStoreFile = new File(trustStore); 1004 if (useSSL && (! blindTrust) && (! trustStoreFile.exists())) 1005 { 1006 outputMessages.add("WARNING: trust store file \"" + trustStore + 1007 "\" not found on SLAMD server system. This test " + 1008 "will blindly trust any SSL certificate " + 1009 "presented by the directory server."); 1010 outputMessages.add(""); 1011 blindTrust = true; 1012 } 1013 else 1014 { 1015 System.setProperty(SSL_TRUST_STORE_PROPERTY, trustStore); 1016 } 1017 } 1018 1019 1020 String trustStorePassword = ""; 1021 StringParameter trustPassParam = 1022 parameters.getStringParameter(trustPWParameter.getName()); 1023 if ((trustPassParam != null) && trustPassParam.hasValue()) 1024 { 1025 trustStorePassword = trustPassParam.getStringValue(); 1026 System.setProperty(SSL_TRUST_PASSWORD_PROPERTY, trustStorePassword); 1027 } 1028 1029 1030 String bindDN = ""; 1031 StringParameter bindDNParam = 1032 parameters.getStringParameter(bindDNParameter.getName()); 1033 if ((bindDNParam != null) && bindDNParam.hasValue()) 1034 { 1035 bindDN = bindDNParam.getStringValue(); 1036 } 1037 1038 1039 String bindPassword = ""; 1040 PasswordParameter bindPWParam = 1041 parameters.getPasswordParameter(bindPWParameter.getName()); 1042 if ((bindPWParam != null) && bindPWParam.hasValue()) 1043 { 1044 bindPassword = bindPWParam.getStringValue(); 1045 } 1046 1047 1048 StringParameter baseDNParam = 1049 parameters.getStringParameter(searchBaseParameter.getName()); 1050 if ((baseDNParam == null) || (! baseDNParam.hasValue())) 1051 { 1052 outputMessages.add("ERROR: No base DN was provided."); 1053 return false; 1054 } 1055 String baseDN = baseDNParam.getStringValue(); 1056 1057 1058 LDAPConnection conn; 1061 if (useSSL) 1062 { 1063 if (blindTrust) 1064 { 1065 try 1066 { 1067 conn = new LDAPConnection(new JSSEBlindTrustSocketFactory()); 1068 } 1069 catch (Exception e) 1070 { 1071 outputMessages.add("ERROR: Unable to instantiate the blind trust " + 1072 "socket factory for use in creating the SSL " + 1073 "connection: " + stackTraceToString(e)); 1074 return false; 1075 } 1076 } 1077 else 1078 { 1079 conn = new LDAPConnection(new JSSESocketFactory(null)); 1080 } 1081 } 1082 else 1083 { 1084 conn = new LDAPConnection(); 1085 } 1086 1087 1088 try 1090 { 1091 if (useSSL) 1092 { 1093 outputMessages.add("Attempting to establish an SSL-based connection " + 1094 "to " + host + ":" + port + "...."); 1095 } 1096 else 1097 { 1098 outputMessages.add("Attempting to establish a connection to " + host + 1099 ":" + port + "...."); 1100 } 1101 conn.connect(host, port); 1102 outputMessages.add("Connected successfully."); 1103 outputMessages.add(""); 1104 } 1105 catch (Exception e) 1106 { 1107 outputMessages.add("ERROR: Unable to connect to the directory " + 1108 "server: " + stackTraceToString(e)); 1109 return false; 1110 } 1111 1112 1113 try 1115 { 1116 outputMessages.add("Attempting to perform an LDAPv3 bind to the " + 1117 "directory server with a DN of '" + bindDN + "'...."); 1118 conn.bind(3, bindDN, bindPassword); 1119 outputMessages.add("Bound successfully."); 1120 outputMessages.add(""); 1121 } 1122 catch (Exception e) 1123 { 1124 try 1125 { 1126 conn.disconnect(); 1127 } catch (Exception e2) {} 1128 1129 outputMessages.add("ERROR: Unable to bind to the directory server: " + 1130 stackTraceToString(e)); 1131 return false; 1132 } 1133 1134 1135 try 1137 { 1138 outputMessages.add("Checking to make sure that the base DN entry '" + 1139 baseDN + "' exists in the directory...."); 1140 LDAPEntry baseDNEntry = conn.read(baseDN, new String [] { "1.1" }); 1141 if (baseDNEntry == null) 1142 { 1143 try 1144 { 1145 conn.disconnect(); 1146 } catch (Exception e2) {} 1147 1148 outputMessages.add("ERROR: Unable to retrieve the base DN entry."); 1149 return false; 1150 } 1151 else 1152 { 1153 outputMessages.add("Successfully read the base DN entry."); 1154 outputMessages.add(""); 1155 } 1156 } 1157 catch (Exception e) 1158 { 1159 try 1160 { 1161 conn.disconnect(); 1162 } catch (Exception e2) {} 1163 1164 outputMessages.add("ERROR: Unable to retrieve the base DN entry: " + 1165 stackTraceToString(e)); 1166 return false; 1167 } 1168 1169 1170 try 1173 { 1174 conn.disconnect(); 1175 } catch (Exception e) {} 1176 1177 outputMessages.add("All tests completed successfully."); 1178 return true; 1179 } 1180 1181 1182 1183 1195 public void initializeClient(String clientID, ParameterList parameters) 1196 throws UnableToRunException 1197 { 1198 hostParameter = parameters.getStringParameter(hostParameter.getName()); 1200 if (hostParameter == null) 1201 { 1202 throw new UnableToRunException("No directory server host provided."); 1203 } 1204 else 1205 { 1206 directoryHost = hostParameter.getStringValue(); 1207 } 1208 1209 1210 portParameter = parameters.getIntegerParameter(portParameter.getName()); 1212 if (portParameter != null) 1213 { 1214 directoryPort = portParameter.getIntValue(); 1215 } 1216 1217 bindDNParameter = parameters.getStringParameter(bindDNParameter.getName()); 1219 if (bindDNParameter == null) 1220 { 1221 bindDN = ""; 1222 } 1223 else 1224 { 1225 bindDN = bindDNParameter.getStringValue(); 1226 } 1227 1228 bindPWParameter = 1230 parameters.getPasswordParameter(bindPWParameter.getName()); 1231 if (bindPWParameter == null) 1232 { 1233 bindPW = ""; 1234 } 1235 else 1236 { 1237 bindPW = bindPWParameter.getStringValue(); 1238 } 1239 1240 searchBaseParameter = 1242 parameters.getStringParameter(searchBaseParameter.getName()); 1243 if (searchBaseParameter != null) 1244 { 1245 searchBase = searchBaseParameter.getStringValue(); 1246 } 1247 1248 1249 useDataFile = false; 1251 loginDataFileParameter = 1252 parameters.getFileURLParameter(loginDataFileParameter.getName()); 1253 if ((loginDataFileParameter != null) && (loginDataFileParameter.hasValue())) 1254 { 1255 String [] fileLines; 1256 try 1257 { 1258 fileLines = loginDataFileParameter.getNonBlankFileLines(); 1259 } 1260 catch (Exception e) 1261 { 1262 throw new UnableToRunException("Unable to retrieve the login data " + 1263 "from the file: " + e, e); 1264 } 1265 1266 ArrayList loginIDList = new ArrayList(fileLines.length); 1268 ArrayList passwordList = new ArrayList(fileLines.length); 1269 for (int i=0; i < fileLines.length; i++) 1270 { 1271 try 1272 { 1273 StringTokenizer tokenizer = new StringTokenizer(fileLines[i], "\t"); 1274 String loginID = tokenizer.nextToken(); 1275 String password = tokenizer.nextToken(); 1276 loginIDList.add(loginID); 1277 passwordList.add(password); 1278 } catch (Exception e) {} 1279 } 1280 1281 loginIDs = new String [loginIDList.size()]; 1284 loginPasswords = new String [passwordList.size()]; 1285 loginIDList.toArray(loginIDs); 1286 passwordList.toArray(loginPasswords); 1287 if (loginIDs.length == 0) 1288 { 1289 throw new UnableToRunException("No login IDs/passwords extracted from " + 1290 "the login data file."); 1291 } 1292 1293 useDataFile = true; 1294 } 1295 else 1296 { 1297 loginPasswordParameter = 1298 parameters.getPasswordParameter(loginPasswordParameter.getName()); 1299 if ((loginPasswordParameter != null) && 1300 (loginPasswordParameter.hasValue())) 1301 { 1302 loginPassword = loginPasswordParameter.getStringValue(); 1303 } 1304 1305 loginIDValueParameter = 1306 parameters.getStringParameter(loginIDValueParameter.getName()); 1307 useLoginIDRange = true; 1308 useSequential = false; 1309 String loginIDValue = loginIDValueParameter.getStringValue(); 1310 try 1311 { 1312 int openPos = loginIDValue.indexOf('['); 1313 int closePos = loginIDValue.indexOf(']', openPos); 1314 loginIDInitial = loginIDValue.substring(0, openPos); 1315 loginIDFinal = loginIDValue.substring(closePos+1); 1316 1317 int dashPos = loginIDValue.indexOf('-', openPos); 1318 if (dashPos < 0) 1319 { 1320 dashPos = loginIDValue.indexOf(':', openPos); 1321 useSequential = true; 1322 } 1323 1324 loginIDMin = Integer.parseInt(loginIDValue.substring(openPos+1, 1325 dashPos)); 1326 loginIDMax = Integer.parseInt(loginIDValue.substring(dashPos+1, 1327 closePos)); 1328 loginIDSpan = loginIDMax - loginIDMin + 1; 1329 sequentialCounter = loginIDMin; 1330 } 1331 catch (Exception e) 1332 { 1333 useLoginIDRange = false; 1334 loginIDInitial = loginIDValue; 1335 } 1336 } 1337 1338 1339 loginIDParameter = 1341 parameters.getStringParameter(loginIDParameter.getName()); 1342 if (loginIDParameter != null) 1343 { 1344 loginIDAttr = loginIDParameter.getStringValue(); 1345 } 1346 1347 1348 attr1Parameter = parameters.getStringParameter(attr1Parameter.getName()); 1350 if (attr1Parameter != null) 1351 { 1352 searchAttr1 = attr1Parameter.getStringValue(); 1353 filter1 = "(" + searchAttr1 + "=*)"; 1354 returnAttrs1 = new String [] { searchAttr1 }; 1355 } 1356 1357 attr2Parameter = parameters.getStringParameter(attr2Parameter.getName()); 1358 if (attr2Parameter != null) 1359 { 1360 searchAttr2 = attr2Parameter.getStringValue(); 1361 filter2 = "(" + searchAttr2 + "=*)"; 1362 returnAttrs2 = new String [] { searchAttr2 }; 1363 } 1364 1365 attr3Parameter = parameters.getStringParameter(attr3Parameter.getName()); 1366 if (attr3Parameter != null) 1367 { 1368 searchAttr3 = attr3Parameter.getStringValue(); 1369 filter3 = "(" + searchAttr3 + "=*)"; 1370 returnAttrs3 = new String [] { searchAttr3 }; 1371 } 1372 1373 returnAttrsOC = new String [] { "objectClass" }; 1374 1375 1376 modAttrs = null; 1378 modAttrsParameter = 1379 parameters.getMultiLineTextParameter(modAttrsParameter.getName()); 1380 if ((modAttrsParameter != null) && (modAttrsParameter.hasValue())) 1381 { 1382 modAttrs = modAttrsParameter.getNonBlankLines(); 1383 } 1384 1385 skipBind = false; 1387 skipBindParameter = 1388 parameters.getBooleanParameter(skipBindParameter.getName()); 1389 if (skipBindParameter != null) 1390 { 1391 skipBind = skipBindParameter.getBooleanValue(); 1392 } 1393 1394 warmUpTime = 0; 1396 warmUpParameter = parameters.getIntegerParameter(warmUpParameter.getName()); 1397 if (warmUpParameter != null) 1398 { 1399 warmUpTime = warmUpParameter.getIntValue(); 1400 } 1401 1402 coolDownTime = 0; 1404 coolDownParameter = 1405 parameters.getIntegerParameter(coolDownParameter.getName()); 1406 if (coolDownParameter != null) 1407 { 1408 coolDownTime = coolDownParameter.getIntValue(); 1409 } 1410 1411 timeLimitParameter = 1413 parameters.getIntegerParameter(timeLimitParameter.getName()); 1414 if (timeLimitParameter != null) 1415 { 1416 timeLimit = timeLimitParameter.getIntValue(); 1417 } 1418 1419 delay = 0; 1421 delayParameter = parameters.getIntegerParameter(delayParameter.getName()); 1422 if (delayParameter != null) 1423 { 1424 delay = delayParameter.getIntValue(); 1425 } 1426 1427 useSSL = false; 1429 useSSLParameter = parameters.getBooleanParameter(useSSLParameter.getName()); 1430 if (useSSLParameter != null) 1431 { 1432 useSSL = useSSLParameter.getBooleanValue(); 1433 } 1434 1435 if (useSSL) 1437 { 1438 blindTrustParameter = 1440 parameters.getBooleanParameter(blindTrustParameter.getName()); 1441 if (blindTrustParameter != null) 1442 { 1443 blindTrust = blindTrustParameter.getBooleanValue(); 1444 } 1445 1446 sslKeyStore = null; 1448 keyStoreParameter = 1449 parameters.getStringParameter(keyStoreParameter.getName()); 1450 if ((keyStoreParameter != null) && (keyStoreParameter.hasValue())) 1451 { 1452 sslKeyStore = keyStoreParameter.getStringValue(); 1453 System.setProperty(SSL_KEY_STORE_PROPERTY, sslKeyStore); 1454 } 1455 1456 sslKeyPassword = null; 1458 keyPWParameter = 1459 parameters.getPasswordParameter(keyPWParameter.getName()); 1460 if ((keyPWParameter != null) && (keyPWParameter.hasValue())) 1461 { 1462 sslKeyPassword = keyPWParameter.getStringValue(); 1463 System.setProperty(SSL_KEY_PASSWORD_PROPERTY, sslKeyPassword); 1464 } 1465 1466 sslTrustStore = null; 1468 trustStoreParameter = 1469 parameters.getStringParameter(trustStoreParameter.getName()); 1470 if ((trustStoreParameter != null) && (trustStoreParameter.hasValue())) 1471 { 1472 sslTrustStore = trustStoreParameter.getStringValue(); 1473 System.setProperty(SSL_TRUST_STORE_PROPERTY, sslTrustStore); 1474 } 1475 1476 sslTrustPassword = null; 1478 trustPWParameter = 1479 parameters.getPasswordParameter(trustPWParameter.getName()); 1480 if ((trustPWParameter != null) && (trustPWParameter.hasValue())) 1481 { 1482 sslTrustPassword = trustPWParameter.getStringValue(); 1483 System.setProperty(SSL_TRUST_PASSWORD_PROPERTY, sslTrustPassword); 1484 } 1485 } 1486 1487 1488 ignoreInvCredParameter = 1491 parameters.getBooleanParameter(ignoreInvCredParameter.getName()); 1492 if (ignoreInvCredParameter != null) 1493 { 1494 ignoreInvalidCredentials = ignoreInvCredParameter.getBooleanValue(); 1495 } 1496 1497 shareConnsParameter = 1499 parameters.getBooleanParameter(shareConnsParameter.getName()); 1500 if (shareConnsParameter != null) 1501 { 1502 useSharedConnections = shareConnsParameter.getBooleanValue(); 1503 } 1504 1505 1506 if (useSharedConnections) 1508 { 1509 if (useSSL) 1510 { 1511 if (blindTrust) 1512 { 1513 try 1514 { 1515 sharedAuthConnection = 1516 new LDAPConnection(new JSSEBlindTrustSocketFactory()); 1517 sharedBindConnection = 1518 new LDAPConnection(new JSSEBlindTrustSocketFactory()); 1519 } 1520 catch (LDAPException le) 1521 { 1522 throw new UnableToRunException(le.getMessage(), le); 1523 } 1524 } 1525 else 1526 { 1527 sharedAuthConnection = 1528 new LDAPConnection(new JSSESocketFactory(null)); 1529 sharedBindConnection = 1530 new LDAPConnection(new JSSESocketFactory(null)); 1531 } 1532 } 1533 else 1534 { 1535 sharedAuthConnection = new LDAPConnection(); 1536 sharedBindConnection = new LDAPConnection(); 1537 } 1538 1539 try 1540 { 1541 sharedAuthConnection.connect(3, directoryHost, directoryPort, bindDN, 1542 bindPW); 1543 sharedBindConnection.connect(3, directoryHost, directoryPort, "", ""); 1544 } 1545 catch (Exception e) 1546 { 1547 throw new UnableToRunException("Could not establish shared " + 1548 "connections to the directory: " + e, 1549 e); 1550 } 1551 } 1552 1553 1554 parentRandom = new Random(); 1556 } 1557 1558 1559 1560 1576 public void initializeThread(String clientID, String threadID, 1577 int collectionInterval, ParameterList parameters) 1578 throws UnableToRunException 1579 { 1580 random = new Random(parentRandom.nextLong()); 1582 1583 if (useSharedConnections) 1587 { 1588 authConnection = sharedAuthConnection; 1589 bindConnection = sharedBindConnection; 1590 } 1591 else 1592 { 1593 if (useSSL) 1594 { 1595 if (blindTrust) 1596 { 1597 try 1598 { 1599 authConnection = 1600 new LDAPConnection(new JSSEBlindTrustSocketFactory()); 1601 bindConnection = 1602 new LDAPConnection(new JSSEBlindTrustSocketFactory()); 1603 } 1604 catch (LDAPException le) 1605 { 1606 throw new UnableToRunException(le.getMessage(), le); 1607 } 1608 } 1609 else 1610 { 1611 authConnection = new LDAPConnection(new JSSESocketFactory(null)); 1612 bindConnection = new LDAPConnection(new JSSESocketFactory(null)); 1613 } 1614 } 1615 else 1616 { 1617 authConnection = new LDAPConnection(); 1618 bindConnection = new LDAPConnection(); 1619 } 1620 1621 try 1622 { 1623 authConnection.connect(3, directoryHost, directoryPort, bindDN, bindPW); 1624 bindConnection.connect(3, directoryHost, directoryPort, "", ""); 1625 } 1626 catch (Exception e) 1627 { 1628 throw new UnableToRunException("Unable to establish the connections " + 1629 "to the directory server: " + e, e); 1630 } 1631 } 1632 1633 authConstraints = authConnection.getConstraints(); 1635 bindConstraints = bindConnection.getConstraints(); 1636 authSearchConstraints = authConnection.getSearchConstraints(); 1637 authConstraints.setTimeLimit(1000*timeLimit); 1638 bindConstraints.setTimeLimit(1000*timeLimit); 1639 authSearchConstraints.setTimeLimit(1000*timeLimit); 1640 authSearchConstraints.setServerTimeLimit(timeLimit); 1641 1642 1643 attemptCounter = 1645 new IncrementalTracker(clientID, threadID, 1646 STAT_TRACKER_AUTHENTICATION_ATTEMPTS, 1647 collectionInterval); 1648 successCounter = 1649 new IncrementalTracker(clientID, threadID, 1650 STAT_TRACKER_SUCCESSFUL_AUTHENTICATIONS, 1651 collectionInterval); 1652 failureCounter = 1653 new IncrementalTracker(clientID, threadID, 1654 STAT_TRACKER_FAILED_AUTHENTICATIONS, 1655 collectionInterval); 1656 bindCounter = new IncrementalTracker(clientID, threadID, 1657 STAT_TRACKER_NUM_BINDS, 1658 collectionInterval); 1659 modCounter = new IncrementalTracker(clientID, threadID, 1660 STAT_TRACKER_NUM_MODS, 1661 collectionInterval); 1662 searchCounter = new IncrementalTracker(clientID, threadID, 1663 STAT_TRACKER_NUM_SEARCH, 1664 collectionInterval); 1665 authTimer = new TimeTracker(clientID, threadID, 1666 STAT_TRACKER_AUTHENTICATION_TIME, 1667 collectionInterval); 1668 bindTimer = new TimeTracker(clientID, threadID, STAT_TRACKER_BIND_TIME, 1669 collectionInterval); 1670 modTimer = new TimeTracker(clientID, threadID, STAT_TRACKER_MOD_TIME, 1671 collectionInterval); 1672 initialSearchTimer = new TimeTracker(clientID, threadID, 1673 STAT_TRACKER_INITIAL_SEARCH_TIME, 1674 collectionInterval); 1675 subsequentSearchTimer = new TimeTracker(clientID, threadID, 1676 STAT_TRACKER_SUBSEQUENT_SEARCH_TIME, 1677 collectionInterval); 1678 failureReasonTracker = new CategoricalTracker(clientID, threadID, 1679 STAT_TRACKER_FAIL_REASON, 1680 collectionInterval); 1681 1682 1683 RealTimeStatReporter statReporter = getStatReporter(); 1685 if (statReporter != null) 1686 { 1687 String jobID = getJobID(); 1688 attemptCounter.enableRealTimeStats(statReporter, jobID); 1689 successCounter.enableRealTimeStats(statReporter, jobID); 1690 failureCounter.enableRealTimeStats(statReporter, jobID); 1691 bindCounter.enableRealTimeStats(statReporter, jobID); 1692 modCounter.enableRealTimeStats(statReporter, jobID); 1693 searchCounter.enableRealTimeStats(statReporter, jobID); 1694 authTimer.enableRealTimeStats(statReporter, jobID); 1695 bindTimer.enableRealTimeStats(statReporter, jobID); 1696 modTimer.enableRealTimeStats(statReporter, jobID); 1697 initialSearchTimer.enableRealTimeStats(statReporter, jobID); 1698 subsequentSearchTimer.enableRealTimeStats(statReporter, jobID); 1699 } 1700 } 1701 1702 1703 1704 1708 public void runJob() 1709 { 1710 long currentTime = System.currentTimeMillis(); 1712 boolean collectingStats = false; 1713 long startCollectingTime = currentTime + (1000 * warmUpTime); 1714 long stopCollectingTime = Long.MAX_VALUE; 1715 if ((coolDownTime > 0) && (getShouldStopTime() > 0)) 1716 { 1717 stopCollectingTime = getShouldStopTime() - (1000 * coolDownTime); 1718 } 1719 1720 long authStartTime = 0; 1723 1724 1725 while (! shouldStop()) 1727 { 1728 currentTime = System.currentTimeMillis(); 1729 if ((! collectingStats) && (currentTime >= startCollectingTime) && 1730 (currentTime < stopCollectingTime)) 1731 { 1732 attemptCounter.startTracker(); 1734 successCounter.startTracker(); 1735 failureCounter.startTracker(); 1736 authTimer.startTracker(); 1737 bindCounter.startTracker(); 1738 modCounter.startTracker(); 1739 searchCounter.startTracker(); 1740 bindTimer.startTracker(); 1741 modTimer.startTracker(); 1742 initialSearchTimer.startTracker(); 1743 subsequentSearchTimer.startTracker(); 1744 failureReasonTracker.startTracker(); 1745 collectingStats = true; 1746 } 1747 else if ((collectingStats) && (currentTime >= stopCollectingTime)) 1748 { 1749 attemptCounter.stopTracker(); 1750 successCounter.stopTracker(); 1751 failureCounter.stopTracker(); 1752 authTimer.stopTracker(); 1753 bindCounter.stopTracker(); 1754 modCounter.stopTracker(); 1755 searchCounter.stopTracker(); 1756 bindTimer.stopTracker(); 1757 modTimer.stopTracker(); 1758 initialSearchTimer.stopTracker(); 1759 subsequentSearchTimer.stopTracker(); 1760 failureReasonTracker.stopTracker(); 1761 collectingStats = false; 1762 } 1763 1764 if ((delay > 0) && (authStartTime > 0)) 1766 { 1767 long now = System.currentTimeMillis(); 1768 long sleepTime = delay - (now - authStartTime); 1769 if (sleepTime > 0) 1770 { 1771 try 1772 { 1773 Thread.sleep(sleepTime); 1774 } catch (InterruptedException ie) {} 1775 1776 if (shouldStop()) 1777 { 1778 break; 1779 } 1780 } 1781 } 1782 1783 String [] loginInfo = getLoginInfo(); 1785 String loginID = loginInfo[0]; 1786 String password = loginInfo[1]; 1787 1788 1789 if (delay > 0) 1791 { 1792 authStartTime = System.currentTimeMillis(); 1793 } 1794 1795 1796 if (collectingStats) 1798 { 1799 attemptCounter.increment(); 1800 authTimer.startTimer(); 1801 } 1802 1803 String failureReason = "Search 1"; 1804 1805 try 1806 { 1807 String userDN = null; 1809 String filter = "(" + loginIDAttr + "=" + loginID + ")"; 1810 LDAPSearchResults results; 1811 if (collectingStats) 1812 { 1813 searchCounter.increment(); 1814 initialSearchTimer.startTimer(); 1815 } 1816 results = authConnection.search(searchBase, LDAPConnection.SCOPE_SUB, 1817 filter, returnAttrsOC, false, 1818 authSearchConstraints); 1819 while (results.hasMoreElements()) 1820 { 1821 Object element = results.nextElement(); 1822 if (element instanceof LDAPEntry) 1823 { 1824 userDN = ((LDAPEntry) element).getDN(); 1825 } 1826 } 1827 if (collectingStats) 1828 { 1829 initialSearchTimer.stopTimer(); 1830 } 1831 1832 if (userDN == null) 1834 { 1835 if (collectingStats) 1836 { 1837 failureCounter.increment(); 1838 authTimer.stopTimer(); 1839 failureReasonTracker.increment(failureReason); 1840 } 1841 continue; 1842 } 1843 1844 failureReason = "Search 2"; 1847 filter = "(objectClass=*)"; 1848 if (collectingStats) 1849 { 1850 searchCounter.increment(); 1851 subsequentSearchTimer.startTimer(); 1852 } 1853 results = authConnection.search(userDN, LDAPConnection.SCOPE_BASE, 1854 filter, returnAttrsOC, false, 1855 authSearchConstraints); 1856 while (results.hasMoreElements()) 1857 { 1858 results.nextElement(); 1859 } 1860 if (collectingStats) 1861 { 1862 subsequentSearchTimer.stopTimer(); 1863 } 1864 1865 if (! skipBind) 1867 { 1868 failureReason = "Bind"; 1869 1870 try 1871 { 1872 if (collectingStats) 1873 { 1874 bindCounter.increment(); 1875 bindTimer.startTimer(); 1876 } 1877 bindConnection.authenticate(3, userDN, password, bindConstraints); 1878 if (collectingStats) 1879 { 1880 bindTimer.stopTimer(); 1881 } 1882 } 1883 catch (LDAPException le) 1884 { 1885 if (collectingStats) 1886 { 1887 bindTimer.stopTimer(); 1888 } 1889 1890 if (le.getLDAPResultCode() == LDAPException.INVALID_CREDENTIALS) 1891 { 1892 if (! ignoreInvalidCredentials) 1893 { 1894 if (collectingStats) 1895 { 1896 failureCounter.increment(); 1897 authTimer.stopTimer(); 1898 failureReasonTracker.increment(failureReason); 1899 } 1900 continue; 1901 } 1902 } 1903 else 1904 { 1905 if (collectingStats) 1906 { 1907 failureCounter.increment(); 1908 authTimer.stopTimer(); 1909 failureReasonTracker.increment(failureReason); 1910 } 1911 continue; 1912 } 1913 } 1914 } 1915 1916 failureReason = "Search 3"; 1918 if (collectingStats) 1919 { 1920 searchCounter.increment(); 1921 subsequentSearchTimer.startTimer(); 1922 } 1923 results = authConnection.search(userDN, LDAPConnection.SCOPE_BASE, 1924 filter1, returnAttrs1, false, 1925 authSearchConstraints); 1926 while (results.hasMoreElements()) 1927 { 1928 results.nextElement(); 1929 } 1930 if (collectingStats) 1931 { 1932 subsequentSearchTimer.stopTimer(); 1933 } 1934 1935 failureReason = "Search 4"; 1937 if (collectingStats) 1938 { 1939 searchCounter.increment(); 1940 subsequentSearchTimer.startTimer(); 1941 } 1942 results = authConnection.search(userDN, LDAPConnection.SCOPE_BASE, 1943 filter2, returnAttrs2, false, 1944 authSearchConstraints); 1945 while (results.hasMoreElements()) 1946 { 1947 results.nextElement(); 1948 } 1949 if (collectingStats) 1950 { 1951 subsequentSearchTimer.stopTimer(); 1952 } 1953 1954 failureReason = "Search 5"; 1956 if (collectingStats) 1957 { 1958 searchCounter.increment(); 1959 subsequentSearchTimer.startTimer(); 1960 } 1961 results = authConnection.search(userDN, LDAPConnection.SCOPE_BASE, 1962 filter1, returnAttrs1, false, 1963 authSearchConstraints); 1964 while (results.hasMoreElements()) 1965 { 1966 results.nextElement(); 1967 } 1968 if (collectingStats) 1969 { 1970 subsequentSearchTimer.stopTimer(); 1971 } 1972 1973 if ((modAttrs != null) && (modAttrs.length > 0)) 1975 { 1976 failureReason = "Modify"; 1977 LDAPModificationSet modSet = new LDAPModificationSet(); 1978 for (int i=0; i < modAttrs.length; i++) 1979 { 1980 LDAPAttribute attr = new LDAPAttribute(modAttrs[i], 1981 getRandomString(80)); 1982 modSet.add(LDAPModification.REPLACE, attr); 1983 } 1984 if (collectingStats) 1985 { 1986 modCounter.increment(); 1987 modTimer.startTimer(); 1988 } 1989 authConnection.modify(userDN, modSet, authConstraints); 1990 if (collectingStats) 1991 { 1992 modTimer.stopTimer(); 1993 } 1994 } 1995 1996 failureReason = "Search 6"; 1998 if (collectingStats) 1999 { 2000 searchCounter.increment(); 2001 subsequentSearchTimer.startTimer(); 2002 } 2003 results = authConnection.search(userDN, LDAPConnection.SCOPE_BASE, 2004 filter1, returnAttrs1, false, 2005 authSearchConstraints); 2006 while (results.hasMoreElements()) 2007 { 2008 results.nextElement(); 2009 } 2010 if (collectingStats) 2011 { 2012 subsequentSearchTimer.stopTimer(); 2013 } 2014 2015 failureReason = "Search 7"; 2017 if (collectingStats) 2018 { 2019 searchCounter.increment(); 2020 subsequentSearchTimer.startTimer(); 2021 } 2022 results = authConnection.search(userDN, LDAPConnection.SCOPE_BASE, 2023 filter1, returnAttrs1, false, 2024 authSearchConstraints); 2025 while (results.hasMoreElements()) 2026 { 2027 results.nextElement(); 2028 } 2029 if (collectingStats) 2030 { 2031 subsequentSearchTimer.stopTimer(); 2032 } 2033 2034 failureReason = "Search 8"; 2036 if (collectingStats) 2037 { 2038 searchCounter.increment(); 2039 subsequentSearchTimer.startTimer(); 2040 } 2041 results = authConnection.search(userDN, LDAPConnection.SCOPE_BASE, 2042 filter3, returnAttrs3, false, 2043 authSearchConstraints); 2044 while (results.hasMoreElements()) 2045 { 2046 results.nextElement(); 2047 } 2048 if (collectingStats) 2049 { 2050 subsequentSearchTimer.stopTimer(); 2051 } 2052 } 2053 catch (Exception e) 2054 { 2055 2056 if (collectingStats) 2057 { 2058 failureCounter.increment(); 2059 authTimer.stopTimer(); 2060 failureReasonTracker.increment(failureReason); 2061 } 2062 continue; 2063 } 2064 2065 2066 if (collectingStats) 2069 { 2070 successCounter.increment(); 2071 authTimer.stopTimer(); 2072 } 2073 } 2074 2075 2076 if (collectingStats) 2078 { 2079 attemptCounter.stopTracker(); 2080 successCounter.stopTracker(); 2081 failureCounter.stopTracker(); 2082 authTimer.stopTracker(); 2083 bindCounter.stopTracker(); 2084 modCounter.stopTracker(); 2085 searchCounter.stopTracker(); 2086 bindTimer.stopTracker(); 2087 modTimer.stopTracker(); 2088 initialSearchTimer.stopTracker(); 2089 subsequentSearchTimer.stopTracker(); 2090 failureReasonTracker.stopTracker(); 2091 } 2092 2093 2094 if (! useSharedConnections) 2096 { 2097 try 2098 { 2099 authConnection.disconnect(); 2100 } catch (Exception e) {} 2101 2102 try 2103 { 2104 bindConnection.disconnect(); 2105 } catch (Exception e) {} 2106 } 2107 } 2108 2109 2110 2111 2115 public void destroy() 2116 { 2117 if (authConnection != null) 2118 { 2119 try 2120 { 2121 authConnection.disconnect(); 2122 } catch (Exception e) {} 2123 2124 authConnection = null; 2125 } 2126 2127 if (bindConnection != null) 2128 { 2129 try 2130 { 2131 bindConnection.disconnect(); 2132 } catch (Exception e) {} 2133 2134 bindConnection = null; 2135 } 2136 } 2137 2138 2139 2140 2145 public void finalizeClient() 2146 { 2147 if (useSharedConnections) 2149 { 2150 try 2151 { 2152 sharedAuthConnection.disconnect(); 2153 } catch (Exception e) {} 2154 2155 try 2156 { 2157 sharedBindConnection.disconnect(); 2158 } catch (Exception e) {} 2159 } 2160 } 2161 2162 2163 2164 2170 public String [] getLoginInfo() 2171 { 2172 String [] loginInfo = new String [2]; 2173 2174 if (useDataFile) 2175 { 2176 int slot = (random.nextInt() & 0x7FFFFFFF) % loginIDs.length; 2177 loginInfo[0] = loginIDs[slot]; 2178 loginInfo[1] = loginPasswords[slot]; 2179 } 2180 else 2181 { 2182 if (useLoginIDRange) 2183 { 2184 int value; 2185 if (useSequential) 2186 { 2187 value = sequentialCounter++; 2188 if (sequentialCounter > loginIDMax) 2189 { 2190 sequentialCounter = loginIDMax; 2191 } 2192 } 2193 else 2194 { 2195 value = ((random.nextInt() & 0x7FFFFFFF) % loginIDSpan) + loginIDMin; 2196 } 2197 2198 loginInfo[0] = loginIDInitial + value + loginIDFinal; 2199 loginInfo[1] = loginPassword; 2200 } 2201 else 2202 { 2203 loginInfo[0] = loginIDInitial; 2204 loginInfo[1] = loginPassword; 2205 } 2206 } 2207 2208 return loginInfo; 2209 } 2210 2211 2212 2213 2220 public String getRandomString(int length) 2221 { 2222 char[] returnArray = new char[length]; 2223 2224 for (int i=0; i < returnArray.length; i++) 2225 { 2226 returnArray[i] = ALPHABET[Math.abs((random.nextInt()) & 0x7FFFFFFF) % 2227 ALPHABET.length]; 2228 } 2229 2230 return new String (returnArray); 2231 } 2232} 2233 2234 | Popular Tags |