directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r493667 - in /directory/sandbox/triplesec-jacc2: guardian-api/src/main/java/org/safehaus/triplesec/guardian/ guardian-ldap/src/main/java/org/safehaus/triplesec/guardian/ldap/ integration/src/main/java/org/safehaus/triplesec/integration/ ite...
Date Sun, 07 Jan 2007 06:31:56 GMT
Author: djencks
Date: Sat Jan  6 22:31:55 2007
New Revision: 493667

URL: http://svn.apache.org/viewvc?view=rev&rev=493667
Log:
add some basic support for java permissions in guardian, with a very simple test

Modified:
    directory/sandbox/triplesec-jacc2/guardian-api/src/main/java/org/safehaus/triplesec/guardian/EntryApplicationPolicy.java
    directory/sandbox/triplesec-jacc2/guardian-ldap/src/main/java/org/safehaus/triplesec/guardian/ldap/LdapApplicationPolicy.java
    directory/sandbox/triplesec-jacc2/integration/src/main/java/org/safehaus/triplesec/integration/TriplesecIntegration.java
    directory/sandbox/triplesec-jacc2/itest-data/src/main/resources/server.ldif

Modified: directory/sandbox/triplesec-jacc2/guardian-api/src/main/java/org/safehaus/triplesec/guardian/EntryApplicationPolicy.java
URL: http://svn.apache.org/viewvc/directory/sandbox/triplesec-jacc2/guardian-api/src/main/java/org/safehaus/triplesec/guardian/EntryApplicationPolicy.java?view=diff&rev=493667&r1=493666&r2=493667
==============================================================================
--- directory/sandbox/triplesec-jacc2/guardian-api/src/main/java/org/safehaus/triplesec/guardian/EntryApplicationPolicy.java
(original)
+++ directory/sandbox/triplesec-jacc2/guardian-api/src/main/java/org/safehaus/triplesec/guardian/EntryApplicationPolicy.java
Sat Jan  6 22:31:55 2007
@@ -26,6 +26,8 @@
 import java.util.Set;
 import java.util.HashSet;
 import java.util.HashMap;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
 
 import javax.naming.directory.Attributes;
 import javax.naming.directory.Attribute;
@@ -33,7 +35,7 @@
 import javax.naming.NamingEnumeration;
 
 /**
- * @version $Rev:$ $Date:$
+ * @version $Rev$ $Date$
  */
 public abstract class EntryApplicationPolicy implements ApplicationPolicy {
     /** the name of the application this store is associated with */
@@ -55,10 +57,57 @@
 
     protected PermissionEntry loadPermission(Attributes attrs) throws NamingException
     {
-        Permission perm;
-        String permName = ( String ) attrs.get( "permName" ).get();
-        perm = new StringPermission( permName );
-        return new PermissionEntry(permName, perm);
+        Permission perm = null;
+        String permId = getStringAttribute(attrs, "permName");
+        String javaClassName = getStringAttribute(attrs, "permJavaClass");
+        if (javaClassName == null) {
+            perm = new StringPermission( permId );
+        } else {
+            String name = getStringAttribute(attrs, "permJavaName");
+            String actions = getStringAttribute(attrs, "permJavaActions");
+            ClassLoader loader = Thread.currentThread().getContextClassLoader();
+            Class permissionClass;
+            try {
+                permissionClass = Class.forName(javaClassName, true, loader);
+            } catch (ClassNotFoundException e) {
+                throw new NamingException("Could not load permission class " + javaClassName
+ " in classloader " + loader);
+            }
+            try {
+                Constructor<Permission> twoargs = permissionClass.getConstructor(String.class,
String.class);
+                perm = twoargs.newInstance(name, actions);
+            } catch (NoSuchMethodException e) {
+                //ignore
+            } catch (IllegalAccessException e) {
+                throw (NamingException) new NamingException("Could not create permission").initCause(e);
+            } catch (InvocationTargetException e) {
+                throw (NamingException) new NamingException("Could not create permission").initCause(e.getTargetException());
+            } catch (InstantiationException e) {
+                throw (NamingException) new NamingException("Could not create permission").initCause(e);
+            }
+            if (perm == null) {
+                try {
+                    Constructor<Permission> onearg = permissionClass.getConstructor(String.class);
+                    perm = onearg.newInstance(name);
+                } catch (NoSuchMethodException e) {
+                    throw (NamingException) new NamingException("Could not create permission").initCause(e);
+                } catch (IllegalAccessException e) {
+                    throw (NamingException) new NamingException("Could not create permission").initCause(e);
+                } catch (InvocationTargetException e) {
+                    throw (NamingException) new NamingException("Could not create permission").initCause(e.getTargetException());
+                } catch (InstantiationException e) {
+                    throw (NamingException) new NamingException("Could not create permission").initCause(e);
+                }
+            }
+        }
+        return new PermissionEntry(permId, perm);
+    }
+
+    private String getStringAttribute(Attributes attrs, String attrID) throws NamingException
{
+        Attribute attr = attrs.get(attrID);
+        if (attr == null) {
+            return null;
+        }
+        return ( String ) attr.get();
     }
 
     public String getApplicationName()
@@ -83,7 +132,7 @@
 
     protected Role getRole( Attributes attrs ) throws NamingException
     {
-        String roleName = ( String ) attrs.get( "roleName" ).get();
+        String roleName = getStringAttribute(attrs, "roleName");
         Permissions grants = new Permissions();
         Attribute attributes = attrs.get( "grants" );
 

Modified: directory/sandbox/triplesec-jacc2/guardian-ldap/src/main/java/org/safehaus/triplesec/guardian/ldap/LdapApplicationPolicy.java
URL: http://svn.apache.org/viewvc/directory/sandbox/triplesec-jacc2/guardian-ldap/src/main/java/org/safehaus/triplesec/guardian/ldap/LdapApplicationPolicy.java?view=diff&rev=493667&r1=493666&r2=493667
==============================================================================
--- directory/sandbox/triplesec-jacc2/guardian-ldap/src/main/java/org/safehaus/triplesec/guardian/ldap/LdapApplicationPolicy.java
(original)
+++ directory/sandbox/triplesec-jacc2/guardian-ldap/src/main/java/org/safehaus/triplesec/guardian/ldap/LdapApplicationPolicy.java
Sat Jan  6 22:31:55 2007
@@ -224,7 +224,7 @@
     private void loadPermissions() throws GuardianException
     {
         SearchControls ctrls = new SearchControls();
-        ctrls.setReturningAttributes( new String[] { "permName" } );
+        ctrls.setReturningAttributes( new String[] { "permName", "permJavaClass", "permJavaName",
"permJavaActions" } );
         ctrls.setSearchScope( SearchControls.ONELEVEL_SCOPE );
         try
         {
@@ -233,10 +233,9 @@
             while ( list.hasMore() )
             {
                 SearchResult result = list.next();
-                String permName = ( String ) result.getAttributes().get( "permName" ).get();
                 PermissionEntry permEntry = loadPermission( result.getAttributes());
                 permissions.put(permEntry.getPermissionName(), permEntry.getPermission());
-                log.debug( "loading permission " + permName + " for application " + applicationName
);
+                log.debug( "loading permission " + permEntry.getPermissionName() + " for
application " + applicationName );
             }
         }
         catch ( NamingException e )

Modified: directory/sandbox/triplesec-jacc2/integration/src/main/java/org/safehaus/triplesec/integration/TriplesecIntegration.java
URL: http://svn.apache.org/viewvc/directory/sandbox/triplesec-jacc2/integration/src/main/java/org/safehaus/triplesec/integration/TriplesecIntegration.java?view=diff&rev=493667&r1=493666&r2=493667
==============================================================================
--- directory/sandbox/triplesec-jacc2/integration/src/main/java/org/safehaus/triplesec/integration/TriplesecIntegration.java
(original)
+++ directory/sandbox/triplesec-jacc2/integration/src/main/java/org/safehaus/triplesec/integration/TriplesecIntegration.java
Sat Jan  6 22:31:55 2007
@@ -283,7 +283,7 @@
             String msg = "The configuration resources directory '" +
                     resourcesDirectory + "' does not exist will search classpath for resources";
             resourcesDirectory = null;
-            log.error( msg );
+            log.debug( msg );
         }
 
         // --------------------------------------------------------------------

Modified: directory/sandbox/triplesec-jacc2/itest-data/src/main/resources/server.ldif
URL: http://svn.apache.org/viewvc/directory/sandbox/triplesec-jacc2/itest-data/src/main/resources/server.ldif?view=diff&rev=493667&r1=493666&r2=493667
==============================================================================
--- directory/sandbox/triplesec-jacc2/itest-data/src/main/resources/server.ldif (original)
+++ directory/sandbox/triplesec-jacc2/itest-data/src/main/resources/server.ldif Sat Jan  6
22:31:55 2007
@@ -351,7 +351,10 @@
 dn: permName=mockPerm0,ou=permissions,appName=mockApplication,ou=applications,dc=example,dc=com
 objectClass: top
 objectClass: policyPermission
+objectClass: javaPermission
 permName: mockPerm0
+permJavaClass: org.safehaus.triplesec.guardian.StringPermission
+permJavaName: mockPerm0
 
 dn: permName=mockPerm1,ou=permissions,appName=mockApplication,ou=applications,dc=example,dc=com
 objectClass: top



Mime
View raw message