directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vte...@apache.org
Subject svn commit: r111969 - incubator/directory/janus/trunk/script/src/java/org/apache/janus/script/xml/builder
Date Wed, 15 Dec 2004 14:21:28 GMT
Author: vtence
Date: Wed Dec 15 06:21:23 2004
New Revision: 111969

URL: http://svn.apache.org/viewcvs?view=rev&rev=111969
Log:
These files missed the last commit
Added:
   incubator/directory/janus/trunk/script/src/java/org/apache/janus/script/xml/builder/
   incubator/directory/janus/trunk/script/src/java/org/apache/janus/script/xml/builder/DefaultRuleBuilder.java
  (contents, props changed)
   incubator/directory/janus/trunk/script/src/java/org/apache/janus/script/xml/builder/FalsePredicateBuilder.java
  (contents, props changed)
   incubator/directory/janus/trunk/script/src/java/org/apache/janus/script/xml/builder/HasGroupPredicateBuilder.java
  (contents, props changed)
   incubator/directory/janus/trunk/script/src/java/org/apache/janus/script/xml/builder/HasRolePredicateBuilder.java
  (contents, props changed)
   incubator/directory/janus/trunk/script/src/java/org/apache/janus/script/xml/builder/HasUsernamePredicateBuilder.java
  (contents, props changed)
   incubator/directory/janus/trunk/script/src/java/org/apache/janus/script/xml/builder/TruePredicateBuilder.java
  (contents, props changed)

Added: incubator/directory/janus/trunk/script/src/java/org/apache/janus/script/xml/builder/DefaultRuleBuilder.java
Url: http://svn.apache.org/viewcvs/incubator/directory/janus/trunk/script/src/java/org/apache/janus/script/xml/builder/DefaultRuleBuilder.java?view=auto&rev=111969
==============================================================================
--- (empty file)
+++ incubator/directory/janus/trunk/script/src/java/org/apache/janus/script/xml/builder/DefaultRuleBuilder.java
Wed Dec 15 06:21:23 2004
@@ -0,0 +1,120 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.janus.script.xml.builder;
+
+import org.apache.janus.authorization.DefaultRule;
+import org.apache.janus.authorization.Effect;
+import org.apache.janus.authorization.Predicate;
+import org.apache.janus.authorization.predicate.Predicates;
+import org.apache.janus.authorization.effect.DenyOverridesEffect;
+import org.apache.janus.authorization.effect.Effects;
+import org.apache.janus.authorization.effect.FirstApplicableEffect;
+import org.apache.janus.authorization.effect.LastApplicableEffect;
+import org.apache.janus.authorization.effect.PermitOverridesEffect;
+import org.apache.janus.script.xml.NodeBuilder;
+import org.apache.janus.script.xml.NodeBuilderLookup;
+import org.dom4j.Element;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Iterator;
+
+public class DefaultRuleBuilder implements NodeBuilder
+{
+    private final String m_elementName;
+    private final Map m_effects;
+
+    public DefaultRuleBuilder()
+    {
+        this( "rule" );
+    }
+
+    public DefaultRuleBuilder( String elementName )
+    {
+        m_elementName = elementName;
+        m_effects = new HashMap();
+        registerEffects();
+    }
+
+    public boolean canBuild( Element e )
+    {
+        return m_elementName.equals( e.getName() );
+    }
+
+    public Object buildFrom( Element e, NodeBuilderLookup lookup )
+    {
+        String effectName = e.attributeValue( "effect" );
+        DefaultRule rule = new DefaultRule( effect( effectName ) );
+        setSubjectPredicate( rule, e, lookup );
+        setPermissionPredicate( rule, e, lookup );
+        return rule;
+    }
+
+    private Effect effect( String name )
+    {
+        return (Effect) m_effects.get( name );
+    }
+
+    private Predicate predicate( Element e, NodeBuilderLookup lookup )
+    {
+        NodeBuilder builder = lookup.lookupBuilder( e );
+        return (Predicate) builder.buildFrom( e, lookup );
+    }
+
+    private void registerEffects()
+    {
+        m_effects.put( "grant", Effects.GRANT );
+        m_effects.put( "deny", Effects.DENY );
+        m_effects.put( "not-applicable", Effects.NOT_APPLICABLE );
+        m_effects.put( "permit-overrides", new PermitOverridesEffect() );
+        m_effects.put( "deny-overrides", new DenyOverridesEffect() );
+        m_effects.put( "first-applicable", new FirstApplicableEffect() );
+        m_effects.put( "last-applicable", new LastApplicableEffect() );
+    }
+
+    private void setPermissionPredicate( DefaultRule rule, Element element, NodeBuilderLookup
lookup )
+    {
+        Element permissions = element.element( "permissions" );
+        List predicates = permissions.elements();
+
+        Predicate p = Predicates.TRUE;
+        for ( Iterator it = predicates.iterator(); it.hasNext(); )
+        {
+            Element e = ( Element ) it.next();
+            // Consider moving this logic to default rule
+            p = Predicates.and( p, predicate( e, lookup ) );
+        }
+        rule.matchPermissions( p );
+    }
+
+    private void setSubjectPredicate( DefaultRule rule, Element element, NodeBuilderLookup
lookup  )
+    {
+        Element subjects = element.element( "subjects" );
+        List predicates = subjects.elements();
+
+        Predicate p = Predicates.TRUE;
+        for ( Iterator it = predicates.iterator(); it.hasNext(); )
+        {
+            Element e = ( Element ) it.next();
+            // Consider moving this logic to default rule
+            p = Predicates.and( p, predicate( e, lookup ) );
+        }
+        rule.matchSubjects( p );
+    }
+}
+

Added: incubator/directory/janus/trunk/script/src/java/org/apache/janus/script/xml/builder/FalsePredicateBuilder.java
Url: http://svn.apache.org/viewcvs/incubator/directory/janus/trunk/script/src/java/org/apache/janus/script/xml/builder/FalsePredicateBuilder.java?view=auto&rev=111969
==============================================================================
--- (empty file)
+++ incubator/directory/janus/trunk/script/src/java/org/apache/janus/script/xml/builder/FalsePredicateBuilder.java
Wed Dec 15 06:21:23 2004
@@ -0,0 +1,47 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.janus.script.xml.builder;
+
+import org.apache.janus.script.xml.NodeBuilder;
+import org.apache.janus.script.xml.NodeBuilderLookup;
+import org.apache.janus.authorization.predicate.Predicates;
+import org.dom4j.Element;
+
+public class FalsePredicateBuilder implements NodeBuilder
+{
+    private final String m_elementName;
+
+    public FalsePredicateBuilder()
+    {
+       this( "none" );
+    }
+
+    public FalsePredicateBuilder( String elementName )
+    {
+        m_elementName = elementName;
+    }
+
+    public boolean canBuild( Element e )
+    {
+        return m_elementName.equals( e.getName() );
+    }
+
+    public Object buildFrom( Element e, NodeBuilderLookup lookup )
+    {
+        return Predicates.FALSE;
+    }
+}

Added: incubator/directory/janus/trunk/script/src/java/org/apache/janus/script/xml/builder/HasGroupPredicateBuilder.java
Url: http://svn.apache.org/viewcvs/incubator/directory/janus/trunk/script/src/java/org/apache/janus/script/xml/builder/HasGroupPredicateBuilder.java?view=auto&rev=111969
==============================================================================
--- (empty file)
+++ incubator/directory/janus/trunk/script/src/java/org/apache/janus/script/xml/builder/HasGroupPredicateBuilder.java
Wed Dec 15 06:21:23 2004
@@ -0,0 +1,48 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.janus.script.xml.builder;
+
+import org.apache.janus.authentication.attribute.GroupPrincipal;
+import org.apache.janus.authorization.predicate.HasPrincipalPredicate;
+import org.apache.janus.script.xml.NodeBuilder;
+import org.apache.janus.script.xml.NodeBuilderLookup;
+import org.dom4j.Element;
+
+public class HasGroupPredicateBuilder implements NodeBuilder
+{
+    private final String m_elementName;
+
+    public HasGroupPredicateBuilder()
+    {
+        this( "group" );
+    }
+
+    public HasGroupPredicateBuilder( String elementName )
+    {
+        m_elementName = elementName;
+    }
+
+    public boolean canBuild( Element e )
+    {
+        return m_elementName.equals( e.getName() );
+    }
+
+    public Object buildFrom( Element e, NodeBuilderLookup lookup )
+    {
+        return new HasPrincipalPredicate( new GroupPrincipal( e.getTextTrim() ));
+    }
+}

Added: incubator/directory/janus/trunk/script/src/java/org/apache/janus/script/xml/builder/HasRolePredicateBuilder.java
Url: http://svn.apache.org/viewcvs/incubator/directory/janus/trunk/script/src/java/org/apache/janus/script/xml/builder/HasRolePredicateBuilder.java?view=auto&rev=111969
==============================================================================
--- (empty file)
+++ incubator/directory/janus/trunk/script/src/java/org/apache/janus/script/xml/builder/HasRolePredicateBuilder.java
Wed Dec 15 06:21:23 2004
@@ -0,0 +1,49 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.janus.script.xml.builder;
+
+import org.apache.janus.authentication.attribute.GroupPrincipal;
+import org.apache.janus.authentication.attribute.RolePrincipal;
+import org.apache.janus.authorization.predicate.HasPrincipalPredicate;
+import org.apache.janus.script.xml.NodeBuilder;
+import org.apache.janus.script.xml.NodeBuilderLookup;
+import org.dom4j.Element;
+
+public class HasRolePredicateBuilder implements NodeBuilder
+{
+    private final String m_elementName;
+
+    public HasRolePredicateBuilder()
+    {
+        this( "role" );
+    }
+
+    public HasRolePredicateBuilder( String elementName )
+    {
+        m_elementName = elementName;
+    }
+
+    public boolean canBuild( Element e )
+    {
+        return m_elementName.equals( e.getName() );
+    }
+
+    public Object buildFrom( Element e, NodeBuilderLookup lookup )
+    {
+        return new HasPrincipalPredicate( new RolePrincipal( e.getTextTrim() ));
+    }
+}

Added: incubator/directory/janus/trunk/script/src/java/org/apache/janus/script/xml/builder/HasUsernamePredicateBuilder.java
Url: http://svn.apache.org/viewcvs/incubator/directory/janus/trunk/script/src/java/org/apache/janus/script/xml/builder/HasUsernamePredicateBuilder.java?view=auto&rev=111969
==============================================================================
--- (empty file)
+++ incubator/directory/janus/trunk/script/src/java/org/apache/janus/script/xml/builder/HasUsernamePredicateBuilder.java
Wed Dec 15 06:21:23 2004
@@ -0,0 +1,48 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.janus.script.xml.builder;
+
+import org.apache.janus.authentication.realm.UsernamePrincipal;
+import org.apache.janus.authorization.predicate.HasPrincipalPredicate;
+import org.apache.janus.script.xml.NodeBuilder;
+import org.apache.janus.script.xml.NodeBuilderLookup;
+import org.dom4j.Element;
+
+public class HasUsernamePredicateBuilder implements NodeBuilder
+{
+    private final String m_elementName;
+
+    public HasUsernamePredicateBuilder()
+    {
+        this( "username" );
+    }
+
+    public HasUsernamePredicateBuilder( String elementName )
+    {
+        m_elementName = elementName;
+    }
+
+    public boolean canBuild( Element e )
+    {
+        return m_elementName.equals( e.getName() );
+    }
+
+    public Object buildFrom( Element e, NodeBuilderLookup lookup )
+    {
+        return new HasPrincipalPredicate( new UsernamePrincipal( e.getTextTrim() ));
+    }
+}

Added: incubator/directory/janus/trunk/script/src/java/org/apache/janus/script/xml/builder/TruePredicateBuilder.java
Url: http://svn.apache.org/viewcvs/incubator/directory/janus/trunk/script/src/java/org/apache/janus/script/xml/builder/TruePredicateBuilder.java?view=auto&rev=111969
==============================================================================
--- (empty file)
+++ incubator/directory/janus/trunk/script/src/java/org/apache/janus/script/xml/builder/TruePredicateBuilder.java
Wed Dec 15 06:21:23 2004
@@ -0,0 +1,47 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.janus.script.xml.builder;
+
+import org.apache.janus.script.xml.NodeBuilder;
+import org.apache.janus.script.xml.NodeBuilderLookup;
+import org.apache.janus.authorization.predicate.Predicates;
+import org.dom4j.Element;
+
+public class TruePredicateBuilder implements NodeBuilder
+{
+    private final String m_elementName;
+
+    public TruePredicateBuilder()
+    {
+       this( "any" );
+    }
+
+    public TruePredicateBuilder( String elementName )
+    {
+        m_elementName = elementName;
+    }
+
+    public boolean canBuild( Element e )
+    {
+        return m_elementName.equals( e.getName() );
+    }                 
+
+    public Object buildFrom( Element e, NodeBuilderLookup lookup )
+    {
+        return Predicates.TRUE;
+    }
+}

Mime
View raw message