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 40 public class AuthRateJobClass 41 extends JobClass 42 { 43 46 public static final int MEMBERSHIP_TYPE_NONE = 0; 47 48 49 50 54 public static final int MEMBERSHIP_TYPE_STATIC = 1; 55 56 57 58 62 public static final int MEMBERSHIP_TYPE_DYNAMIC = 2; 63 64 65 66 70 public static final int MEMBERSHIP_TYPE_ROLE = 3; 71 72 73 74 77 public static final String DEFAULT_LOG_ID_ATTR = "uid"; 78 79 80 81 85 public static final String ROLE_ATTR = "nsRole"; 86 87 88 89 92 public static final String SSL_KEY_STORE_PROPERTY = 93 "javax.net.ssl.keyStore"; 94 95 96 97 100 public static final String SSL_KEY_PASSWORD_PROPERTY = 101 "javax.net.ssl.keyStorePassword"; 102 103 104 105 108 public static final String SSL_TRUST_STORE_PROPERTY = 109 "javax.net.ssl.trustStore"; 110 111 112 113 116 public static final String SSL_TRUST_PASSWORD_PROPERTY = 117 "javax.net.ssl.trustStorePassword"; 118 119 120 121 125 public static final String STAT_TRACKER_AUTHENTICATION_ATTEMPTS = 126 "Authentication Attempts"; 127 128 129 130 131 135 public static final String STAT_TRACKER_AUTHENTICATION_TIME = 136 "Authentication Time"; 137 138 139 140 141 145 public static final String STAT_TRACKER_FAILED_AUTHENTICATIONS = 146 "Failed Authentications"; 147 148 149 150 154 public static final String STAT_TRACKER_SUCCESSFUL_AUTHENTICATIONS = 155 "Successful Authentications"; 156 157 158 159 163 public static final String STAT_TRACKER_TOTAL_AUTHENTICATIONS = 164 "Total Authentication Attempts"; 165 166 167 168 172 public static final String [] NO_ATTRS = new String [] { "1.1" }; 173 174 175 176 static boolean blindTrust; 179 180 static boolean ignoreInvalidCredentials; 183 184 static boolean useDataFile; 187 188 static boolean useLoginIDRange; 190 191 static boolean useSequential; 193 194 static boolean useSSL; 196 197 static boolean useSharedConnections; 200 201 static int coolDownTime; 203 204 static int directoryPort; 206 207 static int loginIDMax; 209 210 static int loginIDMin; 212 213 static int loginIDSpan; 215 216 static int membershipType; 218 219 static int iterations; 221 222 static int sequentialCounter; 224 225 static int timeLimit; 228 229 static int warmUpTime; 231 232 static long delay; 234 235 static LDAPConnection sharedAuthConnection; 237 238 static LDAPConnection sharedBindConnection; 240 241 static Random parentRandom; 244 245 static String bindDN; 248 249 static String bindPW; 251 252 static String directoryHost; 254 255 static String loginIDAttr; 258 259 static String loginIDFinal; 261 262 static String loginIDInitial; 264 265 static String loginPassword; 267 268 static String membershipDN; 270 271 static String membershipURLBase; 273 274 static String membershipURLFilter; 276 277 static String readPassFromAttr; 280 281 static String searchBase; 284 285 static String sslKeyStore; 287 288 static String sslKeyPassword; 290 291 static String sslTrustStore; 293 294 static String sslTrustPassword; 296 297 static String [] loginIDs; 299 300 static String [] loginPasswords; 302 303 304 305 BooleanParameter blindTrustParameter = 307 new BooleanParameter("blind_trust", "Blindly Trust Any Certificate", 308 "Indicates whether the client should blindly trust " + 309 "any certificate presented by the server, or " + 310 "whether the key and trust stores should be used.", 311 true); 312 313 BooleanParameter ignoreInvCredParameter = 316 new BooleanParameter("ignore_49", "Ignore Invalid Credentials Errors", 317 "Indicates whether bind failures because of " + 318 "invalid credentials (err=49). This makes it " + 319 "possible to use this job without actually " + 320 "know user passwords.", false); 321 322 BooleanParameter shareConnsParameter = 324 new BooleanParameter("share_conns", "Share Connections between Threads", 325 "Indicates whether the connections to the " + 326 "directory server will be shared between threads " + 327 "or if each client thread will have its own " + 328 "connections.", true); 329 330 BooleanParameter useSSLParameter = 332 new BooleanParameter("usessl", "Use SSL", 333 "Indicates whether SSL should be used for all " + 334 "communication with the directory server", false); 335 336 FileURLParameter loginDataFileParameter = 338 new FileURLParameter("login_data_file", "Login Data File URL", 339 "The URL (FILE or HTTP) of the file containing " + 340 "the login IDs and passwords to use for the " + 341 "authentication.", null, false); 342 343 IntegerParameter coolDownParameter = 345 new IntegerParameter("cool_down", "Cool Down Time", 346 "The time in seconds that the job should " + 347 "continue searching after ending statistics " + 348 "collection.", true, 0, true, 0, false, 0); 349 350 IntegerParameter delayParameter = 353 new IntegerParameter("delay", "Time Between Authentications (ms)", 354 "Specifies the length of time in milliseconds " + 355 "each thread should wait between authentication " + 356 "attempts. Note that this delay will be " + 357 "between the starts of consecutive attempts and " + 358 "not between the end of one attempt and the " + 359 "beginning of the next. If an authentication " + 360 "takes longer than this length of time, then " + 361 "there will be no delay.", true, 0, true, 0, false, 362 0); 363 364 IntegerParameter iterationsParameter = 366 new IntegerParameter("num_iterations", "Number of Iterations", 367 "The number of authentications that should be " + 368 "performed by each thread", false, -1); 369 370 IntegerParameter portParameter = 372 new IntegerParameter("ldap_port", "Directory Server Port", 373 "The port number for the directory server.", true, 374 389, true, 1, true, 65535); 375 376 IntegerParameter timeLimitParameter = 379 new IntegerParameter("time_limit", "Operation Time Limit", 380 "The maximum length of time in seconds that any " + 381 "single LDAP operation will be allowed to take " + 382 "before it is cancelled.", true, 0, true, 0, false, 383 0); 384 385 IntegerParameter warmUpParameter = 387 new IntegerParameter("warm_up", "Warm Up Time", 388 "The time in seconds that the job should " + 389 "search before beginning statistics collection.", 390 true, 0, true, 0, false, 0); 391 392 PasswordParameter bindPWParameter = 394 new PasswordParameter("bindpw", "Directory Bind Password", 395 "The password to use when binding to the " + 396 "directory server to perform search and modify " + 397 "operations.", false, ""); 398 399 PasswordParameter loginPasswordParameter = 402 new PasswordParameter("login_id_pw", "Login Password", 403 "The password to use when authenticating to the " + 404 "directory for user authentications.", false, ""); 405 406 PasswordParameter keyPWParameter = 408 new PasswordParameter("sslkeypw", "SSL Key Store Password", 409 "The password for the JSSE key store", false, ""); 410 411 PasswordParameter trustPWParameter = 413 new PasswordParameter("ssltrustpw", "SSL Trust Store Password", 414 "The password for the JSSE trust store", false, ""); 415 416 PlaceholderParameter placeholder = new PlaceholderParameter(); 418 419 StringParameter bindDNParameter = 421 new StringParameter("binddn", "Directory Bind DN", 422 "The DN to use when binding to the directory " + 423 "server to perform search and modify operations.", 424 false, ""); 425 426 StringParameter hostParameter = 428 new StringParameter("ldap_host", "Directory Server Address", 429 "The address for the directory server.", true, ""); 430 431 StringParameter keyStoreParameter = 433 new StringParameter("sslkeystore", "SSL Key Store", 434 "The path to the JSSE key store to use for an " + 435 "SSL-based connection", false, ""); 436 437 StringParameter loginIDParameter = 439 new StringParameter("login_id_attr", "Login ID Attribute", 440 "The attribute to use as the login ID to find the " + 441 "user's entry.", true, DEFAULT_LOG_ID_ATTR); 442 443 StringParameter loginIDValueParameter = 445 new StringParameter("login_id_value", "Login ID Value", 446 "The text to use as the value of the login ID " + 447 "attribute in search filters. The value may " + 448 "contain a range of numbers in square brackets.", 449 false, ""); 450 451 StringParameter membershipDNParameter = 454 new StringParameter("membership_dn", "Membership DN", 455 "The DN of a static group, dynamic group, or role " + 456 "for which to determine whether the user is a " + 457 "member.", false, ""); 458 459 StringParameter readPassFromAttrParameter = 462 new StringParameter("read_pass_from_attr", 463 "Read Password from Attribute", 464 "The name of the LDAP attribute from which the " + 465 "user's password should be read, rather than " + 466 "using the same static password for every user.", 467 false, null); 468 469 470 StringParameter searchBaseParameter = 472 new StringParameter("search_base", "User Search Base", 473 "The DN in the directory server under which user " + 474 "entries may be found.", true, ""); 475 476 StringParameter trustStoreParameter = 478 new StringParameter("ssltruststore", "SSL Trust Store", 479 "The path to the JSSE trust store to use for an " + 480 "SSL-based connection", false, ""); 481 482 AccumulatingTracker totalAuths; 485 486 IncrementalTracker attemptCounter; 488 489 IncrementalTracker failureCounter; 491 492 IncrementalTracker successCounter; 494 495 LDAPConnection authConnection; 498 499 LDAPConnection bindConnection; 501 502 LDAPConstraints authConstraints; 504 505 LDAPConstraints bindConstraints; 507 508 LDAPSearchConstraints authSearchConstraints; 510 511 Random random; 513 514 TimeTracker authTimer; 516 517 518 519 523 public AuthRateJobClass() 524 { 525 super(); 526 } 527 528 529 530 536 public String getJobName() 537 { 538 return "LDAP Auth Rate"; 539 } 540 541 542 543 549 public String getJobDescription() 550 { 551 return "This job performs repeated authentications against an LDAP " + 552 "directory server, optionally including a lookup to verify that the " + 553 "user is a member of an indicated group or role."; 554 } 555 556 557 558 564 public String getJobCategoryName() 565 { 566 return "LDAP"; 567 } 568 569 570 571 576 public ParameterList getParameterStubs() 577 { 578 Parameter[] parameterArray = new Parameter[] 579 { 580 placeholder, 581 hostParameter, 582 portParameter, 583 bindDNParameter, 584 bindPWParameter, 585 placeholder, 586 searchBaseParameter, 587 loginDataFileParameter, 588 loginIDValueParameter, 589 loginPasswordParameter, 590 readPassFromAttrParameter, 591 loginIDParameter, 592 membershipDNParameter, 593 placeholder, 594 warmUpParameter, 595 coolDownParameter, 596 timeLimitParameter, 597 delayParameter, 598 placeholder, 599 useSSLParameter, 600 blindTrustParameter, 601 keyStoreParameter, 602 keyPWParameter, 603 trustStoreParameter, 604 trustPWParameter, 605 placeholder, 606 iterationsParameter, 607 ignoreInvCredParameter, 608 shareConnsParameter 609 }; 610 611 return new ParameterList(parameterArray); 612 } 613 614 615 616 638 public StatTracker[] getStatTrackerStubs(String clientID, String threadID, 639 int collectionInterval) 640 { 641 return new StatTracker[] 642 { 643 new IncrementalTracker(clientID, threadID, 644 STAT_TRACKER_AUTHENTICATION_ATTEMPTS, 645 collectionInterval), 646 new IncrementalTracker(clientID, threadID, 647 STAT_TRACKER_SUCCESSFUL_AUTHENTICATIONS, 648 collectionInterval), 649 new IncrementalTracker(clientID, threadID, 650 STAT_TRACKER_FAILED_AUTHENTICATIONS, 651 collectionInterval), 652 new TimeTracker(clientID, threadID, STAT_TRACKER_AUTHENTICATION_TIME, 653 collectionInterval) 654 }; 655 } 656 657 658 659 664 public StatTracker[] getStatTrackers() 665 { 666 return new StatTracker[] 667 { 668 attemptCounter, 669 successCounter, 670 failureCounter, 671 totalAuths, 672 authTimer 673 }; 674 } 675 676 677 678 700 public void validateJobInfo(int numClients, int threadsPerClient, 701 int threadStartupDelay, Date startTime, 702 Date stopTime, int duration, 703 int collectionInterval, ParameterList parameters) 704 throws InvalidValueException 705 { 706 FileURLParameter loginDataURLParameter = 707 parameters.getFileURLParameter(loginDataFileParameter.getName()); 708 if ((loginDataURLParameter == null) || 709 (! loginDataURLParameter.hasValue())) 710 { 711 StringParameter loginValueParameter = 712 parameters.getStringParameter(loginIDValueParameter.getName()); 713 PasswordParameter loginPWParameter = 714 parameters.getPasswordParameter(loginPasswordParameter.getName()); 715 StringParameter pwAttrParameter = 716 parameters.getStringParameter(readPassFromAttrParameter.getName()); 717 718 if ((loginValueParameter == null) || 719 (! loginValueParameter.hasValue())) 720 { 721 throw new InvalidValueException("If no login data file is provided, " + 722 "then you must provide a login ID " + 723 "value."); 724 } 725 726 if (((loginPWParameter == null) || (! loginPWParameter.hasValue())) && 727 ((pwAttrParameter == null) || (! pwAttrParameter.hasValue()))) 728 { 729 throw new InvalidValueException("If no login data file is provided, " + 730 "then you must provide a password " + 731 "or the name of an attribute from " + 732 "which to read the password."); 733 } 734 } 735 } 736 737 738 739 747 public boolean providesParameterTest() 748 { 749 return true; 750 } 751 752 753 754 781 public boolean testJobParameters(ParameterList parameters, 782 ArrayList outputMessages) 783 { 784 StringParameter hostParam = 786 parameters.getStringParameter(hostParameter.getName()); 787 if ((hostParam == null) || (! hostParam.hasValue())) 788 { 789 outputMessages.add("ERROR: No directory server address was provided."); 790 return false; 791 } 792 String host = hostParam.getStringValue(); 793 794 795 IntegerParameter portParam = 796 parameters.getIntegerParameter(portParameter.getName()); 797 if ((portParam == null) || (! hostParam.hasValue())) 798 { 799 outputMessages.add("ERROR: No directory server port was provided."); 800 return false; 801 } 802 int port = portParam.getIntValue(); 803 804 805 boolean useSSL = false; 806 BooleanParameter useSSLParam = 807 parameters.getBooleanParameter(useSSLParameter.getName()); 808 if (useSSLParam != null) 809 { 810 useSSL = useSSLParam.getBooleanValue(); 811 } 812 813 814 boolean blindTrust = true; 815 BooleanParameter blindTrustParam = 816 parameters.getBooleanParameter(blindTrustParameter.getName()); 817 if (blindTrustParam != null) 818 { 819 blindTrust = blindTrustParam.getBooleanValue(); 820 } 821 822 823 String keyStore = null; 824 StringParameter keyStoreParam = 825 parameters.getStringParameter(keyStoreParameter.getName()); 826 if ((keyStoreParam != null) && keyStoreParam.hasValue()) 827 { 828 keyStore = keyStoreParam.getStringValue(); 829 File keyStoreFile = new File(keyStore); 830 if (useSSL && (! blindTrust) && (! keyStoreFile.exists())) 831 { 832 outputMessages.add("WARNING: Key store file \"" + keyStore + 833 "\" not found on SLAMD server system. This test " + 834 "will blindly trust any SSL certificate " + 835 "presented by the directory server."); 836 outputMessages.add(""); 837 blindTrust = true; 838 } 839 else 840 { 841 System.setProperty(SSL_KEY_STORE_PROPERTY, keyStore); 842 } 843 } 844 845 846 String keyStorePassword = ""; 847 StringParameter keyPassParam = 848 parameters.getStringParameter(keyPWParameter.getName()); 849 if ((keyPassParam != null) && keyPassParam.hasValue()) 850 { 851 keyStorePassword = keyPassParam.getStringValue(); 852 System.setProperty(SSL_KEY_PASSWORD_PROPERTY, keyStorePassword); 853 } 854 855 856 String trustStore = null; 857 StringParameter trustStoreParam = 858 parameters.getStringParameter(trustStoreParameter.getName()); 859 if ((trustStoreParam != null) && trustStoreParam.hasValue()) 860 { 861 trustStore = trustStoreParam.getStringValue(); 862 File trustStoreFile = new File(trustStore); 863 if (useSSL && (! blindTrust) && (! trustStoreFile.exists())) 864 { 865 outputMessages.add("WARNING: trust store file \"" + trustStore + 866 "\" not found on SLAMD server system. This test " + 867 "will blindly trust any SSL certificate " + 868 "presented by the directory server."); 869 outputMessages.add(""); 870 blindTrust = true; 871 } 872 else 873 { 874 System.setProperty(SSL_TRUST_STORE_PROPERTY, trustStore); 875 } 876 } 877 878 879 String trustStorePassword = ""; 880 StringParameter trustPassParam = 881 parameters.getStringParameter(trustPWParameter.getName()); 882 if ((trustPassParam != null) && trustPassParam.hasValue()) 883 { 884 trustStorePassword = trustPassParam.getStringValue(); 885 System.setProperty(SSL_TRUST_PASSWORD_PROPERTY, trustStorePassword); 886 } 887 888 889 String bindDN = ""; 890 StringParameter bindDNParam = 891 parameters.getStringParameter(bindDNParameter.getName()); 892 if ((bindDNParam != null) && bindDNParam.hasValue()) 893 { 894 bindDN = bindDNParam.getStringValue(); 895 } 896 897 898 String bindPassword = ""; 899 PasswordParameter bindPWParam = 900 parameters.getPasswordParameter(bindPWParameter.getName()); 901 if ((bindPWParam != null) && bindPWParam.hasValue()) 902 { 903 bindPassword = bindPWParam.getStringValue(); 904 } 905 906 907 StringParameter baseDNParam = 908 parameters.getStringParameter(searchBaseParameter.getName()); 909 if ((baseDNParam == null) || (! baseDNParam.hasValue())) 910 { 911 outputMessages.add("ERROR: No base DN was provided."); 912 return false; 913 } 914 String baseDN = baseDNParam.getStringValue(); 915 916 917 LDAPConnection conn; 920 if (useSSL) 921 { 922 if (blindTrust) 923 { 924 try 925 { 926 conn = new LDAPConnection(new JSSEBlindTrustSocketFactory()); 927 } 928 catch (Exception e) 929 { 930 outputMessages.add("ERROR: Unable to instantiate the blind trust " + 931 "socket factory for use in creating the SSL " + 932 "connection: " + stackTraceToString(e)); 933 return false; 934 } 935 } 936 else 937 { 938 conn = new LDAPConnection(new JSSESocketFactory(null)); 939 } 940 } 941 else 942 { 943 conn = new LDAPConnection(); 944 } 945 946 947 try 949 { 950 if (useSSL) 951 { 952 outputMessages.add("Attempting to establish an SSL-based connection " + 953 "to " + host + ":" + port + "...."); 954 } 955 else 956 { 957 outputMessages.add("Attempting to establish a connection to " + host + 958 ":" + port + "...."); 959 } 960 conn.connect(host, port); 961 outputMessages.add("Connected successfully."); 962 outputMessages.add(""); 963 } 964 catch (Exception e) 965 { 966 outputMessages.add("ERROR: Unable to connect to the directory " + 967 "server: " + stackTraceToString(e)); 968 return false; 969 } 970 971 972 try 974 { 975 outputMessages.add("Attempting to perform an LDAPv3 bind to the " + 976 "directory server with a DN of '" + bindDN + "'...."); 977 conn.bind(3, bindDN, bindPassword); 978 outputMessages.add("Bound successfully."); 979 outputMessages.add(""); 980 } 981 catch (Exception e) 982 { 983 try 984 { 985 conn.disconnect(); 986 } catch (Exception e2) {} 987 988 outputMessages.add("ERROR: Unable to bind to the directory server: " + 989 stackTraceToString(e)); 990 return false; 991 } 992 993 994 try 996 { 997 outputMessages.add("Checking to make sure that the base DN entry '" + 998 baseDN + "' exists in the directory...."); 999 LDAPEntry baseDNEntry = conn.read(baseDN, new String [] { "1.1" }); 1000 if (baseDNEntry == null) 1001 { 1002 try 1003 { 1004 conn.disconnect(); 1005 } catch (Exception e2) {} 1006 1007 outputMessages.add("ERROR: Unable to retrieve the base DN entry."); 1008 return false; 1009 } 1010 else 1011 { 1012 outputMessages.add("Successfully read the base DN entry."); 1013 outputMessages.add(""); 1014 } 1015 } 1016 catch (Exception e) 1017 { 1018 try 1019 { 1020 conn.disconnect(); 1021 } catch (Exception e2) {} 1022 1023 outputMessages.add("ERROR: Unable to retrieve the base DN entry: " + 1024 stackTraceToString(e)); 1025 return false; 1026 } 1027 1028 1029 try 1032 { 1033 conn.disconnect(); 1034 } catch (Exception e) {} 1035 1036 outputMessages.add("All tests completed successfully."); 1037 return true; 1038 } 1039 1040 1041 1042 1054 public void initializeClient(String clientID, ParameterList parameters) 1055 throws UnableToRunException 1056 { 1057 hostParameter = parameters.getStringParameter(hostParameter.getName()); 1059 if (hostParameter == null) 1060 { 1061 throw new UnableToRunException("No directory server host provided."); 1062 } 1063 else 1064 { 1065 directoryHost = hostParameter.getStringValue(); 1066 } 1067 1068 1069 portParameter = parameters.getIntegerParameter(portParameter.getName()); 1071 if (portParameter != null) 1072 { 1073 directoryPort = portParameter.getIntValue(); 1074 } 1075 1076 bindDNParameter = parameters.getStringParameter(bindDNParameter.getName()); 1078 if (bindDNParameter == null) 1079 { 1080 bindDN = ""; 1081 } 1082 else 1083 { 1084 bindDN = bindDNParameter.getStringValue(); 1085 } 1086 1087 bindPWParameter = 1089 parameters.getPasswordParameter(bindPWParameter.getName()); 1090 if (bindPWParameter == null) 1091 { 1092 bindPW = ""; 1093 } 1094 else 1095 { 1096 bindPW = bindPWParameter.getStringValue(); 1097 } 1098 1099 searchBaseParameter = 1101 parameters.getStringParameter(searchBaseParameter.getName()); 1102 if (searchBaseParameter != null) 1103 { 1104 searchBase = searchBaseParameter.getStringValue(); 1105 } 1106 1107 1108 useDataFile = false; 1110 loginDataFileParameter = 1111 parameters.getFileURLParameter(loginDataFileParameter.getName()); 1112 if ((loginDataFileParameter != null) && (loginDataFileParameter.hasValue())) 1113 { 1114 String [] fileLines; 1115 try 1116 { 1117 fileLines = loginDataFileParameter.getNonBlankFileLines(); 1118 } 1119 catch (Exception e) 1120 { 1121 throw new UnableToRunException("Unable to retrieve the login data " + 1122 "from the file: " + e, e); 1123 } 1124 1125 ArrayList loginIDList = new ArrayList(fileLines.length); 1127 ArrayList passwordList = new ArrayList(fileLines.length); 1128 for (int i=0; i < fileLines.length; i++) 1129 { 1130 try 1131 { 1132 StringTokenizer tokenizer = new StringTokenizer(fileLines[i], "\t"); 1133 String loginID = tokenizer.nextToken(); 1134 String password = tokenizer.nextToken(); 1135 loginIDList.add(loginID); 1136 passwordList.add(password); 1137 } catch (Exception e) {} 1138 } 1139 1140 loginIDs = new String [loginIDList.size()]; 1143 loginPasswords = new String [passwordList.size()]; 1144 loginIDList.toArray(loginIDs); 1145 passwordList.toArray(loginPasswords); 1146 if (loginIDs.length == 0) 1147 { 1148 throw new UnableToRunException("No login IDs/passwords extracted from " + 1149 "the login data file."); 1150 } 1151 1152 useDataFile = true; 1153 } 1154 else 1155 { 1156 loginPasswordParameter = 1157 parameters.getPasswordParameter(loginPasswordParameter.getName()); 1158 if ((loginPasswordParameter != null) && 1159 (loginPasswordParameter.hasValue())) 1160 { 1161 loginPassword = loginPasswordParameter.getStringValue(); 1162 } 1163 1164 loginIDValueParameter = 1165 parameters.getStringParameter(loginIDValueParameter.getName()); 1166 useLoginIDRange = true; 1167 useSequential = false; 1168 String loginIDValue = loginIDValueParameter.getStringValue(); 1169 try 1170 { 1171 int openPos = loginIDValue.indexOf('['); 1172 int closePos = loginIDValue.indexOf(']', openPos); 1173 loginIDInitial = loginIDValue.substring(0, openPos); 1174 loginIDFinal = loginIDValue.substring(closePos+1); 1175 1176 int dashPos = loginIDValue.indexOf('-', openPos); 1177 if (dashPos < 0) 1178 { 1179 dashPos = loginIDValue.indexOf(':', openPos); 1180 useSequential = true; 1181 } 1182 loginIDMin = Integer.parseInt(loginIDValue.substring(openPos+1, 1183 dashPos)); 1184 loginIDMax = Integer.parseInt(loginIDValue.substring(dashPos+1, 1185 closePos)); 1186 loginIDSpan = loginIDMax - loginIDMin + 1; 1187 sequentialCounter = loginIDMin; 1188 } 1189 catch (Exception e) 1190 { 1191 useLoginIDRange = false; 1192 loginIDInitial = loginIDValue; 1193 } 1194 } 1195 1196 readPassFromAttr = null; 1198 readPassFromAttrParameter = 1199 parameters.getStringParameter(readPassFromAttrParameter.getName()); 1200 if (readPassFromAttrParameter != null) 1201 { 1202 readPassFromAttr = readPassFromAttrParameter.getStringValue(); 1203 } 1204 1205 loginIDParameter = 1207 parameters.getStringParameter(loginIDParameter.getName()); 1208 if (loginIDParameter != null) 1209 { 1210 loginIDAttr = loginIDParameter.getStringValue(); 1211 } 1212 1213 membershipDNParameter = 1215 parameters.getStringParameter(membershipDNParameter.getName()); 1216 if ((membershipDNParameter != null) && (membershipDNParameter.hasValue())) 1217 { 1218 membershipDN = membershipDNParameter.getStringValue(); 1219 } 1220 else 1221 { 1222 membershipDN = null; 1223 } 1224 1225 warmUpTime = 0; 1227 warmUpParameter = parameters.getIntegerParameter(warmUpParameter.getName()); 1228 if (warmUpParameter != null) 1229 { 1230 warmUpTime = warmUpParameter.getIntValue(); 1231 } 1232 1233 coolDownTime = 0; 1235 coolDownParameter = 1236 parameters.getIntegerParameter(coolDownParameter.getName()); 1237 if (coolDownParameter != null) 1238 { 1239 coolDownTime = coolDownParameter.getIntValue(); 1240 } 1241 1242 timeLimitParameter = 1244 parameters.getIntegerParameter(timeLimitParameter.getName()); 1245 if (timeLimitParameter != null) 1246 { 1247 timeLimit = timeLimitParameter.getIntValue(); 1248 } 1249 1250 delay = 0; 1252 delayParameter = parameters.getIntegerParameter(delayParameter.getName()); 1253 if (delayParameter != null) 1254 { 1255 delay = delayParameter.getIntValue(); 1256 } 1257 1258 useSSL = false; 1260 useSSLParameter = parameters.getBooleanParameter(useSSLParameter.getName()); 1261 if (useSSLParameter != null) 1262 { 1263 useSSL = useSSLParameter.getBooleanValue(); 1264 } 1265 1266 if (useSSL) 1268 { 1269 blindTrustParameter = 1271 parameters.getBooleanParameter(blindTrustParameter.getName()); 1272 if (blindTrustParameter != null) 1273 { 1274 blindTrust = blindTrustParameter.getBooleanValue(); 1275 } 1276 1277 sslKeyStore = null; 1279 keyStoreParameter = 1280 parameters.getStringParameter(keyStoreParameter.getName()); 1281 if ((keyStoreParameter != null) && (keyStoreParameter.hasValue())) 1282 { 1283 sslKeyStore = keyStoreParameter.getStringValue(); 1284 System.setProperty(SSL_KEY_STORE_PROPERTY, sslKeyStore); 1285 } 1286 1287 sslKeyPassword = null; 1289 keyPWParameter = 1290 parameters.getPasswordParameter(keyPWParameter.getName()); 1291 if ((keyPWParameter != null) && (keyPWParameter.hasValue())) 1292 { 1293 sslKeyPassword = keyPWParameter.getStringValue(); 1294 System.setProperty(SSL_KEY_PASSWORD_PROPERTY, sslKeyPassword); 1295 } 1296 1297 sslTrustStore = null; 1299 trustStoreParameter = 1300 parameters.getStringParameter(trustStoreParameter.getName()); 1301 if ((trustStoreParameter != null) && (trustStoreParameter.hasValue())) 1302 { 1303 sslTrustStore = trustStoreParameter.getStringValue(); 1304 System.setProperty(SSL_TRUST_STORE_PROPERTY, sslTrustStore); 1305 } 1306 1307 sslTrustPassword = null; 1309 trustPWParameter = 1310 parameters.getPasswordParameter(trustPWParameter.getName()); 1311 if ((trustPWParameter != null) && (trustPWParameter.hasValue())) 1312 { 1313 sslTrustPassword = trustPWParameter.getStringValue(); 1314 System.setProperty(SSL_TRUST_PASSWORD_PROPERTY, sslTrustPassword); 1315 } 1316 } 1317 1318 1319 iterations = -1; 1321 iterationsParameter = 1322 parameters.getIntegerParameter(iterationsParameter.getName()); 1323 if ((iterationsParameter != null) && (iterationsParameter.hasValue())) 1324 { 1325 iterations = iterationsParameter.getIntValue(); 1326 } 1327 1328 1329 ignoreInvCredParameter = 1332 parameters.getBooleanParameter(ignoreInvCredParameter.getName()); 1333 if (ignoreInvCredParameter != null) 1334 { 1335 ignoreInvalidCredentials = ignoreInvCredParameter.getBooleanValue(); 1336 } 1337 1338 shareConnsParameter = 1340 parameters.getBooleanParameter(shareConnsParameter.getName()); 1341 if (shareConnsParameter != null) 1342 { 1343 useSharedConnections = shareConnsParameter.getBooleanValue(); 1344 } 1345 1346 1347 if (useSharedConnections) 1349 { 1350 if (useSSL) 1351 { 1352 if (blindTrust) 1353 { 1354 try 1355 { 1356 sharedAuthConnection = 1357 new LDAPConnection(new JSSEBlindTrustSocketFactory()); 1358 sharedBindConnection = 1359 new LDAPConnection(new JSSEBlindTrustSocketFactory()); 1360 } 1361 catch (LDAPException le) 1362 { 1363 throw new UnableToRunException(le.getMessage(), le); 1364 } 1365 } 1366 else 1367 { 1368 sharedAuthConnection = 1369 new LDAPConnection(new JSSESocketFactory(null)); 1370 sharedBindConnection = 1371 new LDAPConnection(new JSSESocketFactory(null)); 1372 } 1373 } 1374 else 1375 { 1376 sharedAuthConnection = new LDAPConnection(); 1377 sharedBindConnection = new LDAPConnection(); 1378 } 1379 1380 try 1381 { 1382 sharedAuthConnection.connect(3, directoryHost, directoryPort, bindDN, 1383 bindPW); 1384 sharedBindConnection.connect(3, directoryHost, directoryPort, "", ""); 1385 } 1386 catch (Exception e) 1387 { 1388 throw new UnableToRunException("Could not establish shared " + 1389 "connections to the directory: " + e, 1390 e); 1391 } 1392 } 1393 1394 1395 membershipType = MEMBERSHIP_TYPE_NONE; 1398 if (membershipDN != null) 1399 { 1400 LDAPConnection conn = null; 1402 if (useSharedConnections) 1403 { 1404 conn = sharedAuthConnection; 1405 } 1406 else 1407 { 1408 try 1409 { 1410 if (useSSL) 1411 { 1412 if (blindTrust) 1413 { 1414 conn = new LDAPConnection(new JSSEBlindTrustSocketFactory()); 1415 } 1416 else 1417 { 1418 conn = new LDAPConnection(new JSSESocketFactory(null)); 1419 } 1420 } 1421 else 1422 { 1423 conn = new LDAPConnection(); 1424 } 1425 conn.connect(3, directoryHost, directoryPort, bindDN, bindPW); 1426 } 1427 catch (Exception e) 1428 { 1429 throw new UnableToRunException("Could not connect to directory " + 1430 "server " + directoryHost + ":" + 1431 directoryPort + 1432 " to retrieve membership entry.", e); 1433 } 1434 } 1435 1436 String [] attrsToReturn = new String [] { "objectClass", "memberURL" }; 1438 LDAPEntry entry = null; 1439 try 1440 { 1441 entry = conn.read(membershipDN, attrsToReturn); 1442 } 1443 catch (Exception e) {} 1444 1445 if (entry == null) 1446 { 1447 try 1448 { 1449 conn.disconnect(); 1450 } catch (Exception e) {} 1451 throw new UnableToRunException("Could not retrieve the membership " + 1452 "entry '" + membershipDN + "' from " + 1453 "directory " + directoryHost + ":" + 1454 directoryPort + "."); 1455 } 1456 1457 LDAPAttribute ocAttr = entry.getAttribute("objectClass"); 1459 String [] ocValues = null; 1460 if ((ocAttr == null) || 1461 ((ocValues = ocAttr.getStringValueArray()) == null) || 1462 (ocValues.length == 0)) 1463 { 1464 try 1465 { 1466 conn.disconnect(); 1467 } catch (Exception e) {} 1468 throw new UnableToRunException("Could not retrieve objectclass " + 1469 "values from '" + membershipDN + "'"); 1470 } 1471 1472 for (int i=0; i < ocValues.length; i++) 1473 { 1474 if (ocValues[i].equalsIgnoreCase("groupOfNames") || 1475 ocValues[i].equalsIgnoreCase("groupOfUniqueNames")) 1476 { 1477 membershipType = MEMBERSHIP_TYPE_STATIC; 1478 break; 1479 } 1480 else if (ocValues[i].equalsIgnoreCase("groupOfURLs")) 1481 { 1482 LDAPAttribute urlAttr = entry.getAttribute("memberURL"); 1483 String [] urlValues = null; 1484 if ((urlAttr == null) || 1485 ((urlValues = urlAttr.getStringValueArray()) == null) || 1486 (urlValues.length == 0)) 1487 { 1488 try 1489 { 1490 conn.disconnect(); 1491 } catch (Exception e) {} 1492 1493 throw new UnableToRunException("Could not retrieve memberURL " + 1494 "from dynamic group entry " + 1495 membershipDN); 1496 } 1497 1498 try 1499 { 1500 LDAPUrl url = new LDAPUrl(urlValues[0]); 1501 membershipURLBase = LDAPDN.normalize(url.getDN()); 1502 membershipURLFilter = url.getFilter(); 1503 } 1504 catch (Exception e) 1505 { 1506 try 1507 { 1508 conn.disconnect(); 1509 } catch (Exception e2) {} 1510 1511 throw new UnableToRunException("Could not interpret " + 1512 urlValues[0] + " as an LDAP URL", e); 1513 } 1514 1515 membershipType = MEMBERSHIP_TYPE_DYNAMIC; 1516 break; 1517 } 1518 else if (ocValues[i].toLowerCase().indexOf("role") >= 0) 1519 { 1520 membershipType = MEMBERSHIP_TYPE_ROLE; 1521 membershipDN = LDAPDN.normalize(membershipDN); 1522 break; 1523 } 1524 } 1525 1526 if (membershipType == MEMBERSHIP_TYPE_NONE) 1527 { 1528 throw new UnableToRunException("Could not determine the membership " + 1529 "type to check for entry " + 1530 membershipDN); 1531 } 1532 1533 if (! useSharedConnections) 1534 { 1535 try 1536 { 1537 conn.disconnect(); 1538 } catch (Exception e) {} 1539 } 1540 } 1541 1542 parentRandom = new Random(); 1544 } 1545 1546 1547 1548 1564 public void initializeThread(String clientID, String threadID, 1565 int collectionInterval, ParameterList parameters) 1566 throws UnableToRunException 1567 { 1568 random = new Random(parentRandom.nextLong()); 1570 1571 if (useSharedConnections) 1575 { 1576 authConnection = sharedAuthConnection; 1577 bindConnection = sharedBindConnection; 1578 } 1579 else 1580 { 1581 if (useSSL) 1582 { 1583 if (blindTrust) 1584 { 1585 try 1586 { 1587 authConnection = 1588 new LDAPConnection(new JSSEBlindTrustSocketFactory()); 1589 bindConnection = 1590 new LDAPConnection(new JSSEBlindTrustSocketFactory()); 1591 } 1592 catch (LDAPException le) 1593 { 1594 throw new UnableToRunException(le.getMessage(), le); 1595 } 1596 } 1597 else 1598 { 1599 authConnection = new LDAPConnection(new JSSESocketFactory(null)); 1600 bindConnection = new LDAPConnection(new JSSESocketFactory(null)); 1601 } 1602 } 1603 else 1604 { 1605 authConnection = new LDAPConnection(); 1606 bindConnection = new LDAPConnection(); 1607 } 1608 1609 try 1610 { 1611 authConnection.connect(3, directoryHost, directoryPort, bindDN, bindPW); 1612 bindConnection.connect(3, directoryHost, directoryPort, "", ""); 1613 } 1614 catch (Exception e) 1615 { 1616 throw new UnableToRunException("Unable to establish the connections " + 1617 "to the directory server: " + e, e); 1618 } 1619 } 1620 1621 authConstraints = authConnection.getConstraints(); 1623 bindConstraints = bindConnection.getConstraints(); 1624 authSearchConstraints = authConnection.getSearchConstraints(); 1625 authConstraints.setTimeLimit(1000*timeLimit); 1626 bindConstraints.setTimeLimit(1000*timeLimit); 1627 authSearchConstraints.setTimeLimit(1000*timeLimit); 1628 authSearchConstraints.setServerTimeLimit(timeLimit); 1629 1630 1631 attemptCounter = 1633 new IncrementalTracker(clientID, threadID, 1634 STAT_TRACKER_AUTHENTICATION_ATTEMPTS, 1635 collectionInterval); 1636 successCounter = 1637 new IncrementalTracker(clientID, threadID, 1638 STAT_TRACKER_SUCCESSFUL_AUTHENTICATIONS, 1639 collectionInterval); 1640 failureCounter = 1641 new IncrementalTracker(clientID, threadID, 1642 STAT_TRACKER_FAILED_AUTHENTICATIONS, 1643 collectionInterval); 1644 totalAuths = new AccumulatingTracker(clientID, threadID, 1645 STAT_TRACKER_TOTAL_AUTHENTICATIONS, 1646 collectionInterval); 1647 authTimer = new TimeTracker(clientID, threadID, 1648 STAT_TRACKER_AUTHENTICATION_TIME, 1649 collectionInterval); 1650 1651 1652 RealTimeStatReporter statReporter = getStatReporter(); 1654 if (statReporter != null) 1655 { 1656 String jobID = getJobID(); 1657 attemptCounter.enableRealTimeStats(statReporter, jobID); 1658 successCounter.enableRealTimeStats(statReporter, jobID); 1659 failureCounter.enableRealTimeStats(statReporter, jobID); 1660 totalAuths.enableRealTimeStats(statReporter, jobID); 1661 authTimer.enableRealTimeStats(statReporter, jobID); 1662 } 1663 } 1664 1665 1666 1667 1671 public void runJob() 1672 { 1673 long currentTime = System.currentTimeMillis(); 1675 boolean collectingStats = false; 1676 long startCollectingTime = currentTime + (1000 * warmUpTime); 1677 long stopCollectingTime = Long.MAX_VALUE; 1678 if ((coolDownTime > 0) && (getShouldStopTime() > 0)) 1679 { 1680 stopCollectingTime = getShouldStopTime() - (1000 * coolDownTime); 1681 } 1682 1683 long authStartTime = 0; 1686 1687 boolean infinite = (iterations <= 0); 1690 1691 for (int i=0; ((! shouldStop()) && ((infinite || (i < iterations)))); i++) 1693 { 1694 currentTime = System.currentTimeMillis(); 1695 if ((! collectingStats) && (currentTime >= startCollectingTime) && 1696 (currentTime < stopCollectingTime)) 1697 { 1698 attemptCounter.startTracker(); 1700 totalAuths.startTracker(); 1701 successCounter.startTracker(); 1702 failureCounter.startTracker(); 1703 authTimer.startTracker(); 1704 collectingStats = true; 1705 } 1706 else if ((collectingStats) && (currentTime >= stopCollectingTime)) 1707 { 1708 attemptCounter.stopTracker(); 1709 totalAuths.stopTracker(); 1710 successCounter.stopTracker(); 1711 failureCounter.stopTracker(); 1712 authTimer.stopTracker(); 1713 collectingStats = false; 1714 } 1715 1716 if ((delay > 0) && (authStartTime > 0)) 1718 { 1719 long now = System.currentTimeMillis(); 1720 long sleepTime = delay - (now - authStartTime); 1721 if (sleepTime > 0) 1722 { 1723 try 1724 { 1725 Thread.sleep(sleepTime); 1726 } catch (InterruptedException ie) {} 1727 1728 if (shouldStop()) 1729 { 1730 break; 1731 } 1732 } 1733 } 1734 1735 String [] loginInfo = getLoginInfo(); 1737 String loginID = loginInfo[0]; 1738 String password = loginInfo[1]; 1739 1740 1741 if (delay > 0) 1743 { 1744 authStartTime = System.currentTimeMillis(); 1745 } 1746 1747 1748 if (collectingStats) 1750 { 1751 attemptCounter.increment(); 1752 totalAuths.increment(); 1753 authTimer.startTimer(); 1754 } 1755 1756 String [] attrsToReturn; 1758 if ((membershipDN == null) || (membershipType != MEMBERSHIP_TYPE_ROLE)) 1759 { 1760 if ((readPassFromAttr == null) || (readPassFromAttr.length() == 0)) 1761 { 1762 attrsToReturn = NO_ATTRS; 1763 } 1764 else 1765 { 1766 attrsToReturn = new String [] { readPassFromAttr }; 1767 } 1768 } 1769 else 1770 { 1771 if ((readPassFromAttr == null) || (readPassFromAttr.length() == 0)) 1772 { 1773 attrsToReturn = new String [] { ROLE_ATTR }; 1774 } 1775 else 1776 { 1777 attrsToReturn = new String [] { ROLE_ATTR, readPassFromAttr }; 1778 } 1779 } 1780 1781 String filter = "(" + loginIDAttr + "=" + loginID + ")"; 1782 LDAPSearchResults results; 1783 LDAPEntry userEntry = null; 1784 try 1785 { 1786 results = authConnection.search(searchBase, LDAPConnection.SCOPE_SUB, 1787 filter, attrsToReturn, false, 1788 authSearchConstraints); 1789 while (results.hasMoreElements()) 1790 { 1791 Object element = results.nextElement(); 1792 if (element instanceof LDAPEntry) 1793 { 1794 userEntry = (LDAPEntry) element; 1795 } 1796 } 1797 } 1798 catch (LDAPException le) 1799 { 1800 if (collectingStats) 1802 { 1803 failureCounter.increment(); 1804 authTimer.stopTimer(); 1805 } 1806 continue; 1807 } 1808 1809 1810 if (userEntry == null) 1812 { 1813 if (collectingStats) 1814 { 1815 failureCounter.increment(); 1816 authTimer.stopTimer(); 1817 } 1818 continue; 1819 } 1820 1821 1822 if ((readPassFromAttr != null) && (readPassFromAttr.length() > 0)) 1825 { 1826 LDAPAttribute attr = userEntry.getAttribute(readPassFromAttr); 1827 if (attr == null) 1828 { 1829 if (collectingStats) 1830 { 1831 failureCounter.increment(); 1832 authTimer.stopTimer(); 1833 } 1834 continue; 1835 } 1836 else 1837 { 1838 String [] values = attr.getStringValueArray(); 1839 if ((values == null) || (values.length == 0)) 1840 { 1841 if (collectingStats) 1842 { 1843 failureCounter.increment(); 1844 authTimer.stopTimer(); 1845 } 1846 continue; 1847 } 1848 else 1849 { 1850 password = values[0]; 1851 } 1852 } 1853 } 1854 1855 1856 try 1859 { 1860 bindConnection.authenticate(3, userEntry.getDN(), password); 1861 } 1862 catch (LDAPException le) 1863 { 1864 if (! (ignoreInvalidCredentials && 1865 (le.getLDAPResultCode() == LDAPException.INVALID_CREDENTIALS))) 1866 { 1867 if (collectingStats) 1868 { 1869 failureCounter.increment(); 1870 authTimer.stopTimer(); 1871 } 1872 continue; 1873 } 1874 } 1875 1876 1877 if (membershipDN != null) 1879 { 1880 if (isMember(userEntry)) 1881 { 1882 if (collectingStats) 1883 { 1884 successCounter.increment(); 1885 authTimer.stopTimer(); 1886 } 1887 } 1888 else 1889 { 1890 if (collectingStats) 1891 { 1892 failureCounter.increment(); 1893 authTimer.stopTimer(); 1894 } 1895 } 1896 } 1897 else 1898 { 1899 if (collectingStats) 1900 { 1901 successCounter.increment(); 1902 authTimer.stopTimer(); 1903 } 1904 } 1905 } 1906 1907 1908 1909 if (collectingStats) 1911 { 1912 attemptCounter.stopTracker(); 1913 totalAuths.stopTracker(); 1914 successCounter.stopTracker(); 1915 failureCounter.stopTracker(); 1916 authTimer.stopTracker(); 1917 } 1918 1919 1920 if (! useSharedConnections) 1922 { 1923 try 1924 { 1925 authConnection.disconnect(); 1926 } catch (Exception e) {} 1927 1928 try 1929 { 1930 bindConnection.disconnect(); 1931 } catch (Exception e) {} 1932 } 1933 } 1934 1935 1936 1937 1941 public void destroy() 1942 { 1943 if (authConnection != null) 1944 { 1945 try 1946 { 1947 authConnection.disconnect(); 1948 } catch (Exception e) {} 1949 1950 authConnection = null; 1951 } 1952 1953 if (bindConnection != null) 1954 { 1955 try 1956 { 1957 bindConnection.disconnect(); 1958 } catch (Exception e) {} 1959 1960 bindConnection = null; 1961 } 1962 } 1963 1964 1965 1966 1971 public void finalizeClient() 1972 { 1973 if (useSharedConnections) 1975 { 1976 try 1977 { 1978 sharedAuthConnection.disconnect(); 1979 } catch (Exception e) {} 1980 1981 try 1982 { 1983 sharedBindConnection.disconnect(); 1984 } catch (Exception e) {} 1985 } 1986 } 1987 1988 1989 1990 1998 public boolean isMember(LDAPEntry userEntry) 1999 { 2000 switch (membershipType) 2001 { 2002 case MEMBERSHIP_TYPE_STATIC: 2003 String userDN = userEntry.getDN(); 2004 String filter = "(|(&(objectclass=groupOfNames)(member=" + userDN + 2005 "))(&(objectClass=groupOfUniqueNames)(uniqueMember=" + 2006 userDN + ")))"; 2007 try 2008 { 2009 LDAPSearchResults results = 2010 authConnection.search(membershipDN, LDAPConnection.SCOPE_BASE, 2011 filter, NO_ATTRS, false); 2012 while (results.hasMoreElements()) 2013 { 2014 Object element = results.nextElement(); 2015 if (element instanceof LDAPEntry) 2016 { 2017 return true; 2018 } 2019 } 2020 2021 return false; 2022 } 2023 catch (Exception e) 2024 { 2025 return false; 2026 } 2027 case MEMBERSHIP_TYPE_DYNAMIC: 2028 userDN = LDAPDN.normalize(userEntry.getDN()); 2029 if (! userDN.endsWith(membershipURLBase)) 2030 { 2031 return false; 2032 } 2033 2034 try 2035 { 2036 LDAPSearchResults results = 2037 authConnection.search(userDN, LDAPConnection.SCOPE_BASE, 2038 membershipURLFilter, NO_ATTRS, false); 2039 while (results.hasMoreElements()) 2040 { 2041 Object element = results.nextElement(); 2042 if (element instanceof LDAPEntry) 2043 { 2044 return true; 2045 } 2046 } 2047 2048 return false; 2049 } 2050 catch (Exception e) 2051 { 2052 return false; 2053 } 2054 case MEMBERSHIP_TYPE_ROLE: 2055 LDAPAttribute roleAttr = userEntry.getAttribute(ROLE_ATTR); 2056 String [] roleValues = null; 2057 if ((roleAttr == null) || 2058 ((roleValues = roleAttr.getStringValueArray()) == null) || 2059 (roleValues.length == 0)) 2060 { 2061 return false; 2062 } 2063 2064 for (int i=0; i < roleValues.length; i++) 2065 { 2066 String roleDN = LDAPDN.normalize(roleValues[i]); 2067 if (roleDN.equals(membershipDN)) 2068 { 2069 return true; 2070 } 2071 } 2072 2073 return false; 2074 } 2075 2076 2077 return false; 2078 } 2079 2080 2081 2082 2088 public String [] getLoginInfo() 2089 { 2090 String [] loginInfo = new String [2]; 2091 2092 if (useDataFile) 2093 { 2094 int slot = (random.nextInt() & 0x7FFFFFFF) % loginIDs.length; 2095 loginInfo[0] = loginIDs[slot]; 2096 loginInfo[1] = loginPasswords[slot]; 2097 } 2098 else 2099 { 2100 if (useLoginIDRange) 2101 { 2102 int value; 2103 if (useSequential) 2104 { 2105 value = sequentialCounter++; 2106 if (sequentialCounter > loginIDMax) 2107 { 2108 sequentialCounter = loginIDMin; 2109 } 2110 } 2111 else 2112 { 2113 value = ((random.nextInt() & 0x7FFFFFFF) % loginIDSpan) + loginIDMin; 2114 } 2115 loginInfo[0] = loginIDInitial + value + loginIDFinal; 2116 loginInfo[1] = loginPassword; 2117 } 2118 else 2119 { 2120 loginInfo[0] = loginIDInitial; 2121 loginInfo[1] = loginPassword; 2122 } 2123 } 2124 2125 return loginInfo; 2126 } 2127} 2128 2129 | Popular Tags |