directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: rev 10363 - in incubator/directory/rms/trunk/je/src: java/org/apache/rms/je/role test/org/apache/rms/je/role
Date Wed, 28 Apr 2004 16:22:01 GMT
Author: akarasulu
Date: Wed Apr 28 09:21:59 2004
New Revision: 10363

Modified:
   incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/role/JeRoleDAO.java
   incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/role/RoleDAOMonitor.java
   incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/role/RoleDAOMonitorAdapter.java
   incubator/directory/rms/trunk/je/src/test/org/apache/rms/je/role/JeRoleDAOTest.java
Log:
Commit changes ...

 o completed JeRoleDAO.getGrants() and JeRoleDAO.setGrants()
 o completed unit tests for JeRoleDAO.getGrants() and JeRoleDAO.setGrants()
 o added monitering methods for both methods to the monitor interface
 o added no-op monitor methods for the monitor adapter



Modified: incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/role/JeRoleDAO.java
==============================================================================
--- incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/role/JeRoleDAO.java	(original)
+++ incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/role/JeRoleDAO.java	Wed Apr
28 09:21:59 2004
@@ -449,7 +449,30 @@
      */
     public byte[] getGrants( String appName, String roleName ) throws RmsException
     {
-        throw new NotImplementedException( "STUB" ) ;
+        byte[] grants = null ;
+
+        try
+        {
+            DatabaseEntry data = getRow( appName, roleName, false ) ;
+            grants = BINDING.getGrants( data ) ;
+        }
+        catch ( IOException e )
+        {
+            monitor.failedGrantsLookup( this, appName, roleName, e ) ;
+            throw new RmsException( "Failed to bind entry to a Role", e ) ;
+        }
+        catch ( JeRmsException e )
+        {
+            if ( e.getStatus() == OperationStatus.NOTFOUND )
+            {
+                monitor.roleDoesNotExist( this, "getGrants", appName, roleName ) ;
+            }
+
+            throw e ;
+        }
+
+        monitor.grantsLookedUp( this, appName, roleName, grants ) ;
+        return grants ;
     }
 
 
@@ -465,7 +488,57 @@
      */
     public void setGrants( String appName, String roleName, byte[] grants ) throws RmsException
     {
-        throw new NotImplementedException( "STUB" ) ;
+        OperationStatus status = null ;
+        DatabaseEntry key = null ;
+        DatabaseEntry value = new DatabaseEntry() ;
+
+        try
+        {
+            key = getRow( appName, roleName, true ) ;
+        }
+        catch ( JeRmsException e )
+        {
+            if ( e.getStatus() == OperationStatus.NOTFOUND )
+            {
+                monitor.roleDoesNotExist( this, "setGrants", appName, roleName ) ;
+            }
+
+            throw e ;
+        }
+
+        try
+        {
+            // Get the full data record from primary
+            status = db.get( null, key, value, LockMode.DEFAULT ) ;
+
+            // use appName, roleName and new role grants to construct new record
+            BINDING.objectToEntry( value, appName, roleName, grants ) ;
+
+            // put data record into primary overwriting the old data record
+            status = db.put( null, key, value ) ;
+
+            if ( status != OperationStatus.SUCCESS )
+            {
+                RmsException e = new JeRmsException( status,
+                        "failed to set the grants for role " + roleName
+                        + " for application " + appName + " with status of "
+                        + status.toString() ) ;
+                monitor.failedOnSetGrants( this, appName, roleName, e ) ;
+                throw e ;
+            }
+        }
+        catch ( IOException e )
+        {
+            monitor.failedOnSetGrants( this, appName, roleName, e ) ;
+            throw new RmsException( e ) ;
+        }
+        catch ( DatabaseException e )
+        {
+            monitor.failedOnSetGrants( this, appName, roleName, e ) ;
+            throw new RmsException( e ) ;
+        }
+
+        monitor.roleGrantsAltered( this, appName, roleName, grants ) ;
     }
 
 

Modified: incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/role/RoleDAOMonitor.java
==============================================================================
--- incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/role/RoleDAOMonitor.java	(original)
+++ incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/role/RoleDAOMonitor.java	Wed
Apr 28 09:21:59 2004
@@ -16,12 +16,8 @@
  */
 package org.apache.rms.je.role ;
 
-import org.apache.rms.Role;
-import org.apache.rms.RmsException;
 
-import java.io.IOException;
-
-import com.sleepycat.je.DatabaseException;
+import org.apache.rms.Role ;
 
 
 /**
@@ -161,4 +157,52 @@
      */
     void failedOnRename( JeRoleDAO dao, String appName, String oldName,
                          String newName, Throwable fault ) ;
+
+    /**
+     * Monitors events where a lookup of the grants of an application role
+     * fail.
+     *
+     * @param dao the data access object
+     * @param appName the name of the application
+     * @param roleName the name of the role
+     * @param fault the fault that caused the failure
+     */
+    void failedGrantsLookup( JeRoleDAO dao, String appName, String roleName,
+                             Throwable fault ) ;
+
+    /**
+     * Monitors events where the grants of an application role are
+     * succesfully looked up.
+     *
+     * @param dao the data access object
+     * @param appName the name of the application
+     * @param roleName the name of the role
+     * @param grants the grants for the role that were successfully looked up
+     */
+    void grantsLookedUp( JeRoleDAO dao, String appName, String roleName,
+                         byte[] grants ) ;
+
+    /**
+     * Monitors events where the grants of an application role are
+     * succesfully altered.
+     *
+     * @param dao the data access object
+     * @param appName the name of the application
+     * @param roleName the name of the role
+     * @param grants the newly set grants for the role
+     */
+    void roleGrantsAltered( JeRoleDAO dao, String appName, String roleName,
+                            byte[] grants ) ;
+
+    /**
+     * Monitors events where changes to the grants of an application
+     * role fail.
+     *
+     * @param dao the data access object
+     * @param appName the name of the application
+     * @param roleName the name of the role
+     * @param fault the fault that caused the failure
+     */
+    void failedOnSetGrants( JeRoleDAO dao, String appName, String roleName,
+                            Throwable fault ) ;
 }

Modified: incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/role/RoleDAOMonitorAdapter.java
==============================================================================
--- incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/role/RoleDAOMonitorAdapter.java
(original)
+++ incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/role/RoleDAOMonitorAdapter.java
Wed Apr 28 09:21:59 2004
@@ -215,4 +215,69 @@
             fault.printStackTrace() ;
         }
     }
+
+
+    /**
+     * Monitors events where a lookup of the grants of an application role fail.
+     *
+     * @param dao      the data access object
+     * @param appName  the name of the application
+     * @param roleName the name of the role
+     * @param fault    the fault that caused the failure
+     */
+    public void failedGrantsLookup( JeRoleDAO dao, String appName, String roleName,
+                                    Throwable fault )
+    {
+        if ( fault != null )
+        {
+            fault.printStackTrace() ;
+        }
+    }
+
+
+    /**
+     * Monitors events where the grants of an application role are succesfully looked up.
+     *
+     * @param dao      the data access object
+     * @param appName  the name of the application
+     * @param roleName the name of the role
+     * @param grants   the grants for the role that were successfully looked up
+     */
+    public void grantsLookedUp( JeRoleDAO dao, String appName, String roleName,
+                                byte[] grants )
+    {
+    }
+
+
+    /**
+     * Monitors events where the grants of an application role are
+     * succesfully altered.
+     *
+     * @param dao      the data access object
+     * @param appName  the name of the application
+     * @param roleName the name of the role
+     * @param grants   the newly set grants for the role
+     */
+    public void roleGrantsAltered( JeRoleDAO dao, String appName,
+                                   String roleName, byte[] grants )
+    {
+    }
+
+
+    /**
+     * Monitors events where changes to the grants of an application role fail.
+     *
+     * @param dao      the data access object
+     * @param appName  the name of the application
+     * @param roleName the name of the role
+     * @param fault    the fault that caused the failure
+     */
+    public void failedOnSetGrants( JeRoleDAO dao, String appName,
+                                   String roleName, Throwable fault )
+    {
+        if ( fault != null )
+        {
+            fault.printStackTrace() ;
+        }
+    }
 }

Modified: incubator/directory/rms/trunk/je/src/test/org/apache/rms/je/role/JeRoleDAOTest.java
==============================================================================
--- incubator/directory/rms/trunk/je/src/test/org/apache/rms/je/role/JeRoleDAOTest.java	(original)
+++ incubator/directory/rms/trunk/je/src/test/org/apache/rms/je/role/JeRoleDAOTest.java	Wed
Apr 28 09:21:59 2004
@@ -17,20 +17,18 @@
 package org.apache.rms.je.role ;
 
 
+import com.sleepycat.je.* ;
+
+import org.apache.rms.Role ;
 import org.apache.rms.RmsException ;
-import org.apache.rms.BitPermission ;
-import org.apache.rms.DefaultApplication;
-import org.apache.rms.Role;
+import org.apache.rms.DefaultApplication ;
 
-import org.apache.rms.je.JeUtils ;
 import org.apache.rms.je.AbstractJeTest ;
-import org.apache.rms.je.application.JeApplication;
-import org.apache.rms.je.permissions.*;
 import org.apache.rms.je.sequence.Sequence ;
 import org.apache.rms.je.sequence.JeSequenceDao ;
+import org.apache.rms.je.application.JeApplication ;
 import org.apache.rms.je.sequence.JeSequenceFactory ;
-
-import com.sleepycat.je.*;
+import org.apache.commons.lang.ArrayUtils;
 
 
 /**
@@ -219,5 +217,70 @@
         catch ( RmsException e )
         {
         }
+    }
+
+
+    public void testCreateGetAndSetGrants() throws Exception
+    {
+        assertFalse( roleDAO.has( "app1", "roleA" ) ) ;
+        assertFalse( roleDAO.has( "app1", "roleB" ) ) ;
+        assertFalse( roleDAO.has( "app1", "roleC" ) ) ;
+        assertFalse( roleDAO.has( "app1", "roleD" ) ) ;
+
+        DefaultApplication application = new JeApplication( "app1" ) ;
+        roleDAO.create( application, "roleA" ) ;
+        roleDAO.create( application, "roleB" ) ;
+        roleDAO.create( application, "roleC" ) ;
+        roleDAO.create( application, "roleD" ) ;
+
+        assertTrue( roleDAO.has( "app1", "roleA" ) ) ;
+        assertTrue( roleDAO.has( "app1", "roleB" ) ) ;
+        assertTrue( roleDAO.has( "app1", "roleC" ) ) ;
+        assertTrue( roleDAO.has( "app1", "roleD" ) ) ;
+
+        byte[] grants = null ;
+        grants = roleDAO.getGrants( "app1", "roleA" ) ;
+        assertTrue( ArrayUtils.isEquals( ArrayUtils.EMPTY_BYTE_ARRAY,
+                grants ) ) ;
+
+        grants = roleDAO.getGrants( "app1", "roleB" ) ;
+        assertTrue( ArrayUtils.isEquals( ArrayUtils.EMPTY_BYTE_ARRAY,
+                grants ) ) ;
+
+        grants = roleDAO.getGrants( "app1", "roleC" ) ;
+        assertTrue( ArrayUtils.isEquals( ArrayUtils.EMPTY_BYTE_ARRAY,
+                grants ) ) ;
+
+        grants = roleDAO.getGrants( "app1", "roleD" ) ;
+        assertTrue( ArrayUtils.isEquals( ArrayUtils.EMPTY_BYTE_ARRAY,
+                grants ) ) ;
+
+        byte[] newGrants = new byte[2] ;
+        newGrants[0] = 123 ;
+        newGrants[1] = 45 ;
+
+        roleDAO.setGrants( "app1", "roleA", newGrants ) ;
+        grants = roleDAO.getGrants( "app1", "roleA" ) ;
+        assertFalse( ArrayUtils.isEquals( ArrayUtils.EMPTY_BYTE_ARRAY,
+                grants ) ) ;
+        assertTrue( ArrayUtils.isEquals( newGrants, grants ) ) ;
+
+        roleDAO.setGrants( "app1", "roleB", newGrants ) ;
+        grants = roleDAO.getGrants( "app1", "roleB" ) ;
+        assertFalse( ArrayUtils.isEquals( ArrayUtils.EMPTY_BYTE_ARRAY,
+                grants ) ) ;
+        assertTrue( ArrayUtils.isEquals( newGrants, grants ) ) ;
+
+        roleDAO.setGrants( "app1", "roleC", newGrants ) ;
+        grants = roleDAO.getGrants( "app1", "roleC" ) ;
+        assertFalse( ArrayUtils.isEquals( ArrayUtils.EMPTY_BYTE_ARRAY,
+                grants ) ) ;
+        assertTrue( ArrayUtils.isEquals( newGrants, grants ) ) ;
+
+        roleDAO.setGrants( "app1", "roleD", newGrants ) ;
+        grants = roleDAO.getGrants( "app1", "roleD" ) ;
+        assertFalse( ArrayUtils.isEquals( ArrayUtils.EMPTY_BYTE_ARRAY,
+                grants ) ) ;
+        assertTrue( ArrayUtils.isEquals( newGrants, grants ) ) ;
     }
 }

Mime
View raw message