531 |
531 |
Hashtable env = new Hashtable(11);
|
532 |
532 |
env.put(Context.INITIAL_CONTEXT_FACTORY,
|
533 |
533 |
"com.sun.jndi.ldap.LdapCtxFactory");
|
534 |
|
env.put(Context.REFERRAL, referral);
|
|
534 |
env.put(Context.REFERRAL, "throw");
|
535 |
535 |
env.put(Context.PROVIDER_URL, ldapUrl);
|
536 |
536 |
try {
|
537 |
537 |
|
... | ... | |
561 |
561 |
SearchResult sr = (SearchResult)enum.next();
|
562 |
562 |
uvec.add(sr.getName()+","+ldapBase);
|
563 |
563 |
}
|
|
564 |
|
564 |
565 |
|
565 |
566 |
// initialize groups[] and fill it
|
566 |
567 |
groups = new String[uvec.size()];
|
... | ... | |
571 |
572 |
// Close the context when we're done
|
572 |
573 |
ctx.close();
|
573 |
574 |
|
|
575 |
} catch(ReferralException re) {
|
|
576 |
System.out.println("caught a referral to " + re.toString());
|
|
577 |
try
|
|
578 |
{
|
|
579 |
Context c = handleReferral(env, re);
|
|
580 |
DirContext dc = (DirContext)c;
|
|
581 |
String[] attrIDs = {"cn"};
|
|
582 |
// Specify the attributes to match.
|
|
583 |
// Groups are objects with attribute objectclass=groupofuniquenames.
|
|
584 |
// and have attribute uniquemember: uid=foruser,ldapbase.
|
|
585 |
SearchControls ctls = new SearchControls();
|
|
586 |
ctls.setReturningAttributes(attrIDs);
|
|
587 |
ctls.setSearchScope(SearchControls.SUBTREE_SCOPE);
|
|
588 |
|
|
589 |
String filter = null;
|
|
590 |
String gfilter = "(objectClass=groupOfUniqueNames)";
|
|
591 |
if (null == foruser) {
|
|
592 |
filter = gfilter;
|
|
593 |
} else {
|
|
594 |
filter = "(& " + gfilter + "(uniqueMember=" + foruser + "))";
|
|
595 |
}
|
|
596 |
NamingEnumeration enum = dc.search(ldapBase, filter, ctls);
|
|
597 |
|
|
598 |
// Print the groups
|
|
599 |
Vector uvec = new Vector();
|
|
600 |
while (enum.hasMore()) {
|
|
601 |
SearchResult sr = (SearchResult)enum.next();
|
|
602 |
uvec.add(sr.getName()+","+ldapBase);
|
|
603 |
}
|
|
604 |
|
|
605 |
// initialize groups[] and fill it
|
|
606 |
groups = new String[uvec.size()];
|
|
607 |
for (int i=0; i < uvec.size(); i++) {
|
|
608 |
groups[i] = (String)uvec.elementAt(i);
|
|
609 |
}
|
|
610 |
c.close();
|
|
611 |
dc.close();
|
|
612 |
}
|
|
613 |
catch(Exception e)
|
|
614 |
{
|
|
615 |
System.out.println("returning groups as null");
|
|
616 |
return groups;
|
|
617 |
}
|
574 |
618 |
} catch (NamingException e) {
|
575 |
619 |
System.err.println("Problem getting groups in AuthLdap.getGroups 2:" + e);
|
576 |
620 |
e.printStackTrace(System.err);
|
577 |
621 |
throw new ConnectException(
|
578 |
622 |
"Problem getting groups for a user in AuthLdap.getGroups:" + e);
|
579 |
|
}
|
|
623 |
}
|
580 |
624 |
return groups;
|
581 |
625 |
}
|
582 |
626 |
|
updated the referral mechanism so that metacat doesn't crash when a referral server is not available