Project

General

Profile

« Previous | Next » 

Revision 866

Added by berkley over 22 years ago

I think i have fixed the ldap referral bug. the test lter account that david made for me works, however I would like matt or someone more knowedgeable with ldap to please check my code. the changes I made are around line 200 of AuthLdap. I put a comment in the source where the code needs to be checked.

View differences:

src/edu/ucsb/nceas/metacat/AuthLdap.java
90 90
  public boolean authenticate(String user, String password)
91 91
                    throws ConnectException
92 92
  {
93
System.out.println("ldap authenticating");
93 94
    String ldapUrl = this.ldapUrl;
94 95
    String ldapsUrl = this.ldapsUrl;
95 96
    String ldapBase = this.ldapBase;
......
144 145
        env.put(Context.INITIAL_CONTEXT_FACTORY, 
145 146
            "com.sun.jndi.ldap.LdapCtxFactory");
146 147

  
148
        System.out.println("referral: " + referral);
147 149
        // Now that we have the dn, we can authenticate, so
148 150
        // authenticate this time when opening the DirContext
149
        env.put(Context.REFERRAL, referral);
151
        env.put(Context.REFERRAL, "throw");
152
        System.out.println("ldapsUrl: " + ldapsUrl + " ldapBase: " + ldapBase);
150 153
        env.put(Context.PROVIDER_URL, ldapsUrl + ldapBase);
151 154
        if ( !ldapsUrl.equals(ldapUrl) ) {
152 155
          // ldap is set on default port 389
......
187 190
          }
188 191
        } catch (javax.naming.InvalidNameException ine) {
189 192
            System.out.println("An invalid DN was provided!");
190
        }
193
        } catch(javax.naming.ReferralException re) {
194
	    System.out.println("referral to : " + re.getReferralInfo().toString());
195
            try
196
            {
197
              /*
198
               Matt, I think this is right but I'm not sure...please check me to make
199
               sure I didn't do something wrong here.
200
              */
201
              Context refctx = re.getReferralContext(env);
202
              authenticated = true;
203
            }
204
            catch(Exception e)
205
            {
206
                System.out.println("Error with referral to : " + re.getReferralInfo().toString());
207
            }
208
            
209
	}
191 210
    } else { 
192 211
        util.debugMessage("User not found");
193 212
    }
......
212 231
    Hashtable env = new Hashtable(11);
213 232
    env.put(Context.INITIAL_CONTEXT_FACTORY,
214 233
            "com.sun.jndi.ldap.LdapCtxFactory");
234
    util.debugMessage("setting referrals to: " + referral);
215 235
    env.put(Context.REFERRAL, referral);
216 236
    env.put(Context.PROVIDER_URL, ldapUrl + ldapBase);
217 237
//    non-secure LDAP context; dn are publicly readable
......
821 841
            Attribute attr = (Attribute)enum1.next();
822 842
            String attrValue = (String)attr.get();
823 843
            String attrName = (String)attr.getID();
824
 //System.out.println(attrName + "=" + attrValue);
844
 System.out.println(attrName + "=" + attrValue);
825 845
            if ( enum1.hasMore() ) {
826 846
              attr = (Attribute)enum1.next();
827 847
              String refValue = (String)attr.get();
828 848
              String refName = (String)attr.getID();
829
 //System.out.println(refName + "=" + refValue);
849
 System.out.println(refName + "=" + refValue);
830 850
              if ( ldapBase.startsWith(refName + "=" + refValue) ) {
831 851
                trees.put(ldapBase,
832 852
                          attrValue.substring(0,attrValue.lastIndexOf("/")+1) );
......
834 854
                trees.put(refName + "=" + refValue + "," + ldapBase,
835 855
                          attrValue.substring(0,attrValue.lastIndexOf("/")+1) );
836 856
              }
837
 //System.out.println("REFERRAL:" + attrValue);
857
 System.out.println("REFERRAL:" + attrValue);
838 858
            } else if ( ldapBase.startsWith(attrName + "=" + attrValue) ) {
839 859
                trees.put(ldapBase, ldapUrl);
840 860
            } else {              
841 861
                trees.put(attrName + "=" + attrValue + "," + ldapBase, ldapUrl);
842
 //System.out.println(ldapUrl + attrName + "=" + attrValue + "," + ldapBase);
862
 System.out.println(ldapUrl + attrName + "=" + attrValue + "," + ldapBase);
843 863
            }
844 864
          }
845 865
        }
......
853 873
      "Problem getting subtrees in AuthLdap.getSubtrees:" + e);
854 874
    }
855 875

  
856
//System.out.println("number of subtrees:" + trees.size());
876
System.out.println("number of subtrees:" + trees.size());
857 877
    return trees;
858 878
  }
859 879

  

Also available in: Unified diff