Project

General

Profile

« Previous | Next » 

Revision 2129

Added by sgarg over 20 years ago

Made changes so that PISCO and NRS trees are also returned in getPrincipals action.

View differences:

src/edu/ucsb/nceas/metacat/AuthLdap.java
835 835
    Hashtable env = new Hashtable(11);
836 836
    env.put(Context.INITIAL_CONTEXT_FACTORY,
837 837
            "com.sun.jndi.ldap.LdapCtxFactory");
838
    env.put(Context.REFERRAL, referral);
838
    // env.put(Context.REFERRAL, referral);
839
    // Using 'ignore' here instead of 'follow' as 'ignore' seems
840
    // to do the job better. 'follow' was not bringing up the UCNRS
841
    // and PISCO tree whereas 'ignore' brings up the tree.
842

  
843
    env.put(Context.REFERRAL, "ignore");
839 844
    env.put(Context.PROVIDER_URL, ldapUrl + ldapBase);
840 845

  
841 846
    try {
......
864 869

  
865 870
        SearchResult sr = (SearchResult) enum.next();
866 871

  
867
   //     util.debugMessage("SSSSSSSSSGGGGG: enum " + sr.toString() , 9);
868
   //     util.debugMessage("SSSSSSSSSGGGGG: enum " + sr.getName() , 9);
869 872
        Attributes attrs = sr.getAttributes();
870 873
        NamingEnumeration enum1 = attrs.getAll(); // "dc" and "ref" attrs
871 874

  
872
//        while (enum1.hasMore()) {
873
  //        Attribute attr = (Attribute) enum1.next();
874
    //      String attrValue = (String) attr.get();
875
     //     String attrName = (String) attr.getID();
876
     //   }
877

  
878 875
        if (enum1.hasMore()) {
879 876
          Attribute attr = (Attribute) enum1.next();
880 877
          String attrValue = (String) attr.get();
......
889 886
                        attrValue.substring(0, attrValue.lastIndexOf("/") + 1));
890 887
            }
891 888
            else {
892
              trees.put(refName + "=" + refValue + "," + ldapBase,
889
              // this is a referral - so organization name is appended in
890
              // front of the ldapbase.... later it is stripped out
891
              // in getPrincipals
892
              trees.put("[" + refName + "=" + refValue + "]" +
893
                        attrValue.substring(attrValue.lastIndexOf("/") + 1,
894
                                            attrValue.length()),
893 895
                        attrValue.substring(0, attrValue.lastIndexOf("/") + 1));
896

  
897
              // trees.put(refName + "=" + refValue + "," + ldapBase,
898
              //           attrValue.substring(0, attrValue.lastIndexOf("/") + 1));
894 899
            }
895 900

  
896 901
          }
......
898 903
            trees.put(ldapBase, ldapUrl);
899 904
          }
900 905
          else {
901
            if(sr.isRelative()){
906
            if (sr.isRelative()) {
902 907
              trees.put(attrName + "=" + attrValue + "," + ldapBase, ldapUrl);
903 908
            } else {
904 909
              String referenceURL = sr.getName();
905
              referenceURL = referenceURL.substring(0, referenceURL.lastIndexOf("/") + 1);
906
              trees.put(attrName + "=" + attrValue + "," + ldapBase, referenceURL);
910
              referenceURL = referenceURL.substring(0,
911
                  referenceURL.lastIndexOf("/") + 1);
912
              trees.put(attrName + "=" + attrValue + "," + ldapBase,
913
                        referenceURL);
907 914
            }
908 915

  
909 916
          }
......
921 928
          "Problem getting subtrees in AuthLdap.getSubtrees:" + e);
922 929
    }
923 930

  
924
  //  util.debugMessage("SSSSSSSSSGGGGG: trees: " + trees.toString() , 9);
925 931
    return trees;
926 932
  }
927 933

  
......
951 957
      this.ldapBase = (String) enum.nextElement();
952 958
      this.ldapUrl = (String) subtrees.get(ldapBase);
953 959

  
960

  
961
      /*
962
       * code to get the organization name from ldapBase
963
       */
954 964
      String orgName = this.ldapBase;
955
      if (orgName != null && orgName.indexOf("o=") > -1) {
956
        orgName = orgName.substring(orgName.indexOf("o=") + 2);
957
        orgName = orgName.substring(0, orgName.indexOf(","));
965
      if(orgName.startsWith("[")){
966
        // if orgName starts with [ then it is a referral URL...
967
        // (see code in getSubtress)
968
        // hence orgName can be retrieved  by getting the string between
969
        // 'o=' and ']'
970
        // also the string between [ and ] needs to be striped out from
971
        // this.ldapBase
972
        this.ldapBase = orgName.substring(orgName.indexOf("]") + 1);
973
        if (orgName != null && orgName.indexOf("o=") > -1) {
974
          orgName = orgName.substring(orgName.indexOf("o=") + 2);
975
          orgName = orgName.substring(0, orgName.indexOf("]"));
976
        }
977
      } else {
978
        // else it is not referral
979
        // hence orgName can be retrieved  by getting the string between
980
        // 'o=' and ','
981
        if (orgName != null && orgName.indexOf("o=") > -1) {
982
          orgName = orgName.substring(orgName.indexOf("o=") + 2);
983
          if (orgName.indexOf(",") > -1) {
984
            orgName = orgName.substring(0, orgName.indexOf(","));
985
          }
986
        }
958 987
      }
959
      else {
960
        orgName = "";
961
      }
962 988

  
963 989
      out.append("  <authSystem URI=\"" +
964 990
                 this.ldapUrl + this.ldapBase + "\" organization=\"" + orgName +

Also available in: Unified diff