1 17 18 package org.apache.catalina.realm; 19 20 import java.io.IOException ; 21 import java.security.Principal ; 22 import java.text.MessageFormat ; 23 import java.util.ArrayList ; 24 import java.util.Arrays ; 25 import java.util.Hashtable ; 26 import java.util.List ; 27 28 import javax.naming.Context ; 29 import javax.naming.CommunicationException ; 30 import javax.naming.CompositeName ; 31 import javax.naming.InvalidNameException ; 32 import javax.naming.NameNotFoundException ; 33 import javax.naming.NamingEnumeration ; 34 import javax.naming.NamingException ; 35 import javax.naming.NameParser ; 36 import javax.naming.Name ; 37 import javax.naming.AuthenticationException ; 38 import javax.naming.directory.Attribute ; 39 import javax.naming.directory.Attributes ; 40 import javax.naming.directory.DirContext ; 41 import javax.naming.directory.InitialDirContext ; 42 import javax.naming.directory.SearchControls ; 43 import javax.naming.directory.SearchResult ; 44 import org.apache.catalina.LifecycleException; 45 import org.apache.catalina.util.Base64; 46 import org.apache.tomcat.util.buf.ByteChunk; 47 import org.apache.tomcat.util.buf.CharChunk; 48 49 155 156 public class JNDIRealm extends RealmBase { 157 158 159 161 164 protected String authentication = null; 165 166 169 protected String connectionName = null; 170 171 172 175 protected String connectionPassword = null; 176 177 178 181 protected String connectionURL = null; 182 183 184 187 protected DirContext context = null; 188 189 190 195 protected String contextFactory = "com.sun.jndi.ldap.LdapCtxFactory"; 196 197 198 201 protected String derefAliases = null; 202 203 207 public final static String DEREF_ALIASES = "java.naming.ldap.derefAliases"; 208 209 212 protected static final String info = 213 "org.apache.catalina.realm.JNDIRealm/1.0"; 214 215 216 219 protected static final String name = "JNDIRealm"; 220 221 222 226 protected String protocol = null; 227 228 229 234 protected String referrals = null; 235 236 237 240 protected String userBase = ""; 241 242 243 247 protected String userSearch = null; 248 249 250 254 protected MessageFormat userSearchFormat = null; 255 256 257 260 protected boolean userSubtree = false; 261 262 263 266 protected String userPassword = null; 267 268 269 277 protected String [] userPatternArray = null; 278 279 280 285 protected String userPattern = null; 286 287 288 292 protected MessageFormat [] userPatternFormatArray = null; 293 294 295 298 protected String roleBase = ""; 299 300 301 305 protected MessageFormat roleFormat = null; 306 307 308 312 protected String userRoleName = null; 313 314 315 318 protected String roleName = null; 319 320 321 325 protected String roleSearch = null; 326 327 328 331 protected boolean roleSubtree = false; 332 333 336 protected String alternateURL; 337 338 342 protected int connectionAttempt = 0; 343 344 347 protected int curUserPattern = 0; 348 349 351 354 public String getAuthentication() { 355 356 return authentication; 357 358 } 359 360 365 public void setAuthentication(String authentication) { 366 367 this.authentication = authentication; 368 369 } 370 371 374 public String getConnectionName() { 375 376 return (this.connectionName); 377 378 } 379 380 381 386 public void setConnectionName(String connectionName) { 387 388 this.connectionName = connectionName; 389 390 } 391 392 393 396 public String getConnectionPassword() { 397 398 return (this.connectionPassword); 399 400 } 401 402 403 408 public void setConnectionPassword(String connectionPassword) { 409 410 this.connectionPassword = connectionPassword; 411 412 } 413 414 415 418 public String getConnectionURL() { 419 420 return (this.connectionURL); 421 422 } 423 424 425 430 public void setConnectionURL(String connectionURL) { 431 432 this.connectionURL = connectionURL; 433 434 } 435 436 437 440 public String getContextFactory() { 441 442 return (this.contextFactory); 443 444 } 445 446 447 452 public void setContextFactory(String contextFactory) { 453 454 this.contextFactory = contextFactory; 455 456 } 457 458 461 public java.lang.String getDerefAliases() { 462 return derefAliases; 463 } 464 465 470 public void setDerefAliases(java.lang.String derefAliases) { 471 this.derefAliases = derefAliases; 472 } 473 474 477 public String getProtocol() { 478 479 return protocol; 480 481 } 482 483 488 public void setProtocol(String protocol) { 489 490 this.protocol = protocol; 491 492 } 493 494 495 498 public String getReferrals () { 499 return referrals; 500 } 501 502 503 507 public void setReferrals (String referrals) { 508 this.referrals = referrals; 509 } 510 511 512 515 public String getUserBase() { 516 517 return (this.userBase); 518 519 } 520 521 522 527 public void setUserBase(String userBase) { 528 529 this.userBase = userBase; 530 531 } 532 533 534 537 public String getUserSearch() { 538 539 return (this.userSearch); 540 541 } 542 543 544 549 public void setUserSearch(String userSearch) { 550 551 this.userSearch = userSearch; 552 if (userSearch == null) 553 userSearchFormat = null; 554 else 555 userSearchFormat = new MessageFormat (userSearch); 556 557 } 558 559 560 563 public boolean getUserSubtree() { 564 565 return (this.userSubtree); 566 567 } 568 569 570 575 public void setUserSubtree(boolean userSubtree) { 576 577 this.userSubtree = userSubtree; 578 579 } 580 581 582 585 public String getUserRoleName() { 586 587 return userRoleName; 588 } 589 590 591 596 public void setUserRoleName(String userRoleName) { 597 598 this.userRoleName = userRoleName; 599 600 } 601 602 603 606 public String getRoleBase() { 607 608 return (this.roleBase); 609 610 } 611 612 613 618 public void setRoleBase(String roleBase) { 619 620 this.roleBase = roleBase; 621 622 } 623 624 625 628 public String getRoleName() { 629 630 return (this.roleName); 631 632 } 633 634 635 640 public void setRoleName(String roleName) { 641 642 this.roleName = roleName; 643 644 } 645 646 647 650 public String getRoleSearch() { 651 652 return (this.roleSearch); 653 654 } 655 656 657 662 public void setRoleSearch(String roleSearch) { 663 664 this.roleSearch = roleSearch; 665 if (roleSearch == null) 666 roleFormat = null; 667 else 668 roleFormat = new MessageFormat (roleSearch); 669 670 } 671 672 673 676 public boolean getRoleSubtree() { 677 678 return (this.roleSubtree); 679 680 } 681 682 683 688 public void setRoleSubtree(boolean roleSubtree) { 689 690 this.roleSubtree = roleSubtree; 691 692 } 693 694 695 698 public String getUserPassword() { 699 700 return (this.userPassword); 701 702 } 703 704 705 710 public void setUserPassword(String userPassword) { 711 712 this.userPassword = userPassword; 713 714 } 715 716 717 720 public String getUserPattern() { 721 722 return (this.userPattern); 723 724 } 725 726 727 737 public void setUserPattern(String userPattern) { 738 739 this.userPattern = userPattern; 740 if (userPattern == null) 741 userPatternArray = null; 742 else { 743 userPatternArray = parseUserPatternString(userPattern); 744 int len = this.userPatternArray.length; 745 userPatternFormatArray = new MessageFormat [len]; 746 for (int i=0; i < len; i++) { 747 userPatternFormatArray[i] = 748 new MessageFormat (userPatternArray[i]); 749 } 750 } 751 } 752 753 754 759 public String getAlternateURL() { 760 761 return this.alternateURL; 762 763 } 764 765 766 771 public void setAlternateURL(String alternateURL) { 772 773 this.alternateURL = alternateURL; 774 775 } 776 777 778 780 781 794 public Principal authenticate(String username, String credentials) { 795 796 DirContext context = null; 797 Principal principal = null; 798 799 try { 800 801 context = open(); 803 804 try { 807 808 principal = authenticate(context, username, credentials); 810 811 } catch (CommunicationException e) { 812 813 containerLog.warn(sm.getString("jndiRealm.exception"), e); 815 816 if (context != null) 818 close(context); 819 820 context = open(); 822 823 principal = authenticate(context, username, credentials); 825 826 } 827 828 829 release(context); 831 832 return (principal); 834 835 } catch (NamingException e) { 836 837 containerLog.error(sm.getString("jndiRealm.exception"), e); 839 840 if (context != null) 842 close(context); 843 844 return (null); 846 847 } 848 849 } 850 851 852 854 855 857 858 869 public synchronized Principal authenticate(DirContext context, 870 String username, 871 String credentials) 872 throws NamingException { 873 874 if (username == null || username.equals("") 875 || credentials == null || credentials.equals("")) 876 return (null); 877 878 if (userPatternArray != null) { 879 for (curUserPattern = 0; 880 curUserPattern < userPatternFormatArray.length; 881 curUserPattern++) { 882 User user = getUser(context, username); 884 if (user != null) { 885 try { 886 if (checkCredentials(context, user, credentials)) { 888 List roles = getRoles(context, user); 890 return (new GenericPrincipal(this, 891 username, 892 credentials, 893 roles)); 894 } 895 } catch (InvalidNameException ine) { 896 containerLog.warn(sm.getString("jndiRealm.exception"), ine); 898 } 903 } 904 } 905 return null; 906 } else { 907 User user = getUser(context, username); 909 if (user == null) 910 return (null); 911 912 if (!checkCredentials(context, user, credentials)) 914 return (null); 915 916 List roles = getRoles(context, user); 918 919 return (new GenericPrincipal(this, username, credentials, roles)); 921 } 922 } 923 924 925 941 protected User getUser(DirContext context, String username) 942 throws NamingException { 943 944 User user = null; 945 946 ArrayList list = new ArrayList (); 948 if (userPassword != null) 949 list.add(userPassword); 950 if (userRoleName != null) 951 list.add(userRoleName); 952 String [] attrIds = new String [list.size()]; 953 list.toArray(attrIds); 954 955 if (userPatternFormatArray != null) { 957 user = getUserByPattern(context, username, attrIds); 958 } else { 959 user = getUserBySearch(context, username, attrIds); 960 } 961 962 return user; 963 } 964 965 966 979 protected User getUserByPattern(DirContext context, 980 String username, 981 String [] attrIds) 982 throws NamingException { 983 984 if (username == null || userPatternFormatArray[curUserPattern] == null) 985 return (null); 986 987 String dn = userPatternFormatArray[curUserPattern].format(new String [] { username }); 989 990 Attributes attrs = null; 992 try { 993 attrs = context.getAttributes(dn, attrIds); 994 } catch (NameNotFoundException e) { 995 return (null); 996 } 997 if (attrs == null) 998 return (null); 999 1000 String password = null; 1002 if (userPassword != null) 1003 password = getAttributeValue(userPassword, attrs); 1004 1005 ArrayList roles = null; 1007 if (userRoleName != null) 1008 roles = addAttributeValues(userRoleName, attrs, roles); 1009 1010 return new User(username, dn, password, roles); 1011 } 1012 1013 1014 1025 protected User getUserBySearch(DirContext context, 1026 String username, 1027 String [] attrIds) 1028 throws NamingException { 1029 1030 if (username == null || userSearchFormat == null) 1031 return (null); 1032 1033 String filter = userSearchFormat.format(new String [] { username }); 1035 1036 SearchControls constraints = new SearchControls (); 1038 1039 if (userSubtree) { 1040 constraints.setSearchScope(SearchControls.SUBTREE_SCOPE); 1041 } 1042 else { 1043 constraints.setSearchScope(SearchControls.ONELEVEL_SCOPE); 1044 } 1045 1046 if (attrIds == null) 1048 attrIds = new String [0]; 1049 constraints.setReturningAttributes(attrIds); 1050 1051 NamingEnumeration results = 1052 context.search(userBase, filter, constraints); 1053 1054 1055 if (results == null || !results.hasMore()) { 1057 return (null); 1058 } 1059 1060 SearchResult result = (SearchResult )results.next(); 1062 1063 if (results.hasMore()) { 1065 if(containerLog.isInfoEnabled()) 1066 containerLog.info("username " + username + " has multiple entries"); 1067 return (null); 1068 } 1069 1070 NameParser parser = context.getNameParser(""); 1072 Name contextName = parser.parse(context.getNameInNamespace()); 1073 Name baseName = parser.parse(userBase); 1074 1075 Name entryName = parser.parse(new CompositeName (result.getName()).get(0)); 1077 1078 Name name = contextName.addAll(baseName); 1079 name = name.addAll(entryName); 1080 String dn = name.toString(); 1081 1082 if (containerLog.isTraceEnabled()) 1083 containerLog.trace(" entry found for " + username + " with dn " + dn); 1084 1085 Attributes attrs = result.getAttributes(); 1087 if (attrs == null) 1088 return null; 1089 1090 String password = null; 1092 if (userPassword != null) 1093 password = getAttributeValue(userPassword, attrs); 1094 1095 ArrayList roles = null; 1097 if (userRoleName != null) 1098 roles = addAttributeValues(userRoleName, attrs, roles); 1099 1100 return new User(username, dn, password, roles); 1101 } 1102 1103 1104 1119 protected boolean checkCredentials(DirContext context, 1120 User user, 1121 String credentials) 1122 throws NamingException { 1123 1124 boolean validated = false; 1125 1126 if (userPassword == null) { 1127 validated = bindAsUser(context, user, credentials); 1128 } else { 1129 validated = compareCredentials(context, user, credentials); 1130 } 1131 1132 if (containerLog.isTraceEnabled()) { 1133 if (validated) { 1134 containerLog.trace(sm.getString("jndiRealm.authenticateSuccess", 1135 user.username)); 1136 } else { 1137 containerLog.trace(sm.getString("jndiRealm.authenticateFailure", 1138 user.username)); 1139 } 1140 } 1141 return (validated); 1142 } 1143 1144 1145 1146 1156 protected boolean compareCredentials(DirContext context, 1157 User info, 1158 String credentials) 1159 throws NamingException { 1160 1161 if (info == null || credentials == null) 1162 return (false); 1163 1164 String password = info.password; 1165 if (password == null) 1166 return (false); 1167 1168 if (containerLog.isTraceEnabled()) 1170 containerLog.trace(" validating credentials"); 1171 1172 boolean validated = false; 1173 if (hasMessageDigest()) { 1174 if (password.startsWith("{SHA}")) { 1178 1179 synchronized (this) { 1180 password = password.substring(5); 1181 md.reset(); 1182 md.update(credentials.getBytes()); 1183 String digestedPassword = 1184 new String (Base64.encode(md.digest())); 1185 validated = password.equals(digestedPassword); 1186 } 1187 } else if (password.startsWith("{SSHA}")) { 1188 1190 synchronized (this) { 1191 password = password.substring(6); 1192 1193 md.reset(); 1194 md.update(credentials.getBytes()); 1195 1196 ByteChunk pwbc = new ByteChunk(password.length()); 1198 try { 1199 pwbc.append(password.getBytes(), 0, password.length()); 1200 } catch (IOException e) { 1201 containerLog.error("Could not append password bytes to chunk: ", e); 1203 } 1204 1205 CharChunk decoded = new CharChunk(); 1206 Base64.decode(pwbc, decoded); 1207 char[] pwarray = decoded.getBuffer(); 1208 1209 final int saltpos = 20; 1211 byte[] hash = new byte[saltpos]; 1212 for (int i=0; i< hash.length; i++) { 1213 hash[i] = (byte) pwarray[i]; 1214 } 1215 1216 byte[] salt = new byte[pwarray.length - saltpos]; 1217 for (int i=0; i< salt.length; i++) 1218 salt[i] = (byte)pwarray[i+saltpos]; 1219 1220 md.update(salt); 1221 byte[] dp = md.digest(); 1222 1223 validated = Arrays.equals(dp, hash); 1224 } } else { 1226 validated = (digest(credentials).equalsIgnoreCase(password)); 1228 } 1229 } else 1230 validated = (digest(credentials).equals(password)); 1231 return (validated); 1232 1233 } 1234 1235 1236 1237 1246 protected boolean bindAsUser(DirContext context, 1247 User user, 1248 String credentials) 1249 throws NamingException { 1250 Attributes attr; 1251 1252 if (credentials == null || user == null) 1253 return (false); 1254 1255 String dn = user.dn; 1256 if (dn == null) 1257 return (false); 1258 1259 if (containerLog.isTraceEnabled()) { 1261 containerLog.trace(" validating credentials by binding as the user"); 1262 } 1263 1264 context.addToEnvironment(Context.SECURITY_PRINCIPAL, dn); 1266 context.addToEnvironment(Context.SECURITY_CREDENTIALS, credentials); 1267 1268 boolean validated = false; 1270 try { 1271 if (containerLog.isTraceEnabled()) { 1272 containerLog.trace(" binding as " + dn); 1273 } 1274 attr = context.getAttributes("", null); 1275 validated = true; 1276 } 1277 catch (AuthenticationException e) { 1278 if (containerLog.isTraceEnabled()) { 1279 containerLog.trace(" bind attempt failed"); 1280 } 1281 } 1282 1283 if (connectionName != null) { 1285 context.addToEnvironment(Context.SECURITY_PRINCIPAL, 1286 connectionName); 1287 } else { 1288 context.removeFromEnvironment(Context.SECURITY_PRINCIPAL); 1289 } 1290 1291 if (connectionPassword != null) { 1292 context.addToEnvironment(Context.SECURITY_CREDENTIALS, 1293 connectionPassword); 1294 } 1295 else { 1296 context.removeFromEnvironment(Context.SECURITY_CREDENTIALS); 1297 } 1298 1299 return (validated); 1300 } 1301 1302 1303 1314 protected List getRoles(DirContext context, User user) 1315 throws NamingException { 1316 1317 if (user == null) 1318 return (null); 1319 1320 String dn = user.dn; 1321 String username = user.username; 1322 1323 if (dn == null || username == null) 1324 return (null); 1325 1326 if (containerLog.isTraceEnabled()) 1327 containerLog.trace(" getRoles(" + dn + ")"); 1328 1329 ArrayList list = user.roles; 1331 if (list == null) { 1332 list = new ArrayList (); 1333 } 1334 1335 if ((roleFormat == null) || (roleName == null)) 1337 return (list); 1338 1339 String filter = roleFormat.format(new String [] { doRFC2254Encoding(dn), username }); 1341 SearchControls controls = new SearchControls (); 1342 if (roleSubtree) 1343 controls.setSearchScope(SearchControls.SUBTREE_SCOPE); 1344 else 1345 controls.setSearchScope(SearchControls.ONELEVEL_SCOPE); 1346 controls.setReturningAttributes(new String [] {roleName}); 1347 1348 NamingEnumeration results = 1350 context.search(roleBase, filter, controls); 1351 if (results == null) 1352 return (list); while (results.hasMore()) { 1354 SearchResult result = (SearchResult ) results.next(); 1355 Attributes attrs = result.getAttributes(); 1356 if (attrs == null) 1357 continue; 1358 list = addAttributeValues(roleName, attrs, list); 1359 } 1360 1361 1362 if (containerLog.isTraceEnabled()) { 1363 if (list != null) { 1364 containerLog.trace(" Returning " + list.size() + " roles"); 1365 for (int i=0; i<list.size(); i++) 1366 containerLog.trace( " Found role " + list.get(i)); 1367 } else { 1368 containerLog.trace(" getRoles about to return null "); 1369 } 1370 } 1371 1372 return (list); 1373 } 1374 1375 1376 1384 private String getAttributeValue(String attrId, Attributes attrs) 1385 throws NamingException { 1386 1387 if (containerLog.isTraceEnabled()) 1388 containerLog.trace(" retrieving attribute " + attrId); 1389 1390 if (attrId == null || attrs == null) 1391 return null; 1392 1393 Attribute attr = attrs.get(attrId); 1394 if (attr == null) 1395 return (null); 1396 Object value = attr.get(); 1397 if (value == null) 1398 return (null); 1399 String valueString = null; 1400 if (value instanceof byte[]) 1401 valueString = new String ((byte[]) value); 1402 else 1403 valueString = value.toString(); 1404 1405 return valueString; 1406 } 1407 1408 1409 1410 1419 private ArrayList addAttributeValues(String attrId, 1420 Attributes attrs, 1421 ArrayList values) 1422 throws NamingException { 1423 1424 if (containerLog.isTraceEnabled()) 1425 containerLog.trace(" retrieving values for attribute " + attrId); 1426 if (attrId == null || attrs == null) 1427 return values; 1428 if (values == null) 1429 values = new ArrayList (); 1430 Attribute attr = attrs.get(attrId); 1431 if (attr == null) 1432 return (values); 1433 NamingEnumeration e = attr.getAll(); 1434 while(e.hasMore()) { 1435 String value = (String )e.next(); 1436 values.add(value); 1437 } 1438 return values; 1439 } 1440 1441 1442 1447 protected void close(DirContext context) { 1448 1449 if (context == null) 1451 return; 1452 1453 try { 1455 if (containerLog.isDebugEnabled()) 1456 containerLog.debug("Closing directory context"); 1457 context.close(); 1458 } catch (NamingException e) { 1459 containerLog.error(sm.getString("jndiRealm.close"), e); 1460 } 1461 this.context = null; 1462 1463 } 1464 1465 1466 1469 protected String getName() { 1470 1471 return (name); 1472 1473 } 1474 1475 1476 1479 protected String getPassword(String username) { 1480 1481 return (null); 1482 1483 } 1484 1485 1488 protected Principal getPrincipal(String username) { 1489 1490 DirContext context = null; 1491 Principal principal = null; 1492 1493 try { 1494 1495 context = open(); 1497 1498 try { 1501 1502 principal = getPrincipal(context, username); 1504 1505 } catch (CommunicationException e) { 1506 1507 containerLog.warn(sm.getString("jndiRealm.exception"), e); 1509 1510 if (context != null) 1512 close(context); 1513 1514 context = open(); 1516 1517 principal = getPrincipal(context, username); 1519 1520 } 1521 1522 1523 release(context); 1525 1526 return (principal); 1528 1529 } catch (NamingException e) { 1530 1531 containerLog.error(sm.getString("jndiRealm.exception"), e); 1533 1534 if (context != null) 1536 close(context); 1537 1538 return (null); 1540 1541 } 1542 1543 1544 } 1545 1546 1547 1550 protected synchronized Principal getPrincipal(DirContext context, 1551 String username) 1552 throws NamingException { 1553 1554 User user = getUser(context, username); 1555 1556 return new GenericPrincipal(this, user.username, user.password , 1557 getRoles(context, user)); 1558 } 1559 1560 1566 protected DirContext open() throws NamingException { 1567 1568 if (context != null) 1570 return (context); 1571 1572 try { 1573 1574 context = new InitialDirContext (getDirectoryContextEnvironment()); 1576 1577 } catch (Exception e) { 1578 1579 connectionAttempt = 1; 1580 1581 containerLog.warn(sm.getString("jndiRealm.exception"), e); 1583 1584 context = new InitialDirContext (getDirectoryContextEnvironment()); 1586 1587 } finally { 1588 1589 connectionAttempt = 0; 1592 1593 } 1594 1595 return (context); 1596 1597 } 1598 1599 1604 protected Hashtable getDirectoryContextEnvironment() { 1605 1606 Hashtable env = new Hashtable (); 1607 1608 if (containerLog.isDebugEnabled() && connectionAttempt == 0) 1610 containerLog.debug("Connecting to URL " + connectionURL); 1611 else if (containerLog.isDebugEnabled() && connectionAttempt > 0) 1612 containerLog.debug("Connecting to URL " + alternateURL); 1613 env.put(Context.INITIAL_CONTEXT_FACTORY, contextFactory); 1614 if (connectionName != null) 1615 env.put(Context.SECURITY_PRINCIPAL, connectionName); 1616 if (connectionPassword != null) 1617 env.put(Context.SECURITY_CREDENTIALS, connectionPassword); 1618 if (connectionURL != null && connectionAttempt == 0) 1619 env.put(Context.PROVIDER_URL, connectionURL); 1620 else if (alternateURL != null && connectionAttempt > 0) 1621 env.put(Context.PROVIDER_URL, alternateURL); 1622 if (authentication != null) 1623 env.put(Context.SECURITY_AUTHENTICATION, authentication); 1624 if (protocol != null) 1625 env.put(Context.SECURITY_PROTOCOL, protocol); 1626 if (referrals != null) 1627 env.put(Context.REFERRAL, referrals); 1628 if (derefAliases != null) 1629 env.put(JNDIRealm.DEREF_ALIASES, derefAliases); 1630 1631 return env; 1632 1633 } 1634 1635 1636 1641 protected void release(DirContext context) { 1642 1643 ; 1645 } 1646 1647 1648 1650 1651 1657 public void start() throws LifecycleException { 1658 1659 super.start(); 1661 1662 try { 1664 open(); 1665 } catch (NamingException e) { 1666 throw new LifecycleException(sm.getString("jndiRealm.open"), e); 1667 } 1668 1669 } 1670 1671 1672 1678 public void stop() throws LifecycleException { 1679 1680 super.stop(); 1682 1683 close(this.context); 1685 1686 } 1687 1688 1697 protected String [] parseUserPatternString(String userPatternString) { 1698 1699 if (userPatternString != null) { 1700 ArrayList pathList = new ArrayList (); 1701 int startParenLoc = userPatternString.indexOf('('); 1702 if (startParenLoc == -1) { 1703 return new String [] {userPatternString}; 1705 } 1706 int startingPoint = 0; 1707 while (startParenLoc > -1) { 1708 int endParenLoc = 0; 1709 while ( (userPatternString.charAt(startParenLoc + 1) == '|') || 1713 (startParenLoc != 0 && userPatternString.charAt(startParenLoc - 1) == '\\') ) { 1714 startParenLoc = userPatternString.indexOf("(", startParenLoc+1); 1715 } 1716 endParenLoc = userPatternString.indexOf(")", startParenLoc+1); 1717 while (userPatternString.charAt(endParenLoc - 1) == '\\') { 1719 endParenLoc = userPatternString.indexOf(")", endParenLoc+1); 1720 } 1721 String nextPathPart = userPatternString.substring 1722 (startParenLoc+1, endParenLoc); 1723 pathList.add(nextPathPart); 1724 startingPoint = endParenLoc+1; 1725 startParenLoc = userPatternString.indexOf('(', startingPoint); 1726 } 1727 return (String [])pathList.toArray(new String [] {}); 1728 } 1729 return null; 1730 1731 } 1732 1733 1734 1748 protected String doRFC2254Encoding(String inString) { 1749 StringBuffer buf = new StringBuffer (inString.length()); 1750 for (int i = 0; i < inString.length(); i++) { 1751 char c = inString.charAt(i); 1752 switch (c) { 1753 case '\\': 1754 buf.append("\\5c"); 1755 break; 1756 case '*': 1757 buf.append("\\2a"); 1758 break; 1759 case '(': 1760 buf.append("\\28"); 1761 break; 1762 case ')': 1763 buf.append("\\29"); 1764 break; 1765 case '\0': 1766 buf.append("\\00"); 1767 break; 1768 default: 1769 buf.append(c); 1770 break; 1771 } 1772 } 1773 return buf.toString(); 1774 } 1775 1776 1777} 1778 1779 1781 1784class User { 1785 String username = null; 1786 String dn = null; 1787 String password = null; 1788 ArrayList roles = null; 1789 1790 1791 User(String username, String dn, String password, ArrayList roles) { 1792 this.username = username; 1793 this.dn = dn; 1794 this.password = password; 1795 this.roles = roles; 1796 } 1797 1798} 1799 | Popular Tags |