Revision 873
Added by Matt Jones about 23 years ago
src/edu/ucsb/nceas/metacat/AuthLdap.java | ||
---|---|---|
35 | 35 |
import javax.naming.Context; |
36 | 36 |
import javax.naming.NamingEnumeration; |
37 | 37 |
import javax.naming.NamingException; |
38 |
import javax.naming.SizeLimitExceededException; |
|
38 | 39 |
import javax.naming.InitialContext; |
39 | 40 |
import javax.naming.directory.InvalidSearchFilterException; |
40 | 41 |
import javax.naming.directory.Attribute; |
... | ... | |
388 | 389 |
"com.sun.jndi.ldap.LdapCtxFactory"); |
389 | 390 |
env.put(Context.REFERRAL, referral); |
390 | 391 |
env.put(Context.PROVIDER_URL, ldapUrl); |
392 |
//env.put(Context.BATCHSIZE, "500"); |
|
391 | 393 |
|
392 | 394 |
try { |
393 | 395 |
|
... | ... | |
400 | 402 |
String[] attrIDs = {"dn"}; |
401 | 403 |
ctls.setReturningAttributes(attrIDs); |
402 | 404 |
ctls.setSearchScope(SearchControls.SUBTREE_SCOPE); |
405 |
//ctls.setCountLimit(1000); |
|
403 | 406 |
String filter = "(objectClass=inetOrgPerson)"; |
404 | 407 |
NamingEnumeration enum = ctx.search(ldapBase, filter, ctls); |
405 | 408 |
|
406 |
// Print the users
|
|
409 |
// Store the users in a vector
|
|
407 | 410 |
Vector uvec = new Vector(); |
408 |
while (enum.hasMore()) { |
|
409 |
SearchResult sr = (SearchResult)enum.next(); |
|
410 |
uvec.add(sr.getName()+","+ldapBase); |
|
411 |
try { |
|
412 |
while (enum.hasMore()) { |
|
413 |
SearchResult sr = (SearchResult)enum.next(); |
|
414 |
uvec.add(sr.getName()+","+ldapBase); |
|
415 |
} |
|
416 |
} catch (SizeLimitExceededException slee) { |
|
417 |
util.debugMessage("LDAP Server size limit exceeded. " + |
|
418 |
"Returning incomplete record set."); |
|
411 | 419 |
} |
412 | 420 |
|
413 | 421 |
// initialize users[]; fill users[] |
... | ... | |
460 | 468 |
Attributes answer = ctx.getAttributes(group, attrIDs); |
461 | 469 |
|
462 | 470 |
Vector uvec = new Vector(); |
463 |
for (NamingEnumeration ae = answer.getAll(); ae.hasMore();) { |
|
464 |
Attribute attr = (Attribute)ae.next(); |
|
465 |
for (NamingEnumeration e = attr.getAll(); e.hasMore(); |
|
466 |
uvec.add(e.next()) |
|
467 |
); |
|
471 |
try { |
|
472 |
for (NamingEnumeration ae = answer.getAll(); ae.hasMore();) { |
|
473 |
Attribute attr = (Attribute)ae.next(); |
|
474 |
for (NamingEnumeration e = attr.getAll(); |
|
475 |
e.hasMore(); |
|
476 |
uvec.add(e.next()) |
|
477 |
); |
|
478 |
} |
|
479 |
} catch (SizeLimitExceededException slee) { |
|
480 |
util.debugMessage("LDAP Server size limit exceeded. " + |
|
481 |
"Returning incomplete record set."); |
|
468 | 482 |
} |
469 | 483 |
|
470 | 484 |
// initialize users[]; fill users[] |
... | ... | |
806 | 820 |
|
807 | 821 |
AuthLdap authservice = new AuthLdap(); |
808 | 822 |
|
823 |
/* |
|
824 |
// Get the list of supported controls |
|
825 |
try { |
|
826 |
// Create initial context |
|
827 |
DirContext dctx = new InitialDirContext(); |
|
828 |
|
|
829 |
// Read supportedcontrol from root DSE |
|
830 |
MetaCatUtil util = new MetaCatUtil(); |
|
831 |
String ldapurl = util.getOption("ldapurl"); |
|
832 |
Attributes attrs = dctx.getAttributes( |
|
833 |
ldapurl, new String[]{"supportedcontrol"}); |
|
834 |
|
|
835 |
System.out.println(attrs); |
|
836 |
// Close the context when we're done |
|
837 |
dctx.close(); |
|
838 |
} catch (NamingException e) { |
|
839 |
e.printStackTrace(); |
|
840 |
} |
|
841 |
*/ |
|
842 |
|
|
809 | 843 |
boolean isValid = false; |
810 | 844 |
try { |
811 | 845 |
isValid = authservice.authenticate(user, password); |
... | ... | |
871 | 905 |
String[] users = authservice.getUsers(user, password); |
872 | 906 |
System.out.println("Users found: " + users.length); |
873 | 907 |
for (int i=0; i < users.length; i++) { |
874 |
System.out.println("User " + i + ": " + users[i]); |
|
908 |
//System.out.println("User " + i + ": " + users[i]);
|
|
875 | 909 |
} |
876 | 910 |
} |
877 |
/* |
|
911 |
|
|
878 | 912 |
// get the whole list groups and users in XML format |
879 | 913 |
if (isValid) { |
880 | 914 |
System.out.println("\nTrying principals...."); |
... | ... | |
887 | 921 |
buff.flush(); |
888 | 922 |
buff.close(); |
889 | 923 |
fw.close(); |
924 |
System.out.println("\nFinished getting principals."); |
|
890 | 925 |
} |
891 |
*/ |
|
926 |
|
|
892 | 927 |
} catch (ConnectException ce) { |
893 | 928 |
System.err.println(ce.getMessage()); |
894 | 929 |
} catch (java.io.IOException ioe) { |
Also available in: Unified diff
Fixed the getUsers() and getPrincipals() methods so that they no longer
fail when large result sets are requested. The problem was that the
LDAP server was returning a "size limit exceeded" message when the resultset
from the query exceeded the default limit of 500 entries. Now we
catch the generated exception, preventing the error.