directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vte...@apache.org
Subject svn commit: rev 57045 - incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authorization
Date Tue, 09 Nov 2004 14:53:15 GMT
Author: vtence
Date: Tue Nov  9 06:53:14 2004
New Revision: 57045

Modified:
   incubator/directory/janus/trunk/sandbox/src/java/org/apache/janus/authorization/DefaultRule.java
Log:
Simple rule implementation - enough for demonstration purposes and simple use cases

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
Tue Nov  9 06:53:14 2004
@@ -17,6 +17,7 @@
 package org.apache.janus.authorization;
 
 import org.apache.janus.authorization.effect.Effects;
+import org.apache.janus.authorization.predicate.Predicates;
 
 import javax.security.auth.Subject;
 
@@ -25,23 +26,44 @@
  */
 public class DefaultRule
 {
-    private final Effect m_effect;
+    private Effect m_effect;
     private Predicate m_subjectPredicate;
+    private Predicate m_permissionPredicate;
+
+    public DefaultRule()
+    {
+        this( Effects.GRANT );
+    }
 
     public DefaultRule( Effect effect )
     {
         m_effect = effect;
+        m_subjectPredicate = Predicates.TRUE;
+        m_permissionPredicate = Predicates.TRUE;
+    }
+
+    public void setEffect( Effect effect )
+    {
+        m_effect = effect;
+    }
+
+    public void matchSubjects( Predicate condition )
+    {
+        m_subjectPredicate = condition;
     }
 
-    public void setSubjectCondition( Predicate predicate )
+    public void matchPermissions( Predicate condition )
     {
-        m_subjectPredicate = predicate;
+        m_permissionPredicate = condition;
     }
 
-    public Effect evaluate( Subject s )
+    public Effect evaluate( Subject s, Permission p )
     {
-        if ( m_subjectPredicate.evaluate( s ) ) return m_effect;
+        return matches( s, p ) ? m_effect : Effects.NOT_APPLICABLE;
+    }
 
-        return Effects.NOT_APPLICABLE;
+    private boolean matches( Subject s, Permission p )
+    {
+        return m_subjectPredicate.evaluate( s ) && m_permissionPredicate.evaluate(
p );
     }
 }

Mime
View raw message