Initial Version
authordousti <dousti@ab3bd59b-922f-494d-bb5f-6f0a3c29deca>
Fri, 7 Jun 2002 20:45:30 +0000 (20:45 +0000)
committerdousti <dousti@ab3bd59b-922f-494d-bb5f-6f0a3c29deca>
Fri, 7 Jun 2002 20:45:30 +0000 (20:45 +0000)
git-svn-id: https://subversion.switch.ch/svn/shibboleth/java-idp/trunk@43 ab3bd59b-922f-494d-bb5f-6f0a3c29deca

src/edu/internet2/middleware/shibboleth/aaLocal/CmuCtxFactory.java [new file with mode: 0755]
src/edu/internet2/middleware/shibboleth/aaLocal/CmuDirContext.java [new file with mode: 0755]
src/edu/internet2/middleware/shibboleth/aaLocal/EchoCtxFactory.java [new file with mode: 0755]
src/edu/internet2/middleware/shibboleth/aaLocal/EchoDirContext.java [new file with mode: 0755]
src/edu/internet2/middleware/shibboleth/aaLocal/SQLCtxFactory.java [new file with mode: 0755]
src/edu/internet2/middleware/shibboleth/aaLocal/SQLDirContext.java [new file with mode: 0755]
src/edu/internet2/middleware/shibboleth/aaLocal/attributes/cmuAndrewId.java [new file with mode: 0644]
src/edu/internet2/middleware/shibboleth/aaLocal/attributes/eduPersonAffiliation.java [new file with mode: 0644]
src/edu/internet2/middleware/shibboleth/aaLocal/attributes/eduPersonPrincipalName.java [new file with mode: 0644]
src/edu/internet2/middleware/shibboleth/aaLocal/attributes/makefile [new file with mode: 0755]
src/edu/internet2/middleware/shibboleth/aaLocal/makefile [new file with mode: 0755]

diff --git a/src/edu/internet2/middleware/shibboleth/aaLocal/CmuCtxFactory.java b/src/edu/internet2/middleware/shibboleth/aaLocal/CmuCtxFactory.java
new file mode 100755 (executable)
index 0000000..c08d530
--- /dev/null
@@ -0,0 +1,13 @@
+import java.util.Hashtable;
+import javax.naming.*;
+import javax.naming.spi.*;
+
+
+public class CmuCtxFactory implements InitialContextFactory{
+
+    public Context getInitialContext(Hashtable env)
+       throws NamingException{
+       return new CmuDirContext(env);
+    }
+
+}
diff --git a/src/edu/internet2/middleware/shibboleth/aaLocal/CmuDirContext.java b/src/edu/internet2/middleware/shibboleth/aaLocal/CmuDirContext.java
new file mode 100755 (executable)
index 0000000..46f1678
--- /dev/null
@@ -0,0 +1,44 @@
+import java.util.*;
+import javax.naming.*;
+import javax.naming.directory.*;
+
+public class CmuDirContext extends InitialDirContext{
+
+    DirContext ctx; 
+
+    public CmuDirContext(Hashtable env)
+       throws NamingException{
+
+       Hashtable env1 = new Hashtable(11);
+       env1.put(Context.INITIAL_CONTEXT_FACTORY,
+              "com.sun.jndi.ldap.LdapCtxFactory");
+
+       env1.put(Context.PROVIDER_URL, env.get(Context.PROVIDER_URL));
+       ctx = new InitialDirContext(env1);
+    }
+
+    
+    public Object lookup(String s) throws NamingException{
+       String uid = null;
+
+       int i = s.indexOf("=");
+       if(i >= 0)
+           uid = s.substring(i+1);
+       else
+           uid = s;
+
+       NamingEnumeration ne = ctx.search("", "cmuAndrewId="+uid, null, null);
+
+       if(ne != null && ne.hasMoreElements()){
+           SearchResult rs = (SearchResult)ne.nextElement();
+           String guid = (String)rs.getAttributes().get("GUID").get();
+           return ctx.lookup("guid="+guid);
+       }
+       return null;
+    }
+    
+    public Attributes getAttributes(String name, String[] ids)
+       throws NamingException{
+       return ctx.getAttributes(name, ids);
+    }
+}
diff --git a/src/edu/internet2/middleware/shibboleth/aaLocal/EchoCtxFactory.java b/src/edu/internet2/middleware/shibboleth/aaLocal/EchoCtxFactory.java
new file mode 100755 (executable)
index 0000000..c071d9d
--- /dev/null
@@ -0,0 +1,13 @@
+import java.util.Hashtable;
+import javax.naming.*;
+import javax.naming.spi.*;
+
+
+public class EchoCtxFactory implements InitialContextFactory{
+
+    public Context getInitialContext(Hashtable env)
+       throws NamingException{
+       return new EchoDirContext(env);
+    }
+
+}
diff --git a/src/edu/internet2/middleware/shibboleth/aaLocal/EchoDirContext.java b/src/edu/internet2/middleware/shibboleth/aaLocal/EchoDirContext.java
new file mode 100755 (executable)
index 0000000..e47bff7
--- /dev/null
@@ -0,0 +1,42 @@
+import java.util.*;
+import javax.naming.*;
+import javax.naming.directory.*;
+
+public class EchoDirContext extends InitialDirContext{
+
+    String uid = "unknown";
+    
+
+    public EchoDirContext(Hashtable env)
+       throws NamingException{
+    }
+
+    
+    public Object lookup(String s) throws NamingException{
+       int i = s.indexOf("=");
+       if(i >= 0)
+           uid = s.substring(i+1);
+       else
+           uid = s;
+
+       return this;
+    }
+    
+    public Attributes getAttributes(String name, String[] ids)
+       throws NamingException{
+
+       BasicAttributes attrs = new BasicAttributes();
+
+       for(int i=0; i<ids.length; i++){
+           if(ids[i].equalsIgnoreCase("eduPersonAffiliation")){
+               // return member as value;
+               attrs.put(new BasicAttribute("eduPersonAffiliation", "member"));
+           }
+           if(ids[i].equalsIgnoreCase("eduPersonPrincipalName")){
+               // return uid
+               attrs.put(new BasicAttribute("eduPersonPrincipalName", uid));
+           }
+       }
+       return attrs;
+    }
+}
diff --git a/src/edu/internet2/middleware/shibboleth/aaLocal/SQLCtxFactory.java b/src/edu/internet2/middleware/shibboleth/aaLocal/SQLCtxFactory.java
new file mode 100755 (executable)
index 0000000..e28103d
--- /dev/null
@@ -0,0 +1,13 @@
+import java.util.Hashtable;
+import javax.naming.*;
+import javax.naming.spi.*;
+
+
+public class SQLCtxFactory implements InitialContextFactory{
+
+    public Context getInitialContext(Hashtable env)
+       throws NamingException{
+       return new SQLDirContext(env);
+    }
+
+}
diff --git a/src/edu/internet2/middleware/shibboleth/aaLocal/SQLDirContext.java b/src/edu/internet2/middleware/shibboleth/aaLocal/SQLDirContext.java
new file mode 100755 (executable)
index 0000000..e5b04ab
--- /dev/null
@@ -0,0 +1,106 @@
+import java.util.*;
+import java.sql.*;
+import javax.naming.*;
+import javax.naming.directory.*;
+
+public class SQLDirContext extends InitialDirContext{
+
+    Connection con;
+    String uid;
+    String guid;
+    Hashtable id2name;
+
+    public SQLDirContext(Hashtable env)
+       throws NamingException{
+
+       String url = (String)env.get(Context.PROVIDER_URL);
+       String driver = (String)env.get("SQL_DRIVER");
+       String user = (String)env.get("SECURITY_PRINCIPAL");
+       String passwd = (String)env.get("SECURITY_CREDENTIALS");
+       uid = (String)env.get("USER_IDENTIFIER");
+       if(url == null)
+           throw new NamingException("Context.PROVIDER_URL not provided");
+       if(driver == null)
+           throw new NamingException("SQL_DRIVER is required");
+       if(user == null)
+           throw new NamingException("SECURITY_PRINCIPAL is required");
+       if(passwd == null)
+           throw new NamingException("SECURITY_CREDENTIALS is required");
+       if(uid == null)
+           throw new NamingException("USER_IDENTIFIER is required");
+       id2name = new Hashtable();
+
+
+
+       try{
+           Class.forName(driver);
+           con = DriverManager.getConnection(url, user, passwd);
+           // get the small sql table and keep it as a hashtable for performance
+           Statement stmt = con.createStatement();
+           ResultSet rs = stmt.executeQuery("SELECT attr_id,attr_name from danr.person_attributes");       
+           while(rs.next()){
+               int i = rs.getInt("attr_id");
+               String n = rs.getString("attr_name");
+               id2name.put(new Integer(i), n);
+           }
+
+           // find the guid from uid
+           String guidQ1 = "SELECT guid from danr.person_attrib WHERE attr_id = ";
+           String guidQ2 = "(SELECT attr_id from danr.person_attributes where attr_name = 'cmuAndrewId')";
+           String guidQ3 = " AND attr_value = '"+uid+"'";
+
+
+           rs = stmt.executeQuery(guidQ1+guidQ2+guidQ3);
+           rs.next();
+           guid = rs.getString("GUID");
+       }catch(Exception e){
+           throw new NamingException("Failed to create SQLDirContext: "+e);
+       }
+    }
+
+    public Attributes getAttributes(String name,
+                                   String[] attrIds)
+       throws NamingException {
+
+       long aTime = System.currentTimeMillis();
+       String q1 = "select attr_id,attr_value from danr.person_attrib where guid = '";
+       String q2 = "' and attr_id = (select attr_id from danr.person_attributes where attr_name ='";
+       String q3 = "')";
+       StringBuffer buf = new StringBuffer(q1+guid+q2);
+       BasicAttributes attrs = new BasicAttributes();
+       try{
+           int len = attrIds.length;
+
+           String[] attrNames = new String[len];
+           System.arraycopy(attrIds, 0, attrNames, 0, len);
+           Arrays.sort(attrNames);
+
+           for(int i=0; i <len-1; i++)
+               buf.append(attrIds[i] + "' OR attr_name ='");
+           buf.append(attrIds[len-1]);
+           buf.append(q3);
+
+           Statement stmt = con.createStatement();
+           ResultSet rs = stmt.executeQuery(buf.toString());       
+
+           BasicAttribute[] attrArray = new BasicAttribute[len];
+           for(int i=0; i <len; i++)
+               attrArray[i] = new BasicAttribute(attrIds[i]);
+
+           while(rs.next()){
+               int anId = rs.getInt("attr_id");
+               String aName = (String)id2name.get(new Integer(anId));
+               Object value = rs.getObject("attr_value");
+               int indx = Arrays.binarySearch(attrNames, aName);
+               attrArray[indx].add(value);
+           }
+           
+           for(int i=0; i <len; i++)
+               attrs.put(attrArray[i]);
+           System.out.print(" ("+(System.currentTimeMillis() - aTime)+" sec)");
+           return attrs;
+       }catch(Exception e){
+           throw new NamingException("Failed to get Attributes: "+e);
+       }
+    }
+}
diff --git a/src/edu/internet2/middleware/shibboleth/aaLocal/attributes/cmuAndrewId.java b/src/edu/internet2/middleware/shibboleth/aaLocal/attributes/cmuAndrewId.java
new file mode 100644 (file)
index 0000000..ca39158
--- /dev/null
@@ -0,0 +1,22 @@
+import edu.internet2.middleware.eduPerson.*;
+import edu.internet2.middleware.shibboleth.Constants; 
+import org.opensaml.*;
+
+
+public class cmuAndrewId extends ScopedAttribute{
+    
+
+    public cmuAndrewId(String[] scopes, Object[] values)
+       throws SAMLException{
+
+       this.super("urn:mace:eduPerson:1.0:eduPersonPrincipalName",
+                  Constants.SHIB_ATTRIBUTE_NAMESPACE_URI, 
+                  new QName("urn:mace:eduPerson:1.0",
+                            "eduPersonPrincipalNameType"),
+                  10*60,
+                  values,
+                  scopes[0],
+                  scopes);
+    }
+}
+
diff --git a/src/edu/internet2/middleware/shibboleth/aaLocal/attributes/eduPersonAffiliation.java b/src/edu/internet2/middleware/shibboleth/aaLocal/attributes/eduPersonAffiliation.java
new file mode 100644 (file)
index 0000000..903aa32
--- /dev/null
@@ -0,0 +1,36 @@
+import edu.internet2.middleware.eduPerson.*;
+import edu.internet2.middleware.shibboleth.Constants; 
+import org.opensaml.*;
+
+public class eduPersonAffiliation extends ScopedAttribute{
+    
+
+    public eduPersonAffiliation(String[] scopes, Object[] values)
+       throws SAMLException{
+
+       this.super("urn:mace:eduPerson:1.0:eduPersonAffiliation",
+                  Constants.SHIB_ATTRIBUTE_NAMESPACE_URI, 
+                  new QName("urn:mace:eduPerson:1.0",
+                            "eduPersonAffiliationType"),
+                  10*60,
+                  values,
+                  scopes[0],
+                  scopes);
+
+     for(int i=0; i<super.values.length; i++){
+       String val = (String)super.values[i];
+       if(val.equalsIgnoreCase("faculty") ||
+          val.equalsIgnoreCase("student") ||
+          val.equalsIgnoreCase("staff") ||
+          val.equalsIgnoreCase("alum") ||
+          val.equalsIgnoreCase("member") ||
+          val.equalsIgnoreCase("affiliate") ||
+          val.equalsIgnoreCase("employee") )
+           super.values[i] = val.toLowerCase();
+       else
+           super.values[i] = "member";
+     }
+
+    }
+}
+
diff --git a/src/edu/internet2/middleware/shibboleth/aaLocal/attributes/eduPersonPrincipalName.java b/src/edu/internet2/middleware/shibboleth/aaLocal/attributes/eduPersonPrincipalName.java
new file mode 100644 (file)
index 0000000..27d4644
--- /dev/null
@@ -0,0 +1,24 @@
+import edu.internet2.middleware.eduPerson.*;
+import edu.internet2.middleware.shibboleth.Constants; 
+import org.opensaml.*;
+
+public class eduPersonPrincipalName extends ScopedAttribute{
+    
+
+    public eduPersonPrincipalName(String[] scopes, Object[] values)
+       throws SAMLException{
+
+       this.super("urn:mace:eduPerson:1.0:eduPersonPrincipalName",
+                  Constants.SHIB_ATTRIBUTE_NAMESPACE_URI, 
+                  new QName("urn:mace:eduPerson:1.0",
+                            "eduPersonPrincipalNameType"),
+                  10*60,
+                  values,
+                  scopes[0],
+                  scopes);
+
+       if(((String)values[0]).indexOf("@") < 0)
+           super.values[0] = (String)values[0]+"@"+scopes[0];
+    }
+}
+
diff --git a/src/edu/internet2/middleware/shibboleth/aaLocal/attributes/makefile b/src/edu/internet2/middleware/shibboleth/aaLocal/attributes/makefile
new file mode 100755 (executable)
index 0000000..7d6881f
--- /dev/null
@@ -0,0 +1,12 @@
+RTLIB=/afs/andrew/acs/asg/shibboleth/runtime/java/v2/lib/
+CMULIB=/afs/andrew/acs/asg/shibboleth/cmu/beta/lib/
+
+CP=.:${RTLIB}/xercesImpl.jar:${RTLIB}/xmlParserAPIs.jar:${RTLIB}/shibboleth.jar:${RTLIB}/opensaml.jar:~blk/src/shib/mm.mysql-2.0.8-bin.jar:/usr/www/tomcat/lib/servlet.jar:${CMULIB}/aa.jar:${CMULIB}/jndi.jar:${CMULIB}/ldap.jar
+
+DESTDIR=/afs/andrew/acs/asg/shibboleth/cmu/beta/lib
+
+all:   *.java
+       javac -classpath ${CP} *.java
+       jar cvf attributes.jar *.class
+       cp attributes.jar ${DESTDIR}
+
diff --git a/src/edu/internet2/middleware/shibboleth/aaLocal/makefile b/src/edu/internet2/middleware/shibboleth/aaLocal/makefile
new file mode 100755 (executable)
index 0000000..edebac7
--- /dev/null
@@ -0,0 +1,24 @@
+RTLIB=/afs/andrew/acs/asg/shibboleth/runtime/java/v2/lib/
+CMULIB=/afs/andrew/acs/asg/shibboleth/cmu/beta/lib/
+
+CP=.:${RTLIB}/xercesImpl.jar:${RTLIB}/xmlParserAPIs.jar:${RTLIB}/shibboleth.jar:${RTLIB}/opensaml.jar:~blk/src/shib/mm.mysql-2.0.8-bin.jar:/usr/www/tomcat/lib/servlet.jar:${CMULIB}/aa.jar:${CMULIB}/jndi.jar:${CMULIB}/ldap.jar
+
+
+INSTDIR=/afs/andrew/acs/asg/shibboleth/cmu/beta/lib
+
+
+all: aaLocal.jar attributes
+
+aaLocal.jar: *.class
+       jar -cvf aaLocal.jar *class
+       
+
+attributes: attributes/*.java
+       cd attributes;make $*
+
+
+*.class:  *.java
+       javac -g -classpath ${CP} *.java
+
+install:  all
+       cp aaLocal.jar ${INSTDIR}