directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vte...@apache.org
Subject svn commit: rev 47617 - in incubator/directory/janus/trunk/sandbox/src: java/org/apache/janus/authorization java/org/apache/janus/authorization/effect java/org/apache/janus/authorization/predicate test/org/apache/janus/authorization
Date Fri, 01 Oct 2004 02:47:24 GMT
Author: vtence
Date: Thu Sep 30 19:47:23 2004
New Revision: 47617

Modified:
   incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authorization/DefaultRule.java
   incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authorization/Effect.java
   incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authorization/Policy.java
   incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authorization/effect/DenyEffect.java
   incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authorization/effect/DenyOverridesEffect.java
   incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authorization/effect/FirstApplicableEffect.java
   incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authorization/effect/GrantEffect.java
   incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authorization/effect/IndeterminateEffect.java
   incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authorization/effect/LastApplicableEffect.java
   incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authorization/effect/NotApplicableEffect.java
   incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authorization/effect/PermitOverridesEffect.java
   incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authorization/predicate/HasPrincipalPredicate.java
   incubator/directory/janus/trunk/sandbox/src/test/org/apache/janus/authorization/DefaultRuleTest.java
Log:
Less code = better code

Modified: incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authorization/DefaultRule.java
==============================================================================
--- incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authorization/DefaultRule.java
(original)
+++ incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authorization/DefaultRule.java
Thu Sep 30 19:47:23 2004
@@ -16,7 +16,6 @@
  */
 package org.apache.janus.authorization;
 
-import org.apache.janus.authorization.effect.IndeterminateEffect;
 import org.apache.janus.authorization.effect.NotApplicableEffect;
 
 import javax.security.auth.Subject;
@@ -39,8 +38,9 @@
         m_subjectPredicate = predicate;
     }
 
-    public Effect evaluate( Subject s ) {
-        if (m_subjectPredicate.evaluate( s ) ) return m_effect;
+    public Effect evaluate( Subject s )
+    {
+        if ( m_subjectPredicate.evaluate( s ) ) return m_effect;
 
         return new NotApplicableEffect();
     }

Modified: incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authorization/Effect.java
==============================================================================
--- incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authorization/Effect.java
(original)
+++ incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authorization/Effect.java
Thu Sep 30 19:47:23 2004
@@ -21,15 +21,11 @@
  */
 public interface Effect
 {
-    Effect and( Effect effect );
-
-    Effect applyTo( Effect effect );
+    Effect derive( Effect effect );
 
     Effect permit();
 
     Effect deny();
 
     Effect indeterminate();
-
-    boolean resolve( EffectResolver resolver );
 }

Modified: incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authorization/Policy.java
==============================================================================
--- incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authorization/Policy.java
(original)
+++ incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authorization/Policy.java
Thu Sep 30 19:47:23 2004
@@ -42,15 +42,15 @@
 
     public Effect evaluate( Subject s, Permission p )
     {
-        Effect netEffect = m_effect;
+        Effect decision = m_effect;
 
         for ( Iterator it = m_rules.iterator(); it.hasNext(); )
         {
             Rule rule = ( Rule ) it.next();
             Effect e = rule.evaluate( s, p );
-            netEffect = netEffect.and( e );
+            decision = e.derive( decision );
         }
 
-        return netEffect;
+        return decision;
     }
 }

Modified: incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authorization/effect/DenyEffect.java
==============================================================================
--- incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authorization/effect/DenyEffect.java
(original)
+++ incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authorization/effect/DenyEffect.java
Thu Sep 30 19:47:23 2004
@@ -17,19 +17,13 @@
 package org.apache.janus.authorization.effect;
 
 import org.apache.janus.authorization.Effect;
-import org.apache.janus.authorization.EffectResolver;
 
 /**
  * @author <a href="mailto:vtence@apache.org">Vincent Tence</a>
  */
 public final class DenyEffect implements Effect
 {
-    public Effect and( Effect effect )
-    {
-        return this;
-    }
-
-    public Effect applyTo( Effect effect )
+    public Effect derive( Effect effect )
     {
         return effect.deny();
     }
@@ -47,10 +41,5 @@
     public Effect indeterminate()
     {
         return this;
-    }
-
-    public boolean resolve( EffectResolver resolver )
-    {
-        return false;
     }
 }

Modified: incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authorization/effect/DenyOverridesEffect.java
==============================================================================
--- incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authorization/effect/DenyOverridesEffect.java
(original)
+++ incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authorization/effect/DenyOverridesEffect.java
Thu Sep 30 19:47:23 2004
@@ -17,7 +17,6 @@
 package org.apache.janus.authorization.effect;
 
 import org.apache.janus.authorization.Effect;
-import org.apache.janus.authorization.EffectResolver;
 
 /**
  * @author <a href="mailto:vtence@apache.org">Vincent Tence</a>
@@ -36,14 +35,9 @@
         m_effect = effect;
     }
 
-    public Effect applyTo( Effect effect )
+    public Effect derive( Effect effect )
     {
-        return effect.and( m_effect );
-    }
-
-    public Effect and( Effect effect )
-    {
-        return effect.applyTo( this );
+        return m_effect.derive( effect );
     }
 
     public Effect permit()
@@ -59,10 +53,5 @@
     public Effect indeterminate()
     {
         return new DenyOverridesEffect( new IndeterminateEffect() );
-    }
-
-    public boolean resolve( EffectResolver resolver )
-    {
-        return m_effect.resolve( resolver );
     }
 }

Modified: incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authorization/effect/FirstApplicableEffect.java
==============================================================================
--- incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authorization/effect/FirstApplicableEffect.java
(original)
+++ incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authorization/effect/FirstApplicableEffect.java
Thu Sep 30 19:47:23 2004
@@ -17,7 +17,6 @@
 package org.apache.janus.authorization.effect;
 
 import org.apache.janus.authorization.Effect;
-import org.apache.janus.authorization.EffectResolver;
 
 /**
  * @author <a href="mailto:vtence@apache.org">Vincent Tence</a>
@@ -36,14 +35,9 @@
         m_effect = effect;
     }
 
-    public Effect applyTo( Effect effect )
+    public Effect derive( Effect effect )
     {
-        return effect.and( m_effect );
-    }
-
-    public Effect and( Effect effect )
-    {
-        return effect.applyTo( this );
+        return m_effect.derive( effect );
     }
 
     public Effect permit()
@@ -59,10 +53,5 @@
     public Effect indeterminate()
     {
         return new IndeterminateEffect();
-    }
-
-    public boolean resolve( EffectResolver resolver )
-    {
-        return m_effect.resolve( resolver );
     }
 }

Modified: incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authorization/effect/GrantEffect.java
==============================================================================
--- incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authorization/effect/GrantEffect.java
(original)
+++ incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authorization/effect/GrantEffect.java
Thu Sep 30 19:47:23 2004
@@ -17,19 +17,13 @@
 package org.apache.janus.authorization.effect;
 
 import org.apache.janus.authorization.Effect;
-import org.apache.janus.authorization.EffectResolver;
 
 /**
  * @author <a href="mailto:vtence@apache.org">Vincent Tence</a>
  */
 public final class GrantEffect implements Effect
 {
-    public Effect and( Effect effect )
-    {
-        return this;
-    }
-
-    public Effect applyTo( Effect effect )
+    public Effect derive( Effect effect )
     {
         return effect.permit();
     }
@@ -47,10 +41,5 @@
     public Effect indeterminate()
     {
         return this;
-    }
-
-    public boolean resolve( EffectResolver resolver )
-    {
-        return true;
     }
 }

Modified: incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authorization/effect/IndeterminateEffect.java
==============================================================================
--- incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authorization/effect/IndeterminateEffect.java
(original)
+++ incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authorization/effect/IndeterminateEffect.java
Thu Sep 30 19:47:23 2004
@@ -17,19 +17,13 @@
 package org.apache.janus.authorization.effect;
 
 import org.apache.janus.authorization.Effect;
-import org.apache.janus.authorization.EffectResolver;
 
 /**
  * @author <a href="mailto:vtence@apache.org">Vincent Tence</a>
  */
 public final class IndeterminateEffect implements Effect
 {
-    public Effect and( Effect effect )
-    {
-        return this;
-    }
-
-    public Effect applyTo( Effect effect )
+    public Effect derive( Effect effect )
     {
         return effect.indeterminate();
     }
@@ -47,10 +41,5 @@
     public Effect indeterminate()
     {
         return this;
-    }
-
-    public boolean resolve( EffectResolver resolver )
-    {
-        return resolver.indeterminate();
     }
 }

Modified: incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authorization/effect/LastApplicableEffect.java
==============================================================================
--- incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authorization/effect/LastApplicableEffect.java
(original)
+++ incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authorization/effect/LastApplicableEffect.java
Thu Sep 30 19:47:23 2004
@@ -36,14 +36,9 @@
         m_effect = effect;
     }
 
-    public Effect applyTo( Effect effect )
+    public Effect derive( Effect effect )
     {
-        return effect.and( m_effect );
-    }
-
-    public Effect and( Effect effect )
-    {
-        return effect.applyTo( this );
+        return m_effect.derive( effect );
     }
 
     public Effect permit()
@@ -59,10 +54,5 @@
     public Effect indeterminate()
     {
         return new LastApplicableEffect( new IndeterminateEffect() );
-    }
-
-    public boolean resolve( EffectResolver resolver )
-    {
-        return m_effect.resolve( resolver );
     }
 }

Modified: incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authorization/effect/NotApplicableEffect.java
==============================================================================
--- incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authorization/effect/NotApplicableEffect.java
(original)
+++ incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authorization/effect/NotApplicableEffect.java
Thu Sep 30 19:47:23 2004
@@ -17,19 +17,13 @@
 package org.apache.janus.authorization.effect;
 
 import org.apache.janus.authorization.Effect;
-import org.apache.janus.authorization.EffectResolver;
 
 /**
  * @author <a href="mailto:vtence@apache.org">Vincent Tence</a>
  */
 public final class NotApplicableEffect implements Effect
 {
-    public Effect and( Effect effect )
-    {
-        return this;
-    }
-
-    public Effect applyTo( Effect effect )
+    public Effect derive( Effect effect )
     {
         return effect;
     }
@@ -47,10 +41,5 @@
     public Effect indeterminate()
     {
         return this;
-    }
-
-    public boolean resolve( EffectResolver resolver )
-    {
-        return resolver.notApplicable();
     }
 }

Modified: incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authorization/effect/PermitOverridesEffect.java
==============================================================================
--- incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authorization/effect/PermitOverridesEffect.java
(original)
+++ incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authorization/effect/PermitOverridesEffect.java
Thu Sep 30 19:47:23 2004
@@ -17,7 +17,6 @@
 package org.apache.janus.authorization.effect;
 
 import org.apache.janus.authorization.Effect;
-import org.apache.janus.authorization.EffectResolver;
 
 /**
  * @author <a href="mailto:vtence@apache.org">Vincent Tence</a>
@@ -36,14 +35,9 @@
         m_effect = effect;
     }
 
-    public Effect applyTo( Effect effect )
+    public Effect derive( Effect effect )
     {
-        return effect.and( m_effect );
-    }
-
-    public Effect and( Effect effect )
-    {
-        return effect.applyTo( this );
+        return m_effect.derive( effect );
     }
 
     public Effect permit()
@@ -61,8 +55,4 @@
         return new PermitOverridesEffect( new IndeterminateEffect() );
     }
 
-    public boolean resolve( EffectResolver resolver )
-    {
-        return m_effect.resolve( resolver );
-    }
 }

Modified: incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authorization/predicate/HasPrincipalPredicate.java
==============================================================================
--- incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authorization/predicate/HasPrincipalPredicate.java
(original)
+++ incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authorization/predicate/HasPrincipalPredicate.java
Thu Sep 30 19:47:23 2004
@@ -36,12 +36,12 @@
 
     public boolean evaluate( Object o )
     {
-        Subject s = (Subject) o;
+        Subject s = ( Subject ) o;
 
         for ( Iterator it = s.getPrincipals().iterator(); it.hasNext(); )
         {
             Principal p = ( Principal ) it.next();
-            if (m_principal.equals( p )) return true;
+            if ( m_principal.equals( p ) ) return true;
         }
 
         return false;

Modified: incubator/directory/janus/trunk/sandbox/src/test/org/apache/janus/authorization/DefaultRuleTest.java
==============================================================================
--- incubator/directory/janus/trunk/sandbox/src/test/org/apache/janus/authorization/DefaultRuleTest.java
(original)
+++ incubator/directory/janus/trunk/sandbox/src/test/org/apache/janus/authorization/DefaultRuleTest.java
Thu Sep 30 19:47:23 2004
@@ -16,12 +16,12 @@
  */
 package org.apache.janus.authorization;
 
-import org.jmock.MockObjectTestCase;
 import org.apache.janus.authentication.realm.UsernamePrincipal;
 import org.apache.janus.authorization.effect.GrantEffect;
 import org.apache.janus.authorization.effect.NotApplicableEffect;
-import org.apache.janus.authorization.predicate.HasPrincipalPredicate;
 import org.apache.janus.authorization.predicate.FalsePredicate;
+import org.apache.janus.authorization.predicate.HasPrincipalPredicate;
+import org.jmock.MockObjectTestCase;
 
 import javax.security.auth.Subject;
 
@@ -55,7 +55,7 @@
     public void testValidConditionOnSubject()
     {
         m_rule = new DefaultRule( new GrantEffect() );
-        m_rule.setSubjectCondition( new HasPrincipalPredicate( new UsernamePrincipal ("johnDoe"
)) );
+        m_rule.setSubjectCondition( new HasPrincipalPredicate( new UsernamePrincipal( "johnDoe"
) ) );
         assertTrue( m_rule.evaluate( john() ) instanceof GrantEffect );
     }
 

Mime
View raw message