Project

General

Profile

Revision 3749

Added by Jing Tao about 13 years ago

Add timeout parameter for searching user name. If some exception happens, it wouldnot throw it, just print it out.

View differences:

src/edu/ucsb/nceas/metacat/AuthLdap.java
402 402
            "com.sun.jndi.ldap.LdapCtxFactory");
403 403
    env.put(Context.REFERRAL, referral);
404 404
    env.put(Context.PROVIDER_URL, ldapUrl);
405
    env.put("com.sun.jndi.ldap.connect.timeout", ldapConnectTimeLimit);
405 406

  
406 407
    try {
407 408

  
......
415 416
          "dn", "cn", "o", "ou", "mail"};
416 417
      ctls.setReturningAttributes(attrIDs);
417 418
      ctls.setSearchScope(SearchControls.SUBTREE_SCOPE);
419
      ctls.setTimeLimit(ldapSearchTimeLimit);
418 420
      //ctls.setCountLimit(1000);
419 421
      String filter = "(objectClass=inetOrgPerson)";
420 422
      NamingEnumeration namingEnum = ctx.search(ldapBase, filter, ctls);
......
484 486
    catch (NamingException e) {
485 487
      logMetacat.error("Problem getting users in AuthLdap.getUsers:" + e);
486 488
      //e.printStackTrace(System.err);
487
      throw new ConnectException(
488
          "Problem getting users in AuthLdap.getUsers:" + e);
489
     /* throw new ConnectException(
490
          "Problem getting users in AuthLdap.getUsers:" + e);*/
489 491
    }
490 492

  
491 493
    return users;
......
647 649
    catch (NamingException e) {
648 650
      logMetacat.error("Problem getting users for a group in " +
649 651
                        "AuthLdap.getUsers:" + e);
650
      throw new ConnectException(
651
          "Problem getting users for a group in AuthLdap.getUsers:" + e);
652
      /*throw new ConnectException(
653
          "Problem getting users for a group in AuthLdap.getUsers:" + e);*/
652 654
    }
653 655

  
654 656
    return users;
......
1077 1079
    while (keyEnum.hasMoreElements()) {
1078 1080
      this.ldapBase = (String) keyEnum.nextElement();
1079 1081
      this.ldapUrl = (String) subtrees.get(ldapBase);
1080

  
1082
      logMetacat.info("ldapBase "+ldapBase);
1083
      logMetacat.info("ldapUrl "+ldapUrl);
1081 1084
      /*
1082 1085
       * code to get the organization name from ldapBase
1083 1086
       */
......
1106 1109
          }
1107 1110
        }
1108 1111
      }
1109

  
1112
      logMetacat.info("org name is  "+orgName);
1110 1113
      out.append("  <authSystem URI=\"" +
1111 1114
                 this.ldapUrl + this.ldapBase + "\" organization=\"" + orgName +
1112 1115
                 "\">\n");
1113 1116

  
1114 1117
      // get all groups for directory context
1115 1118
      String[][] groups = getGroups(user, password);
1119
      logMetacat.debug("after getting groups "+groups);
1116 1120
      String[][] users = getUsers(user, password);
1121
      logMetacat.debug("after getting users "+users);
1117 1122
      int userIndex = 0;
1118 1123

  
1119 1124
      // for the groups and users that belong to them
1120
      if (groups != null && groups.length > 0) {
1121
        for (int i = 0; i < groups.length; i++) {
1125
      if (groups != null && users != null && groups.length > 0) {
1126
    	 for (int i = 0; i < groups.length; i++) {
1122 1127
          out.append("    <group>\n");
1123 1128
          out.append("      <groupname>" + groups[i][0] + "</groupname>\n");
1124 1129
          out.append("      <description>" + groups[i][1] + "</description>\n");
1125 1130
          String[] usersForGroup = getUsers(user, password, groups[i][0]);
1126 1131
          for (int j = 0; j < usersForGroup.length; j++) {
1127
            
1128 1132
            userIndex = searchUser(usersForGroup[j], users);
1129 1133
            out.append("      <user>\n");
1130 1134

  
......
1150 1154
          out.append("    </group>\n");
1151 1155
        }
1152 1156
      }
1153

  
1154
      // for the users not belonging to any grou8p
1155
      for (int j = 0; j < users.length; j++) {
1156
          out.append("    <user>\n");
1157
          out.append("      <username>" + users[j][0] + "</username>\n");
1158
          out.append("      <name>" + users[j][1] + "</name>\n");
1159
          out.append("      <organization>" + users[j][2] +
1160
                     "</organization>\n");
1161
          if (users[j][3].compareTo("null") != 0) {
1162
            out.append("      <organizationUnitName>" + users[j][3] +
1163
                       "</organizationUnitName>\n");
1164
          }
1165
          out.append("      <email>" + users[j][4] + "</email>\n");
1166
          out.append("    </user>\n");
1157
     
1158
      if (users != null)
1159
      {
1160
	      // for the users not belonging to any grou8p
1161
	      for (int j = 0; j < users.length; j++) {
1162
	          out.append("    <user>\n");
1163
	          out.append("      <username>" + users[j][0] + "</username>\n");
1164
	          out.append("      <name>" + users[j][1] + "</name>\n");
1165
	          out.append("      <organization>" + users[j][2] +
1166
	                     "</organization>\n");
1167
	          if (users[j][3].compareTo("null") != 0) {
1168
	            out.append("      <organizationUnitName>" + users[j][3] +
1169
	                       "</organizationUnitName>\n");
1170
	          }
1171
	          out.append("      <email>" + users[j][4] + "</email>\n");
1172
	          out.append("    </user>\n");
1173
	      }
1167 1174
      }
1168 1175

  
1169 1176
      out.append("  </authSystem>\n");

Also available in: Unified diff