- Adding title (or comment) to the Resource object
authordousti <dousti@ab3bd59b-922f-494d-bb5f-6f0a3c29deca>
Tue, 30 Jul 2002 18:42:13 +0000 (18:42 +0000)
committerdousti <dousti@ab3bd59b-922f-494d-bb5f-6f0a3c29deca>
Tue, 30 Jul 2002 18:42:13 +0000 (18:42 +0000)
- Adding support for the above to the command util (ArpUtil).
- Cleanup on ArpUtil with -dir flag.

git-svn-id: https://subversion.switch.ch/svn/shibboleth/java-idp/trunk@241 ab3bd59b-922f-494d-bb5f-6f0a3c29deca

src/edu/internet2/middleware/shibboleth/aa/Arp.java
src/edu/internet2/middleware/shibboleth/aa/ArpResource.java
src/edu/internet2/middleware/shibboleth/aa/arpUtil/ArpUtil.java

index 17765ca..25772e1 100755 (executable)
@@ -219,9 +219,6 @@ public class Arp extends ArpCore implements Serializable{
     //this.acl = acl;
     //}
 
-    //    public String urlToShar(String url) {
-    //    }
-
     public String toString(){
        return name+(isAdmin?"(admin)":"");
     }
index 57459bc..b4b7e5f 100755 (executable)
@@ -66,13 +66,14 @@ public class ArpResource extends ArpCore implements Serializable{
 
     // Attributes
     protected String name;
+    protected String comment;
 
     // Associations
     protected TName tName;
     protected Vector attributes;
     protected AA_Acl acl;
 
-    // constructor
+    // constructors
     public ArpResource(String name) throws NotOwnerException{
        this.name = name;
        tName = new TName(name);
@@ -80,6 +81,12 @@ public class ArpResource extends ArpCore implements Serializable{
        makeAcl("resourceAcl");
     }
 
+    public ArpResource(String name, String comment) throws NotOwnerException{
+       this(name);
+       this.comment = comment;
+    }
+
+
     // Operations
     public String toString() {
        return name+" ["+tName+"]";
@@ -171,6 +178,14 @@ public class ArpResource extends ArpCore implements Serializable{
        return name;
     }
 
+    public String getComment(){
+       return comment;
+    }
+
+    public void setComment(String s){
+       this.comment = s;
+    }
+
     public boolean equals(Object rsrc){
        return name.equals(((ArpResource)rsrc).getName());
     }
index 776c57d..5a60d87 100755 (executable)
@@ -71,8 +71,8 @@ class ArpUtil{
     private static Logger log = Logger.getLogger(ArpUtil.class.getName());
     static Principal user;
     static ArpFactory arpFactory;
-    static String listUsage = "\tArpUtil list <arp name> [-acls] [-dir <ldap url> <user id>] [-sql <sql url> <user id>]";
-    static String addUsage = "\tArpUtil add <arp name> [-admin] <shar name> [-default] <url> <attribute name> [-exclude] [-filter [!]<val1> [!]<val2> ...]";    
+    static String listUsage = "\tArpUtil list <arp name> [-acls] [-dir <ldap url> <user id>]";
+    static String addUsage = "\tArpUtil add <arp name> [-admin] <shar name> [-default] <url> [-title comment] <attribute name> [-exclude] [-filter [!]<val1> [!]<val2> ...]";    
     static String removeUsage = "\tArpUtil remove <arp name> [<shar name> [<url> [<attribute name>]]]";
     static String setAclUsage = "\tArpUtil setAcl <user> <acl> <arp name> [<shar name> [<url>]]";
     static String attrUsage = "\tArpUtil listAttributes <jar file name>";
@@ -122,14 +122,18 @@ class ArpUtil{
            if(len > 2){
                if(args[2].equalsIgnoreCase("-acls"))
                    acls = true;
-               if(args[2].equalsIgnoreCase("-dir") || args[2].equalsIgnoreCase("-sql"))
+               if(args[2].equalsIgnoreCase("-dir")){
                    if(len < 4){
-                       System.out.println("Usage:\n"+listUsage);                                       return;
+                       System.out.println("Usage:\n"+listUsage);
+                       return;
                    }else{
                        ctx = getUserContext(args);
                    }
-               if(ctx == null)
-                   return;
+                   if(ctx == null){
+                       System.out.println("Failed to get Directory Context.");
+                       return;
+                   }
+               }
            }
 
            Arp arp = arpFactory.getInstance(arpName, false);
@@ -148,6 +152,8 @@ class ArpUtil{
                ArpResource[] resources = shars[i].getResources();
                for(int j=0; j < resources.length; j++){
                    System.out.println("\t\tURL: "+resources[j]);
+                   if(resources[j].getComment() != null)
+                       System.out.println("\t\tTITLE: "+resources[j].getComment());
                    if(acls)
                        System.out.println("\t\tACL: "+resources[j].getAcl());
                    ArpAttribute[] attributes = resources[j].getAttributes();
@@ -188,9 +194,11 @@ class ArpUtil{
        boolean isDefault = false;
        boolean doExclude = false;
        boolean hasFilter = false;
+       boolean showTitle = false;
        String resourceName = null;
        String sharName = null;
        String attrName = null;
+       String title = null;
 
        String arpName = args[i++];
        if(args[i].equalsIgnoreCase("-admin")){
@@ -204,6 +212,14 @@ class ArpUtil{
        }
        if(i < args.length)
            resourceName = args[i++];
+
+       if(i < args.length && args[i].equalsIgnoreCase("-title")){
+           showTitle = true;
+           i++;
+           if(i <args.length)
+               title = args[i++];
+       }
+       
        if(i < args.length)
            attrName = args[i++];
        if(i < args.length && args[i].equalsIgnoreCase("-exclude")){
@@ -241,7 +257,7 @@ class ArpUtil{
                s = new ArpShar(sharName, isDefault);
            ArpResource r = s.getResource(resourceName);
            if(r == null)
-               r = new ArpResource(resourceName);
+               r = new ArpResource(resourceName, title);
            ArpAttribute a = r.getAttribute(attrName);
            if(a == null)
                a = new ArpAttribute(attrName, doExclude);
@@ -446,46 +462,22 @@ class ArpUtil{
     public static DirContext getUserContext(String[] args)
     throws Exception{
 
+       if(args.length <5){
+           System.out.println("Usage:\n"+listUsage);
+           return null;
+       }
+
        String dirUrl = args[3];
        String uid = args[4];
        
         Hashtable env = new Hashtable(11);
 
-       if(args[2].equalsIgnoreCase("-dir")){
-           env.put(Context.INITIAL_CONTEXT_FACTORY,
-                   "com.sun.jndi.ldap.LdapCtxFactory");
-           env.put(Context.PROVIDER_URL, dirUrl);
-
-           DirContext ctx = new InitialDirContext(env);
-           
-           NamingEnumeration ne = ctx.search("", "cmuAndrewId="+uid, null, null);
-           if(ne.hasMoreElements()){
-               SearchResult rs = (SearchResult)ne.nextElement();
-               String guid = (String)rs.getAttributes().get("GUID").get();
-               return (DirContext)ctx.lookup("guid="+guid);
-           }else{
-               System.out.println("Search for "+uid+" failed!");
-               return null;
-           }
-
-       }else if(args[2].equalsIgnoreCase("-sql")){
-           env.put(Context.INITIAL_CONTEXT_FACTORY,
-                   "SQLCtxFactory");
-
-           // a Sample of possible args to pass to context
-           env.put(Context.PROVIDER_URL, dirUrl);
-           env.put("SQL_DRIVER", "oracle.jdbc.OracleDriver");
-           env.put("SECURITY_PRINCIPAL", "dousti");
-           env.put("SECURITY_CREDENTIALS", "foobar");
-           env.put("USER_IDENTIFIER", args[4]);
-           DirContext ctx = new InitialDirContext(env);
-           return ctx;
-
-       }else{
-           System.out.println("Usage:\n"+listUsage);
-           return null;
-       }
-       
+       env.put(Context.INITIAL_CONTEXT_FACTORY,
+               "com.sun.jndi.ldap.LdapCtxFactory");
+       env.put(Context.PROVIDER_URL, dirUrl);
+       DirContext ctx = new InitialDirContext(env);
+       return (DirContext)ctx.lookup("uid="+uid);
+               
     }
        
 }