import java.io.IOException;
import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.NamingException;
import javax.naming.ldap.InitialLdapContext;
import javax.naming.ldap.LdapContext;
import com.novell.service.ndssdk.jndi.ldap.ext.GetEffectiveRightsRequest;
import com.novell.service.ndssdk.jndi.ldap.ext.GetEffectiveRightsResponse;
import com.novell.service.ndssdk.jndi.ldap.ext.LdapRights;
import com.novell.service.ndssdk.jndi.ldap.ext.LDAPExtendedResponse;
public class GetEffectiveRights {
public static void main(String[] args) {
if (args.length != 5) {
usage();
}
String hostURL = args[0];
String loginDN = args[1];
String passWord = args[2];
String entryDN = args[3];
String trusteeDN = args[4];
try {
Hashtable env = new Hashtable(5, 0.75f);
env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, hostURL);
env.put(Context.SECURITY_AUTHENTICATION, "simple" );
env.put(Context.SECURITY_PRINCIPAL, loginDN );
env.put(Context.SECURITY_CREDENTIALS, passWord );
LdapContext ctx = new InitialLdapContext(env, null);
String attrName = "[All Attributes Rights]";
GetEffectiveRightsRequest reqs = new GetEffectiveRightsRequest(
entryDN, trusteeDN, attrName);
GetEffectiveRightsResponse resp = (GetEffectiveRightsResponse)
ctx.extendedOperation(reqs);
LdapRights right = resp.getRights();
System.out.println("\n\tThe trustee " + trusteeDN
+ " has the following " + attrName
+ " on the object " + entryDN + " :\n" + right);
System.out.println("\n\tGetEffectiveRights operation succeeded.");
}
catch (NamingException e) {
System.err.println("\n\tGetEffectiveRights operation failed.");
e.printStackTrace();
}
catch (IOException ioe) {
System.err.println("\n\tGetEffectiveRights operation failed.");
ioe.printStackTrace();
}
finally {
System.exit(0);
}
}
public static void usage() {
System.err.println("\n Usage : java GetEffectiveRights <host URL>"
+ " <login dn> <password>\n <entry DN> <trustee DN>\n");
System.err.println(" Example: java GetEffectiveRights ldap://Acme.com:"
+ "389 cn=admin,o=Acme secret\n cn=james,o=Acme cn=admin"
+ ",o=Acme");
System.exit(1);
}
}