152 |
152 |
// Specify the ids of the attributes to return
|
153 |
153 |
String[] attrIDs = {"uid"};
|
154 |
154 |
|
|
155 |
// Specify the attributes to match.
|
|
156 |
// Users are objects that have the attribute objectclass=InetOrgPerson.
|
|
157 |
Attributes matchAttrs = new BasicAttributes(true); // ignore case
|
|
158 |
matchAttrs.put(new BasicAttribute("objectclass", "inetOrgPerson"));
|
|
159 |
|
155 |
160 |
// Search for objects in the current context
|
156 |
|
// All users should be put in subcontext like "ou=Users"
|
157 |
|
// NamingEnumeration answer = ctx.search("ou=Users", null, attrIDs);
|
158 |
|
NamingEnumeration enum = ctx.search("", null, attrIDs);
|
|
161 |
NamingEnumeration enum = ctx.search("", matchAttrs, attrIDs);
|
159 |
162 |
|
160 |
163 |
// Print the users
|
161 |
164 |
Vector uvec = new Vector();
|
... | ... | |
165 |
168 |
NamingEnumeration enum1 = attrs.getAll(); // only "uid" attr
|
166 |
169 |
while (enum1.hasMore()) {
|
167 |
170 |
Attribute attr = (Attribute)enum1.next();
|
168 |
|
//System.out.print(attr.getID() + "=");
|
169 |
|
//System.out.println((String)attr.get());
|
170 |
171 |
uvec.add(attr.get());
|
171 |
172 |
}
|
172 |
173 |
}
|
... | ... | |
223 |
224 |
DirContext ctx = new InitialDirContext(env);
|
224 |
225 |
|
225 |
226 |
// Specify the ids of the attributes to return
|
226 |
|
String[] attrIDs = {"uid"};
|
|
227 |
String[] attrIDs = {"uniquemember"};
|
227 |
228 |
|
|
229 |
// Get the dn for this group
|
|
230 |
identifier = getIdentifyingName(group);
|
|
231 |
|
228 |
232 |
// Specify the attributes to match.
|
229 |
|
// Ask for objects that have the attribute gid == @group.
|
|
233 |
// Groups are objects with attribute objectclass=groupofuniquenames.
|
230 |
234 |
Attributes matchAttrs = new BasicAttributes(true); // ignore case
|
231 |
|
matchAttrs.put(new BasicAttribute("gid", group));
|
|
235 |
matchAttrs.put(new BasicAttribute("objectclass", "groupofuniquenames"));
|
|
236 |
matchAttrs.put(new BasicAttribute("cn", group));
|
232 |
237 |
|
233 |
238 |
// Search for objects in the current context
|
234 |
|
// All users should be put in subcontext like "ou=Users"
|
235 |
|
// NamingEnumeration answer=ctx.search("ou=Users",matchAttrs,attrIDs);
|
236 |
239 |
NamingEnumeration enum = ctx.search("", matchAttrs, attrIDs);
|
237 |
240 |
|
238 |
241 |
// Print the users
|
... | ... | |
240 |
243 |
while (enum.hasMore()) {
|
241 |
244 |
SearchResult sr = (SearchResult)enum.next();
|
242 |
245 |
Attributes attrs = sr.getAttributes();
|
243 |
|
NamingEnumeration enum1 = attrs.getAll(); // only "uid" attr
|
|
246 |
// return all attributes
|
|
247 |
NamingEnumeration enum1 = attrs.getAll(); // only "uniquemember" attr
|
244 |
248 |
while (enum1.hasMore()) {
|
245 |
249 |
Attribute attr = (Attribute)enum1.next();
|
246 |
|
//System.out.print(attr.getID() + "=");
|
247 |
|
//System.out.println((String)attr.get());
|
248 |
|
uvec.add(attr.get());
|
|
250 |
// return all values of that attribute
|
|
251 |
NamingEnumeration enum2 = attr.getAll();
|
|
252 |
while (enum2.hasMore()) {
|
|
253 |
uvec.add((String)enum2.next());
|
|
254 |
}
|
249 |
255 |
}
|
250 |
256 |
}
|
251 |
257 |
|
... | ... | |
301 |
307 |
DirContext ctx = new InitialDirContext(env);
|
302 |
308 |
|
303 |
309 |
// Specify the ids of the attributes to return
|
304 |
|
String[] attrIDs = {"gid"};
|
305 |
|
SearchControls ctls = new SearchControls();
|
306 |
|
ctls.setReturningAttributes(attrIDs);
|
|
310 |
String[] attrIDs = {"cn"};
|
307 |
311 |
|
308 |
|
// Specify the search filter to match.
|
309 |
|
// Ask for objects that do not have "uid".
|
310 |
|
// This will assure that the directory entries are groups.
|
311 |
|
String filter = "(!(uid=*))";
|
312 |
|
|
|
312 |
// Specify the attributes to match.
|
|
313 |
// Groups are objects with attribute objectclass=groupofuniquenames.
|
|
314 |
Attributes matchAttrs = new BasicAttributes(true); // ignore case
|
|
315 |
matchAttrs.put(new BasicAttribute("objectclass", "groupofuniquenames"));
|
|
316 |
|
313 |
317 |
// Search for objects in the current context
|
314 |
|
// All users should be put in subcontext like "ou=Users"
|
315 |
|
// NamingEnumeration answer = ctx.search("ou=Users", filter,ctls);
|
316 |
|
NamingEnumeration enum = ctx.search("", filter, ctls);
|
|
318 |
NamingEnumeration enum = ctx.search("", matchAttrs, attrIDs);
|
317 |
319 |
|
318 |
320 |
// Print the users
|
319 |
321 |
Vector uvec = new Vector();
|
320 |
322 |
while (enum.hasMore()) {
|
321 |
323 |
SearchResult sr = (SearchResult)enum.next();
|
322 |
324 |
Attributes attrs = sr.getAttributes();
|
323 |
|
NamingEnumeration enum1 = attrs.getAll(); // only "gid" attr
|
|
325 |
NamingEnumeration enum1 = attrs.getAll(); // only "cn" attr
|
324 |
326 |
while (enum1.hasMore()) {
|
325 |
327 |
Attribute attr = (Attribute)enum1.next();
|
326 |
|
//System.out.print(attr.getID() + "=");
|
327 |
|
//System.out.println((String)attr.get());
|
328 |
328 |
uvec.add(attr.get());
|
329 |
329 |
}
|
330 |
330 |
}
|
... | ... | |
381 |
381 |
DirContext ctx = new InitialDirContext(env);
|
382 |
382 |
|
383 |
383 |
// Specify the ids of the attributes to return
|
384 |
|
String[] attrIDs = {"gid"};
|
|
384 |
String[] attrIDs = {"cn"};
|
385 |
385 |
|
386 |
386 |
// Specify the attributes to match.
|
387 |
|
// Ask for objects that have the attribute uid == @foruser.
|
|
387 |
// Groups are objects with attribute objectclass=groupofuniquenames.
|
|
388 |
// and have attribute uniquemember=foruser,ldapbase.
|
388 |
389 |
Attributes matchAttrs = new BasicAttributes(true); // ignore case
|
389 |
|
matchAttrs.put(new BasicAttribute("uid", foruser));
|
|
390 |
matchAttrs.put(new BasicAttribute("objectclass", "groupofuniquenames"));
|
|
391 |
matchAttrs.put(new BasicAttribute("uniquemember",foruser+","+ldapBase));
|
390 |
392 |
|
391 |
393 |
// Search for objects in the current context
|
392 |
|
// All users should be put in subcontext like "ou=Users"
|
393 |
|
// NamingEnumeration answer=ctx.search("ou=Users",matchAttrs,attrIDs);
|
394 |
394 |
NamingEnumeration enum = ctx.search("", matchAttrs, attrIDs);
|
395 |
395 |
|
396 |
396 |
// Print the users
|
... | ... | |
401 |
401 |
NamingEnumeration enum1 = attrs.getAll(); // only "gid" attr
|
402 |
402 |
while (enum1.hasMore()) {
|
403 |
403 |
Attribute attr = (Attribute)enum1.next();
|
404 |
|
//System.out.print(attr.getID() + "=");
|
405 |
|
//System.out.println((String)attr.get());
|
406 |
404 |
uvec.add(attr.get());
|
407 |
405 |
}
|
408 |
406 |
}
|
... | ... | |
589 |
587 |
{
|
590 |
588 |
StringBuffer out = new StringBuffer();
|
591 |
589 |
String[] groups = getGroups(user, password);
|
|
590 |
Vector usersIn = new Vector();
|
592 |
591 |
|
593 |
592 |
out.append("<?xml version=\"1.0\"?>\n");
|
594 |
593 |
out.append("<principals>\n");
|
... | ... | |
599 |
598 |
out.append(" <group>\n");
|
600 |
599 |
out.append(" <groupname>" + groups[i] + "<groupname>\n");
|
601 |
600 |
String[] usersForGroup = getUsers(user,password,groups[i]);
|
602 |
|
for (int j=0; j <= usersForGroup.length; j++ ) {
|
|
601 |
for (int j=0; j < usersForGroup.length; j++ ) {
|
|
602 |
usersIn.addElement(usersForGroup[j]);
|
603 |
603 |
out.append(" <user>\n");
|
604 |
604 |
out.append(" <username>" + usersForGroup[j] + "<username>\n");
|
605 |
605 |
out.append(" </user>\n");
|
606 |
606 |
}
|
607 |
|
out.append("</group>\n");
|
|
607 |
out.append(" </group>\n");
|
608 |
608 |
}
|
609 |
|
// for the users only when there are no any groups defined
|
610 |
|
} else {
|
611 |
|
String[] users = getUsers(user, password);
|
612 |
|
for (int j=0; j < users.length; j++ ) {
|
|
609 |
}
|
|
610 |
// for the users not belonging to any group
|
|
611 |
String[] users = getUsers(user, password);
|
|
612 |
for (int j=0; j < users.length; j++ ) {
|
|
613 |
if ( !usersIn.contains(users[j]) ) {
|
613 |
614 |
out.append(" <user>\n");
|
614 |
615 |
out.append(" <username>" + users[j] + "<username>\n");
|
615 |
616 |
out.append(" </user>\n");
|
... | ... | |
642 |
643 |
}
|
643 |
644 |
|
644 |
645 |
if (isValid) {
|
|
646 |
//String group = args[2];
|
645 |
647 |
HashMap userInfo = authservice.getAttributes(user, password, user);
|
646 |
|
|
647 |
648 |
// Print all of the attributes
|
648 |
649 |
Iterator attList = (Iterator)(((Set)userInfo.keySet()).iterator());
|
649 |
650 |
while (attList.hasNext()) {
|
... | ... | |
665 |
666 |
for (int i=0; i < users.length; i++) {
|
666 |
667 |
System.out.println(users[i]);
|
667 |
668 |
}
|
|
669 |
System.out.println("Total " + users.length + " users.");
|
668 |
670 |
}
|
669 |
671 |
*/
|
670 |
672 |
/*
|
... | ... | |
677 |
679 |
}
|
678 |
680 |
}
|
679 |
681 |
*/
|
680 |
|
/* // get the whole list groups and users in XML format
|
|
682 |
// get the whole list groups and users in XML format
|
681 |
683 |
if (isValid) {
|
682 |
684 |
String out = authservice.getPrincipals(user, password);
|
683 |
685 |
java.io.File f = new java.io.File("principals.txt");
|
... | ... | |
688 |
690 |
buff.close();
|
689 |
691 |
fw.close();
|
690 |
692 |
}
|
691 |
|
*/
|
|
693 |
|
692 |
694 |
} catch (ConnectException ce) {
|
693 |
695 |
System.err.println("Error connecting to LDAP server in authldap.main");
|
694 |
696 |
} catch (java.io.IOException ioe) {
|
fixes around getUsers and getGroups.
"getprincipals" action can now produce output like:
<principals>
<group>
<groupname>Administrators<groupname>
<user>
<username>uid=admin,o=NCEAS, c=US<username>
</user>
</group>
<group>
<groupname>Postmaster<groupname>
</group>
<group>
<groupname>TestList<groupname>
<user>
<username>cn=Matt Jones,o=NCEAS,c=US<username>
</user>
</group>
<group>
<groupname>office<groupname>
<user>
<username>cn=Marilyn Snowball, o=NCEAS,c=US<username>
</user>
<user>
<username>cn=John Gaffney, o=NCEAS,c=US<username>
</user>
<user>
<username>cn=Jim Reichman, o=NCEAS,c=US<username>
</user>
<user>
<username>cn=Sue Alemdar,o=NCEAS,c=US<username>
</user>
<user>
<username>cn=Nita Mares,o=NCEAS,c=US<username>
</user>
<user>
<username>uid=yamada,o=NCEAS,c=US<username>
</user>
<user>
<username>uid=andelman,o=NCEAS,c=US<username>
</user>
<user>
<username>uid=lee,o=NCEAS,c=US<username>
</user>
<user>
<username>uid=keiling,o=NCEAS,c=US<username>
</user>
<user>
<username>uid=ossinger,o=NCEAS,c=US<username>
</user>
<user>
<username>uid=bierwage,o=NCEAS,c=US<username>
</user>
<user>
<username>cn=sabo,o=NCEAS,c=US<username>
</user>
<user>
<username>uid=choe,o=NCEAS,c=US<username>
</user>
</group>
<group>
<groupname>tech<groupname>
<user>
<username>cn=Matt Jones, o=NCEAS,c=US<username>
</user>
<user>
<username>cn=Mark P. Schildhauer, o=NCEAS,c=US<username>
</user>
<user>
<username>uid=walswort,o=NCEAS,c=US<username>
</user>
<user>
<username>uid=barteet,o=NCEAS,c=US<username>
</user>
<user>
<username>uid=brandts,o=NCEAS,c=US<username>
</user>
</group>
<group>
<groupname>allstaff<groupname>
<user>
<username>cn=office, o=NCEAS,c=US<username>
</user>
<user>
<username>cn=tech, o=NCEAS,c=US<username>
</user>
</group>
<group>
<groupname>sabgroup<groupname>
<user>
<username>cn=Science Advisory Board, o=NCEAS,c=US<username>
</user>
<user>
<username>cn=allstaff, o=NCEAS,c=US<username>
</user>
</group>
<user>
<username>admin<username>
</user>
<user>
<username>jones<username>
</user>
<user>
<username>staufenb<username>
</user>
<user>
<username>snowball<username>
</user>
<user>
<username>gaffney<username>
</user>
<user>
<username>deweese<username>
</user>
<user>
<username>satow<username>
</user>
<user>
<username>sab<username>
</user>
<user>
<username>reichman<username>
</user>
<user>
<username>davis<username>
</user>
<user>
<username>lenehan<username>
</user>
<user>
<username>schild<username>
</user>
<user>
<username>rehmer<username>
</user>
<user>
<username>hosts<username>
</user>
<user>
<username>lids<username>
</user>
<user>
<username>tundra<username>
</user>
<user>
<username>apex<username>
</user>
<user>
<username>arctic<username>
</user>
<user>
<username>spatialdata<username>
</user>
<user>
<username>tracegaswg<username>
</user>
<user>
<username>meta-analysis<username>
</user>
<user>
<username>productivity<username>
</user>
<user>
<username>dataman<username>
</user>
<user>
<username>coevo<username>
</user>
<user>
<username>spborders<username>
</user>
<user>
<username>kdi<username>
</user>
<user>
<username>ecoessay<username>
</user>
<user>
<username>altlanduse<username>
</user>
<user>
<username>biodiv<username>
</user>
<user>
<username>communitydynamics<username>
</user>
<user>
<username>ecoscience<username>
</user>
<user>
<username>aerc<username>
</user>
<user>
<username>esadata<username>
</user>
<user>
<username>tnc<username>
</user>
<user>
<username>reserves<username>
</user>
<user>
<username>rapid-evo<username>
</user>
<user>
<username>geneflow<username>
</user>
<user>
<username>hcp<username>
</user>
<user>
<username>netpp<username>
</user>
<user>
<username>npp_dec<username>
</user>
<user>
<username>collabra<username>
</user>
<user>
<username>diverse<username>
</user>
<user>
<username>roldan<username>
</user>
<user>
<username>sitevisit<username>
</user>
<user>
<username>invasion<username>
</user>
<user>
<username>villarreal<username>
</user>
<user>
<username>marine<username>
</user>
<user>
<username>deepsea<username>
</user>
<user>
<username>omweg<username>
</user>
<user>
<username>hcpreview<username>
</user>
<user>
<username>treegr<username>
</user>
<user>
<username>obfs<username>
</user>
<user>
<username>scope<username>
</user>
<user>
<username>informatics<username>
</user>
<user>
<username>capital<username>
</user>
<user>
<username>sedgwick<username>
</user>
<user>
<username>reach<username>
</user>
<user>
<username>alemdar<username>
</user>
<user>
<username>mares<username>
</user>
<user>
<username>expertise<username>
</user>
<user>
<username>pmpd<username>
</user>
<user>
<username>mma<username>
</user>
<user>
<username>monitor<username>
</user>
<user>
<username>carbseq<username>
</user>
<user>
<username>yamada<username>
</user>
<user>
<username>download<username>
</user>
<user>
<username>epri<username>
</user>
<user>
<username>andelman<username>
</user>
<user>
<username>recovery<username>
</user>
<user>
<username>warming<username>
</user>
<user>
<username>compete<username>
</user>
<user>
<username>henderson<username>
</user>
<user>
<username>bodysize<username>
</user>
<user>
<username>scaling<username>
</user>
<user>
<username>choe<username>
</user>
<user>
<username>evidence<username>
</user>
<user>
<username>sustainable<username>
</user>
<user>
<username>lee<username>
</user>
<user>
<username>keiling<username>
</user>
<user>
<username>emdi<username>
</user>
<user>
<username>flood<username>
</user>
<user>
<username>statmod<username>
</user>
<user>
<username>forecast<username>
</user>
<user>
<username>erisk<username>
</user>
<user>
<username>hcpreport<username>
</user>
<user>
<username>atbgc<username>
</user>
<user>
<username>hydro<username>
</user>
<user>
<username>walswort<username>
</user>
<user>
<username>phylo<username>
</user>
<user>
<username>ossinger<username>
</user>
<user>
<username>marine-ed<username>
</user>
<user>
<username>sessile<username>
</user>
<user>
<username>brown<username>
</user>
<user>
<username>rosenber<username>
</user>
<user>
<username>marine-rec<username>
</user>
<user>
<username>bierwage<username>
</user>
<user>
<username>marinedata<username>
</user>
<user>
<username>amboseli<username>
</user>
<user>
<username>marpop<username>
</user>
<user>
<username>infectious<username>
</user>
<user>
<username>test9999<username>
</user>
<user>
<username>test9998<username>
</user>
<user>
<username>ecostoichio<username>
</user>
<user>
<username>wetland<username>
</user>
<user>
<username>jimlab<username>
</user>
<user>
<username>sitereview<username>
</user>
<user>
<username>field<username>
</user>
<user>
<username>space<username>
</user>
<user>
<username>intertidal<username>
</user>
<user>
<username>evorate<username>
</user>
<user>
<username>biogeography<username>
</user>
<user>
<username>boundary<username>
</user>
<user>
<username>barteet<username>
</user>
<user>
<username>mast<username>
</user>
<user>
<username>brandts<username>
</user>
<user>
<username>paleodb<username>
</user>
<user>
<username>vegclass<username>
</user>
<user>
<username>nottrott<username>
</user>
<user>
<username>bojilova<username>
</user>
<user>
<username>berkley<username>
</user>
<user>
<username>higgins<username>
</user>
<user>
<username>forest<username>
</user>
<user>
<username>knbseminar<username>
</user>
<user>
<username>downloadagent<username>
</user>
<user>
<username>cbloch<username>
</user>
<user>
<username>esobek<username>
</user>
<user>
<username>rstevens<username>
</user>
<user>
<username>ewalker<username>
</user>
<user>
<username>trobertson<username>
</user>
<user>
<username>scox<username>
</user>
<user>
<username>sandlin<username>
</user>
<user>
<username>mernest<username>
</user>
<user>
<username>bkinlan<username>
</user>
<user>
<username>slester<username>
</user>
<user>
<username>rwilder<username>
</user>
<user>
<username>shamilton<username>
</user>
<user>
<username>sromanach<username>
</user>
<user>
<username>lbusse<username>
</user>
<user>
<username>mjennings<username>
</user>
<user>
<username>swatts<username>
</user>
<user>
<username>kwhitney<username>
</user>
<user>
<username>rwaide<username>
</user>
<user>
<username>wgannon<username>
</user>
<user>
<username>vgremillion<username>
</user>
<user>
<username>jgrode<username>
</user>
<user>
<username>mmoses<username>
</user>
<user>
<username>ewhite<username>
</user>
<user>
<username>ahurlbert<username>
</user>
<user>
<username>vertdist<username>
</user>
<user>
<username>otter<username>
</user>
<user>
<username>oid<username>
</user>
<user>
<username>eddins<username>
</user>
<user>
<username>blankman<username>
</user>
</principals>