Project

General

Profile

« Previous | Next » 

Revision 2130

Added by sgarg over 20 years ago

Added ou also to getprincipal output. So now organizationUnitName is also returned in getprincipal output.

View differences:

src/edu/ucsb/nceas/metacat/AuthLdap.java
444 444
      // Users are objects that have the attribute objectclass=InetOrgPerson.
445 445
      SearchControls ctls = new SearchControls();
446 446
      String[] attrIDs = {
447
          "dn", "cn", "o", "mail"};
447
          "dn", "cn", "o", "ou", "mail"};
448 448
      ctls.setReturningAttributes(attrIDs);
449 449
      ctls.setSearchScope(SearchControls.SUBTREE_SCOPE);
450 450
      //ctls.setCountLimit(1000);
......
455 455
      Vector uvec = new Vector();
456 456
      Vector uname = new Vector();
457 457
      Vector uorg = new Vector();
458
      Vector uou = new Vector();
458 459
      Vector umail = new Vector();
459 460
      Attributes tempAttr = null;
460 461
      try {
......
476 477
            uorg.add(tempAttr.get("o") + "");
477 478
          }
478 479

  
480
          if ( (tempAttr.get("ou") + "").startsWith("ou: ")) {
481
            uou.add( (tempAttr.get("ou") + "").substring(4));
482
          }
483
          else {
484
            uou.add(tempAttr.get("ou") + "");
485
          }
486

  
479 487
          if ( (tempAttr.get("mail") + "").startsWith("mail: ")) {
480 488
            umail.add( (tempAttr.get("mail") + "").substring(6));
481 489
          }
......
492 500
      }
493 501

  
494 502
      // initialize users[]; fill users[]
495
      users = new String[uvec.size()][4];
503
      users = new String[uvec.size()][5];
496 504
      for (int i = 0; i < uvec.size(); i++) {
497 505
        users[i][0] = (String) uvec.elementAt(i);
498 506
        users[i][1] = (String) uname.elementAt(i);
499 507
        users[i][2] = (String) uorg.elementAt(i);
500
        users[i][3] = (String) umail.elementAt(i);
508
        users[i][3] = (String) uorg.elementAt(i);
509
        users[i][4] = (String) umail.elementAt(i);
501 510
      }
502 511

  
503 512
      // Close the context when we're done
......
905 914
          else {
906 915
            if (sr.isRelative()) {
907 916
              trees.put(attrName + "=" + attrValue + "," + ldapBase, ldapUrl);
908
            } else {
917
            }
918
            else {
909 919
              String referenceURL = sr.getName();
910 920
              referenceURL = referenceURL.substring(0,
911 921
                  referenceURL.lastIndexOf("/") + 1);
......
957 967
      this.ldapBase = (String) enum.nextElement();
958 968
      this.ldapUrl = (String) subtrees.get(ldapBase);
959 969

  
960

  
961 970
      /*
962 971
       * code to get the organization name from ldapBase
963 972
       */
964 973
      String orgName = this.ldapBase;
965
      if(orgName.startsWith("[")){
974
      if (orgName.startsWith("[")) {
966 975
        // if orgName starts with [ then it is a referral URL...
967 976
        // (see code in getSubtress)
968 977
        // hence orgName can be retrieved  by getting the string between
......
974 983
          orgName = orgName.substring(orgName.indexOf("o=") + 2);
975 984
          orgName = orgName.substring(0, orgName.indexOf("]"));
976 985
        }
977
      } else {
986
      }
987
      else {
978 988
        // else it is not referral
979 989
        // hence orgName can be retrieved  by getting the string between
980 990
        // 'o=' and ','
......
1013 1023
                         "</username>\n");
1014 1024
            }
1015 1025
            else {
1016
              out.append("      <username>" + users[userIndex][0] +
1026
              out.append("        <username>" + users[userIndex][0] +
1017 1027
                         "</username>\n");
1018
              out.append("      <name>" + users[userIndex][1] + "</name>\n");
1019
              out.append("      <organization>" + users[userIndex][2] +
1028
              out.append("        <name>" + users[userIndex][1] + "</name>\n");
1029
              out.append("        <organization>" + users[userIndex][2] +
1020 1030
                         "</organization>\n");
1021
              out.append("      <email>" + users[userIndex][3] + "</email>\n");
1031
              if (users[userIndex][3].compareTo("null") != 0) {
1032
                out.append("      <organizationUnitName>" + users[userIndex][3] +
1033
                           "</organizationUnitName>\n");
1034
              }
1035
              out.append("        <email>" + users[userIndex][4] + "</email>\n");
1022 1036
            }
1023 1037

  
1024 1038
            out.append("      </user>\n");
......
1027 1041
        }
1028 1042
      }
1029 1043

  
1030
      // for the users not belonging to any group
1044
      // for the users not belonging to any grou8p
1031 1045
      for (int j = 0; j < users.length; j++) {
1032 1046
        if (!usersIn.contains(users[j][0])) {
1033 1047
          out.append("    <user>\n");
1034 1048
          out.append("      <username>" + users[j][0] + "</username>\n");
1035 1049
          out.append("      <name>" + users[j][1] + "</name>\n");
1036
          out.append("      <organization>" + users[j][2] + "</organization>\n");
1037
          out.append("      <email>" + users[j][3] + "</email>\n");
1050
          out.append("      <organization>" + users[j][2] +
1051
                     "</organization>\n");
1052
          if (users[j][3].compareTo("null") != 0) {
1053
            out.append("      <organizationUnitName>" + users[j][3] +
1054
                       "</organizationUnitName>\n");
1055
          }
1056
          out.append("      <email>" + users[j][4] + "</email>\n");
1038 1057
          out.append("    </user>\n");
1039 1058
        }
1040 1059
      }

Also available in: Unified diff