Author: sohil.shah(a)jboss.com
Date: 2009-06-23 16:12:21 -0400 (Tue, 23 Jun 2009)
New Revision: 13492
Added:
modules/authorization/trunk/agent/src/main/java/org/jboss/security/authz/agent/services/CompositionContext.java
Removed:
modules/authorization/trunk/agent/src/main/java/org/jboss/security/authz/agent/services/ComponentRepository.java
modules/authorization/trunk/agent/src/main/java/org/jboss/security/authz/agent/services/RuleComposer.java
modules/authorization/trunk/agent/src/main/java/org/jboss/security/authz/agent/services/RuleDeclarationRepository.java
modules/authorization/trunk/agent/src/main/resources/authz-components.xml
modules/authorization/trunk/agent/src/test/java/org/jboss/security/authz/agent/services/TestConfiguration.java
modules/authorization/trunk/common-api/src/main/java/org/jboss/security/authz/component/ComponentMarker.java
Modified:
modules/authorization/trunk/agent/src/main/java/org/jboss/security/authz/agent/services/PolicyComposer.java
modules/authorization/trunk/agent/src/main/java/org/jboss/security/authz/agent/services/RuleComposition.java
modules/authorization/trunk/agent/src/main/java/org/jboss/security/authz/agent/services/TargetComposition.java
modules/authorization/trunk/agent/src/main/resources/META-INF/jboss-beans.xml
modules/authorization/trunk/agent/src/test/java/org/jboss/security/authz/agent/services/TestPolicyComposition.java
modules/authorization/trunk/core-components-api/src/main/java/org/jboss/security/authz/components/action/Operation.java
modules/authorization/trunk/core-components-api/src/main/java/org/jboss/security/authz/components/resource/URIResource.java
modules/authorization/trunk/core-components-api/src/main/java/org/jboss/security/authz/components/subject/Identity.java
modules/authorization/trunk/core-components-api/src/main/java/org/jboss/security/authz/components/subject/Roles.java
Log:
first pass baseline stability of the developer framework
* need to test it with http-profile and portal-profile built on top of it....fingers
crossed...
Deleted:
modules/authorization/trunk/agent/src/main/java/org/jboss/security/authz/agent/services/ComponentRepository.java
===================================================================
---
modules/authorization/trunk/agent/src/main/java/org/jboss/security/authz/agent/services/ComponentRepository.java 2009-06-23
16:01:40 UTC (rev 13491)
+++
modules/authorization/trunk/agent/src/main/java/org/jboss/security/authz/agent/services/ComponentRepository.java 2009-06-23
20:12:21 UTC (rev 13492)
@@ -1,64 +0,0 @@
-/*
-* JBoss, a division of Red Hat
-* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
-*/
-package org.jboss.security.authz.agent.services;
-
-import java.util.Map;
-
-import org.jboss.security.authz.component.Component;
-
-/**
- * @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
- */
-public class ComponentRepository
-{
- private Map<String, Component> registeredComponents;
-
- public ComponentRepository()
- {
-
- }
-
- public void start()
- {
-
- }
-
- public void stop()
- {
-
- }
- //-----------Repository Access related
services----------------------------------------------------------------------------------------------------------------------------------------------------------
- public void register(String name, Component component)
- {
- this.registeredComponents.put(name, component);
- }
-
- public Component getComponent(String name)
- {
- return this.registeredComponents.get(name);
- }
-
- public void unregister(String name)
- {
- this.registeredComponents.remove(name);
- }
-}
Added:
modules/authorization/trunk/agent/src/main/java/org/jboss/security/authz/agent/services/CompositionContext.java
===================================================================
---
modules/authorization/trunk/agent/src/main/java/org/jboss/security/authz/agent/services/CompositionContext.java
(rev 0)
+++
modules/authorization/trunk/agent/src/main/java/org/jboss/security/authz/agent/services/CompositionContext.java 2009-06-23
20:12:21 UTC (rev 13492)
@@ -0,0 +1,92 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+*/
+package org.jboss.security.authz.agent.services;
+
+import java.io.Serializable;
+import java.util.Set;
+import java.util.HashSet;
+
+import org.jboss.security.authz.model.Effect;
+
+/**
+ * @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
+ */
+public class CompositionContext implements Serializable
+{
+ private TargetComposition policyTarget;
+ private Set<RuleComposition> policyRules;
+
+ public CompositionContext()
+ {
+ this.policyRules = new HashSet<RuleComposition>();
+ }
+
+ //------Public API exposed to the
developer--------------------------------------------------------------------------------------------------------------------------
+ public void setPolicyTarget(Object policyTarget)
+ {
+ this.policyTarget = new TargetComposition();
+ this.policyTarget.setTargetComponent(policyTarget);
+ }
+
+ public void addPolicyRule(Effect effect, Object target, Object logic)
+ {
+ RuleComposition ruleComposition = new RuleComposition();
+ ruleComposition.setEffect(effect);
+ ruleComposition.setTargetComponent(target);
+ ruleComposition.setLogicComponent(logic);
+
+ this.policyRules.add(ruleComposition);
+ }
+
+ public void addPolicyRule(Effect effect, Object target, Object logic, String
condition_expression_type)
+ {
+ RuleComposition ruleComposition = new RuleComposition();
+ ruleComposition.setEffect(effect);
+ ruleComposition.setTargetComponent(target);
+ ruleComposition.setLogicComponent(logic);
+ ruleComposition.setExpressionName(condition_expression_type);
+
+ this.policyRules.add(ruleComposition);
+ }
+
+ public void clearPolicyRule(String ruleDefinition)
+ {
+ for(RuleComposition ruleComposition: this.policyRules)
+ {
+ if(ruleComposition.getType().equals(ruleDefinition))
+ {
+ this.policyRules.remove(ruleComposition);
+ break;
+ }
+ }
+ }
+ //------------internals-----------------------------------------------------------------------------------------------------------------------------------------------
+ TargetComposition getPolicyTarget()
+ {
+ return this.policyTarget;
+ }
+
+ Set<RuleComposition> getPolicyRules()
+ {
+ return this.policyRules;
+ }
+}
Modified:
modules/authorization/trunk/agent/src/main/java/org/jboss/security/authz/agent/services/PolicyComposer.java
===================================================================
---
modules/authorization/trunk/agent/src/main/java/org/jboss/security/authz/agent/services/PolicyComposer.java 2009-06-23
16:01:40 UTC (rev 13491)
+++
modules/authorization/trunk/agent/src/main/java/org/jboss/security/authz/agent/services/PolicyComposer.java 2009-06-23
20:12:21 UTC (rev 13492)
@@ -21,10 +21,51 @@
*/
package org.jboss.security.authz.agent.services;
+import java.util.Set;
+import java.util.HashSet;
+
+import org.jboss.security.authz.model.Target;
+import org.jboss.security.authz.model.Rule;
+import org.jboss.security.authz.model.PolicyMetaData;
+
/**
* @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
*/
public class PolicyComposer
{
+ public PolicyComposer()
+ {
+
+ }
+ public PolicyMetaData compose(CompositionContext context)
+ {
+ PolicyMetaData policyMetaData = null;
+
+ TargetComposition policyTarget = context.getPolicyTarget();
+ Set<RuleComposition> policyRules = context.getPolicyRules();
+
+ if(policyTarget == null)
+ {
+ throw new IllegalStateException("Policy Target is missing!!");
+ }
+
+ if(policyRules == null || policyRules.isEmpty())
+ {
+ throw new IllegalStateException("Policy Rule(s) are missing!!");
+ }
+
+ Target target = policyTarget.compose();
+ Set<Rule> rules = new HashSet<Rule>();
+ for(RuleComposition composition: policyRules)
+ {
+ rules.addAll(composition.compose());
+ }
+
+ policyMetaData = new PolicyMetaData();
+ policyMetaData.setTarget(target);
+ policyMetaData.setRules(rules);
+
+ return policyMetaData;
+ }
}
Deleted:
modules/authorization/trunk/agent/src/main/java/org/jboss/security/authz/agent/services/RuleComposer.java
===================================================================
---
modules/authorization/trunk/agent/src/main/java/org/jboss/security/authz/agent/services/RuleComposer.java 2009-06-23
16:01:40 UTC (rev 13491)
+++
modules/authorization/trunk/agent/src/main/java/org/jboss/security/authz/agent/services/RuleComposer.java 2009-06-23
20:12:21 UTC (rev 13492)
@@ -1,30 +0,0 @@
-/*
-* JBoss, a division of Red Hat
-* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
-*/
-package org.jboss.security.authz.agent.services;
-
-/**
- * @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
- */
-public class RuleComposer
-{
-
-}
Modified:
modules/authorization/trunk/agent/src/main/java/org/jboss/security/authz/agent/services/RuleComposition.java
===================================================================
---
modules/authorization/trunk/agent/src/main/java/org/jboss/security/authz/agent/services/RuleComposition.java 2009-06-23
16:01:40 UTC (rev 13491)
+++
modules/authorization/trunk/agent/src/main/java/org/jboss/security/authz/agent/services/RuleComposition.java 2009-06-23
20:12:21 UTC (rev 13492)
@@ -39,61 +39,72 @@
/**
* @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
*/
-public class RuleComposition
+class RuleComposition
{
private static Logger log = Logger.getLogger(RuleComposition.class);
+ private String type;
private Object targetComponent;
private Object logicComponent;
private String expressionName;
private Effect effect;
- public RuleComposition()
+ RuleComposition()
{
}
- public Object getTargetComponent()
+ Object getTargetComponent()
{
return targetComponent;
}
- public void setTargetComponent(Object targetComponent)
+ void setTargetComponent(Object targetComponent)
{
this.targetComponent = targetComponent;
}
- public Object getLogicComponent()
+ Object getLogicComponent()
{
return logicComponent;
}
- public void setLogicComponent(Object logicComponent)
+ void setLogicComponent(Object logicComponent)
{
this.logicComponent = logicComponent;
}
- public Effect getEffect()
+ Effect getEffect()
{
return effect;
}
- public void setEffect(Effect effect)
+ void setEffect(Effect effect)
{
this.effect = effect;
}
- public String getExpressionName()
+ String getExpressionName()
{
return expressionName;
}
- public void setExpressionName(String expressionName)
+ void setExpressionName(String expressionName)
{
this.expressionName = expressionName;
}
+
+ String getType()
+ {
+ return type;
+ }
+
+ void setType(String type)
+ {
+ this.type = type;
+ }
//----------------------------------------------------------------------------------------------------------------------------------------------------------------
- public Set<Rule> compose()
+ Set<Rule> compose()
{
if(this.effect == null)
{
Deleted:
modules/authorization/trunk/agent/src/main/java/org/jboss/security/authz/agent/services/RuleDeclarationRepository.java
===================================================================
---
modules/authorization/trunk/agent/src/main/java/org/jboss/security/authz/agent/services/RuleDeclarationRepository.java 2009-06-23
16:01:40 UTC (rev 13491)
+++
modules/authorization/trunk/agent/src/main/java/org/jboss/security/authz/agent/services/RuleDeclarationRepository.java 2009-06-23
20:12:21 UTC (rev 13492)
@@ -1,65 +0,0 @@
-/*
-* JBoss, a division of Red Hat
-* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
-*/
-package org.jboss.security.authz.agent.services;
-
-import java.util.Set;
-import java.util.HashSet;
-
-import org.apache.log4j.Logger;
-import org.jboss.security.authz.component.ComponentMarker;
-
-/**
- * @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
- */
-public class RuleDeclarationRepository
-{
- private static Logger log = Logger.getLogger(RuleDeclarationRepository.class);
-
- private Set<ComponentMarker> components;
-
- public RuleDeclarationRepository()
- {
- }
-
- public void start()
- {
- this.components = new HashSet<ComponentMarker>();
- log.info("-------------------------------------------------------------------");
- log.info("RuleDeclarationRepository successfully
started.....................");
- log.info("-------------------------------------------------------------------");
- }
-
- public void stop()
- {
-
- }
-
- public void register(ComponentMarker component)
- {
- this.components.add(component);
-
- log.debug("--------------------------------------------------------------");
- log.debug(component.getClass()+" was successfully registered.............");
- log.debug("--------------------------------------------------------------");
- }
- //---------------------------------------------------------------------------------------------------------------------------------------------------------------
-}
Modified:
modules/authorization/trunk/agent/src/main/java/org/jboss/security/authz/agent/services/TargetComposition.java
===================================================================
---
modules/authorization/trunk/agent/src/main/java/org/jboss/security/authz/agent/services/TargetComposition.java 2009-06-23
16:01:40 UTC (rev 13491)
+++
modules/authorization/trunk/agent/src/main/java/org/jboss/security/authz/agent/services/TargetComposition.java 2009-06-23
20:12:21 UTC (rev 13492)
@@ -41,28 +41,28 @@
/**
* @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
*/
-public class TargetComposition
+class TargetComposition
{
private static Logger log = Logger.getLogger(TargetComposition.class);
private Object targetComponent;
- public TargetComposition()
+ TargetComposition()
{
}
- public Object getTargetComponent()
+ Object getTargetComponent()
{
return targetComponent;
}
- public void setTargetComponent(Object targetComponent)
+ void setTargetComponent(Object targetComponent)
{
this.targetComponent = targetComponent;
}
//------------------------------------------------------------------------------------------------------------------------------------------------------------------
- public Target compose()
+ Target compose()
{
if(this.targetComponent == null)
{
@@ -82,7 +82,7 @@
}
}
- public Set<Target> composeImpliedTargets()
+ Set<Target> composeImpliedTargets()
{
try
{
Modified: modules/authorization/trunk/agent/src/main/resources/META-INF/jboss-beans.xml
===================================================================
---
modules/authorization/trunk/agent/src/main/resources/META-INF/jboss-beans.xml 2009-06-23
16:01:40 UTC (rev 13491)
+++
modules/authorization/trunk/agent/src/main/resources/META-INF/jboss-beans.xml 2009-06-23
20:12:21 UTC (rev 13492)
@@ -3,25 +3,6 @@
<deployment
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:jboss:bean-deployer:2.0
bean-deployer_2_0.xsd"
xmlns="urn:jboss:bean-deployer:2.0">
- <bean name="/agent/RuleDeclarationRepository"
class="org.jboss.security.authz.component.RuleDeclarationRepository">
- <incallback method="register"/>
- </bean>
-
- <bean name="/component/URIResource"
class="org.jboss.security.authz.components.resource.URIResource">
- </bean>
-
- <bean name="/component/Identity"
class="org.jboss.security.authz.components.subject.Identity">
- </bean>
-
- <bean name="/component/Roles"
class="org.jboss.security.authz.components.subject.Roles">
- </bean>
-
- <bean name="/component/Read"
class="org.jboss.security.authz.components.action.Read">
- </bean>
-
- <bean name="/component/Write"
class="org.jboss.security.authz.components.action.Write">
- </bean>
-
- <bean name="/component/Manage"
class="org.jboss.security.authz.components.action.Manage">
- </bean>
+ <bean name="/agent/PolicyComposer"
class="org.jboss.security.authz.agent.services.PolicyComposer">
+ </bean>
</deployment>
\ No newline at end of file
Deleted: modules/authorization/trunk/agent/src/main/resources/authz-components.xml
===================================================================
--- modules/authorization/trunk/agent/src/main/resources/authz-components.xml 2009-06-23
16:01:40 UTC (rev 13491)
+++ modules/authorization/trunk/agent/src/main/resources/authz-components.xml 2009-06-23
20:12:21 UTC (rev 13492)
@@ -1,66 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<components>
- <!--
- TODO: Just for prototyping the Component Contract. Eventually the method of
configuration will be POJO components with Annotations
- -->
- <target-component name="uri" category="resource"
class="org.jboss.security.authz.components.resource.URIResource">
- <target-uri>uniqueUri</target-uri>
- </target-component>
-
- <target-component name="operation" category="action"
class="org.jboss.security.authz.components.action.Operation">
- <target-uri>name</target-uri>
- </target-component>
-
- <target-component name="read" category="action"
class="org.jboss.security.authz.components.action.Read">
- <target-uri>name</target-uri>
- </target-component>
-
- <target-component name="write" category="action"
class="org.jboss.security.authz.components.action.Write">
- <target-uri>name</target-uri>
- </target-component>
-
- <target-component name="manage" category="action"
class="org.jboss.security.authz.components.action.Manage">
- <target-uri>name</target-uri>
- </target-component>
-
- <logic-component name="identity" category="subject"
class="org.jboss.security.authz.components.subject.Identity">
- <target-uri>uri</target-uri>
- <logic-data>
- <data>name</data>
- </logic-data>
- </logic-component>
-
- <logic-component name="roles" category="subject"
class="org.jboss.security.authz.components.subject.Roles">
- <target-uri></target-uri>
- <logic-data>
- <data>names</data>
- </logic-data>
- <logic-expressions>
- <expression>allowExpression</expression>
- <expression>denyExpression</expression>
- </logic-expressions>
- </logic-component>
-
-
- <!--
- Core Rule Compositions shipped with the framework. These can be re-used and more
compositions can be added
- depending upon Application/Profile Requirements
- -->
- <rule-composition name="permitIdentity" outcome="permit">
- <target-component>identity</target-component>
- </rule-composition>
-
- <rule-composition name="denyIdentity" outcome="deny">
- <target-component>identity</target-component>
- </rule-composition>
-
- <rule-composition name="permitRole" outcome="permit">
- <target-component>operation</target-component>
- <logic-component
expression="allowExpression">roles</logic-component>
- </rule-composition>
-
- <rule-composition name="denyRole" outcome="deny">
- <target-component>operation</target-component>
- <logic-component
expression="denyExpression">roles</logic-component>
- </rule-composition>
-</components>
\ No newline at end of file
Deleted:
modules/authorization/trunk/agent/src/test/java/org/jboss/security/authz/agent/services/TestConfiguration.java
===================================================================
---
modules/authorization/trunk/agent/src/test/java/org/jboss/security/authz/agent/services/TestConfiguration.java 2009-06-23
16:01:40 UTC (rev 13491)
+++
modules/authorization/trunk/agent/src/test/java/org/jboss/security/authz/agent/services/TestConfiguration.java 2009-06-23
20:12:21 UTC (rev 13492)
@@ -1,76 +0,0 @@
-/*
-* JBoss, a division of Red Hat
-* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
-*/
-package org.jboss.security.authz.agent.services;
-
-import java.io.InputStream;
-
-import junit.framework.TestCase;
-
-import org.apache.log4j.Logger;
-
-import org.jboss.security.authz.tools.GeneralTool;
-import org.jboss.security.authz.agent.Agent;
-import org.jboss.security.authz.agent.services.ComponentRepository;
-
-/**
- * @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
- */
-public class TestConfiguration extends TestCase
-{
- private static Logger log = Logger.getLogger(TestConfiguration.class);
-
- protected void setUp() throws Exception
- {
- Agent.bootstrap();
- }
- //---------------------------------------------------------------------------------------------------------------------------------------------------------------
- public void test() throws Exception
- {
- InputStream is = null;
- try
- {
- is =
Thread.currentThread().getContextClassLoader().getResourceAsStream("authz-components.xml");
- String xmlConfig = GeneralTool.readStream(is);
-
- ComponentRepository repository = new ComponentRepository();
- this.parse(xmlConfig);
-
- //Assert
- }
- finally
- {
- if(is != null)
- {
- is.close();
- }
- }
- }
- //------------Configuration related
services---------------------------------------------------------------------------------------------------------------------------------------------------------
- private void parse(String xmlConfig)
- {
- log.info("------------------------------------------------------");
- log.info("Parsing-----------------------------------------------");
- log.info(xmlConfig);
- log.info("------------------------------------------------------");
- }
- //---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-}
Modified:
modules/authorization/trunk/agent/src/test/java/org/jboss/security/authz/agent/services/TestPolicyComposition.java
===================================================================
---
modules/authorization/trunk/agent/src/test/java/org/jboss/security/authz/agent/services/TestPolicyComposition.java 2009-06-23
16:01:40 UTC (rev 13491)
+++
modules/authorization/trunk/agent/src/test/java/org/jboss/security/authz/agent/services/TestPolicyComposition.java 2009-06-23
20:12:21 UTC (rev 13492)
@@ -32,17 +32,15 @@
import org.jboss.security.authz.model.Effect;
import org.jboss.security.authz.model.Policy;
import org.jboss.security.authz.model.PolicyMetaData;
-import org.jboss.security.authz.model.Target;
-import org.jboss.security.authz.model.Rule;
-import org.jboss.security.authz.agent.services.RuleComposition;
-import org.jboss.security.authz.agent.services.TargetComposition;
import org.jboss.security.authz.components.subject.Identity;
import org.jboss.security.authz.components.subject.Roles;
import org.jboss.security.authz.components.action.Read;
import org.jboss.security.authz.components.action.Manage;
import org.jboss.security.authz.components.resource.URIResource;
+import org.jboss.security.authz.agent.Agent;
+
import org.jboss.security.authz.agent.test.MockPolicy;
/**
@@ -52,36 +50,32 @@
{
private static Logger log = Logger.getLogger(TestPolicyComposition.class);
+ private PolicyComposer policyComposer;
+
protected void setUp() throws Exception
{
+ Agent.bootstrap();
+ this.policyComposer = (PolicyComposer)Agent.lookup("/agent/PolicyComposer");
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------------
public void testComposePermitIdentity() throws Exception
- {
+ {
+ //Setup the state of Components to be used for Policy Composition
URIResource uriResource = new URIResource();
uriResource.setUri(new URI("/portal/admin-tool/modifyLayout"));
Identity identity = new Identity();
identity.setName("blahUser");
+
+ //Setup the Context for the Composition with these components
+ CompositionContext context = new CompositionContext();
+ context.setPolicyTarget(uriResource);
+ context.addPolicyRule(Effect.PERMIT, identity, null);
- TargetComposition targetComposition = new TargetComposition();
- targetComposition.setTargetComponent(uriResource);
+ PolicyMetaData metadata = this.policyComposer.compose(context);
+ assertNotNull("Target must not be null!!", metadata.getTarget());
+ assertNotNull("Rule must not be null!!", metadata.getRules());
- RuleComposition ruleComposition = new RuleComposition();
- ruleComposition.setTargetComponent(identity);
- ruleComposition.setEffect(Effect.PERMIT);
-
-
- Target policyTarget = targetComposition.compose();
- Set<Rule> policyRule = ruleComposition.compose();
-
- //Assert the State
- assertNotNull("Target must not be null!!", policyTarget);
- assertNotNull("Rule must not be null!!", policyRule);
-
- PolicyMetaData metadata = new PolicyMetaData();
- metadata.setTarget(policyTarget);
- metadata.setRules(policyRule);
Policy policy = new MockPolicy("testComposePermitIdentity", metadata);
log.info("----------------------------------------------------------------");
@@ -89,7 +83,8 @@
}
public void testComposePermitRole() throws Exception
- {
+ {
+ //Setup the state of Components to be used for Policy Composition
Roles roles = new Roles();
Set<String> names = new HashSet<String>();
names.add("admin");
@@ -99,26 +94,15 @@
URIResource uriResource = new URIResource();
uriResource.setUri(new URI("/portal/admin-tool/modifyLayout"));
- TargetComposition targetComposition = new TargetComposition();
- targetComposition.setTargetComponent(uriResource);
-
- RuleComposition ruleComposition = new RuleComposition();
- ruleComposition.setEffect(Effect.PERMIT);
- ruleComposition.setLogicComponent(roles);
- ruleComposition.setExpressionName("allowExpression");
- ruleComposition.setTargetComponent(new Read());
-
-
- Target policyTarget = targetComposition.compose();
- Set<Rule> policyRule = ruleComposition.compose();
-
- //Assert the State
- assertNotNull("Target must not be null!!", policyTarget);
- assertNotNull("Rule must not be null!!", policyRule);
-
- PolicyMetaData metadata = new PolicyMetaData();
- metadata.setTarget(policyTarget);
- metadata.setRules(policyRule);
+
+ //Setup the Context for the Composition with these components
+ CompositionContext context = new CompositionContext();
+ context.setPolicyTarget(uriResource);
+ context.addPolicyRule(Effect.PERMIT, new Read(), roles, "allowExpression");
+
+ PolicyMetaData metadata = this.policyComposer.compose(context);
+ assertNotNull("Target must not be null!!", metadata.getTarget());
+ assertNotNull("Rule must not be null!!", metadata.getRules());
Policy policy = new MockPolicy("testComposePermitRole", metadata);
log.info("----------------------------------------------------------------");
@@ -126,7 +110,8 @@
}
public void testImpliedTarget() throws Exception
- {
+ {
+ //Setup the state of Components to be used for Policy Composition
Roles roles = new Roles();
Set<String> names = new HashSet<String>();
names.add("admin");
@@ -136,26 +121,16 @@
URIResource uriResource = new URIResource();
uriResource.setUri(new URI("/portal/admin-tool/modifyLayout"));
- TargetComposition targetComposition = new TargetComposition();
- targetComposition.setTargetComponent(uriResource);
+
+ //Setup the CompositionContext
+ CompositionContext context = new CompositionContext();
+ context.setPolicyTarget(uriResource);
+ context.addPolicyRule(Effect.PERMIT, new Manage(), roles,
"allowExpression");
+
- RuleComposition ruleComposition = new RuleComposition();
- ruleComposition.setEffect(Effect.PERMIT);
- ruleComposition.setLogicComponent(roles);
- ruleComposition.setExpressionName("allowExpression");
- ruleComposition.setTargetComponent(new Manage());
-
-
- Target policyTarget = targetComposition.compose();
- Set<Rule> policyRule = ruleComposition.compose();
-
- //Assert the State
- assertNotNull("Target must not be null!!", policyTarget);
- assertNotNull("Rule must not be null!!", policyRule);
-
- PolicyMetaData metadata = new PolicyMetaData();
- metadata.setTarget(policyTarget);
- metadata.setRules(policyRule);
+ PolicyMetaData metadata = this.policyComposer.compose(context);
+ assertNotNull("Target must not be null!!", metadata.getTarget());
+ assertNotNull("Rule must not be null!!", metadata.getRules());
Policy policy = new MockPolicy("testComposePermitRole", metadata);
log.info("----------------------------------------------------------------");
Deleted:
modules/authorization/trunk/common-api/src/main/java/org/jboss/security/authz/component/ComponentMarker.java
===================================================================
---
modules/authorization/trunk/common-api/src/main/java/org/jboss/security/authz/component/ComponentMarker.java 2009-06-23
16:01:40 UTC (rev 13491)
+++
modules/authorization/trunk/common-api/src/main/java/org/jboss/security/authz/component/ComponentMarker.java 2009-06-23
20:12:21 UTC (rev 13492)
@@ -1,35 +0,0 @@
-/*
-* JBoss, a division of Red Hat
-* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
-*/
-package org.jboss.security.authz.component;
-
-/**
- * Just a marker interface used for Microcontainer callbacks for registration of security
components with the Agent Component Repository
- *
- * TODO: need to check with Microcontainer team if callbacks can be received based on
Type level Annotations. If so, this marker interface can be completely avoided and
- * kept more elegant. This is more of an elegance issue and not a performance or too much
developer pain the ass issue.
- *
- * @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
- */
-public interface ComponentMarker
-{
-
-}
Modified:
modules/authorization/trunk/core-components-api/src/main/java/org/jboss/security/authz/components/action/Operation.java
===================================================================
---
modules/authorization/trunk/core-components-api/src/main/java/org/jboss/security/authz/components/action/Operation.java 2009-06-23
16:01:40 UTC (rev 13491)
+++
modules/authorization/trunk/core-components-api/src/main/java/org/jboss/security/authz/components/action/Operation.java 2009-06-23
20:12:21 UTC (rev 13492)
@@ -21,7 +21,6 @@
*/
package org.jboss.security.authz.components.action;
-import org.jboss.security.authz.component.ComponentMarker;
import org.jboss.security.authz.component.TargetUri;
/**
@@ -29,7 +28,7 @@
*
* @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
*/
-public abstract class Operation implements ComponentMarker
+public abstract class Operation
{
@TargetUri
protected String name;
Modified:
modules/authorization/trunk/core-components-api/src/main/java/org/jboss/security/authz/components/resource/URIResource.java
===================================================================
---
modules/authorization/trunk/core-components-api/src/main/java/org/jboss/security/authz/components/resource/URIResource.java 2009-06-23
16:01:40 UTC (rev 13491)
+++
modules/authorization/trunk/core-components-api/src/main/java/org/jboss/security/authz/components/resource/URIResource.java 2009-06-23
20:12:21 UTC (rev 13492)
@@ -25,7 +25,6 @@
import org.apache.log4j.Logger;
-import org.jboss.security.authz.component.ComponentMarker;
import org.jboss.security.authz.component.Component;
import org.jboss.security.authz.component.ComponentType;
import org.jboss.security.authz.component.ComponentCategory;
@@ -41,7 +40,7 @@
type=ComponentType.TARGET,
category=ComponentCategory.RESOURCE
)
-public class URIResource implements ComponentMarker
+public class URIResource
{
private static Logger log = Logger.getLogger(URIResource.class);
Modified:
modules/authorization/trunk/core-components-api/src/main/java/org/jboss/security/authz/components/subject/Identity.java
===================================================================
---
modules/authorization/trunk/core-components-api/src/main/java/org/jboss/security/authz/components/subject/Identity.java 2009-06-23
16:01:40 UTC (rev 13491)
+++
modules/authorization/trunk/core-components-api/src/main/java/org/jboss/security/authz/components/subject/Identity.java 2009-06-23
20:12:21 UTC (rev 13492)
@@ -22,7 +22,6 @@
******************************************************************************/
package org.jboss.security.authz.components.subject;
-import org.jboss.security.authz.component.ComponentMarker;
import org.jboss.security.authz.component.Component;
import org.jboss.security.authz.component.ComponentType;
import org.jboss.security.authz.component.ComponentCategory;
@@ -43,7 +42,7 @@
type=ComponentType.LOGIC,
category=ComponentCategory.SUBJECT
)
-public class Identity implements ComponentMarker
+public class Identity
{
/**
* Unique id/name of the Identity
Modified:
modules/authorization/trunk/core-components-api/src/main/java/org/jboss/security/authz/components/subject/Roles.java
===================================================================
---
modules/authorization/trunk/core-components-api/src/main/java/org/jboss/security/authz/components/subject/Roles.java 2009-06-23
16:01:40 UTC (rev 13491)
+++
modules/authorization/trunk/core-components-api/src/main/java/org/jboss/security/authz/components/subject/Roles.java 2009-06-23
20:12:21 UTC (rev 13492)
@@ -28,7 +28,6 @@
import org.jboss.security.authz.tools.GeneralTool;
-import org.jboss.security.authz.component.ComponentMarker;
import org.jboss.security.authz.component.Component;
import org.jboss.security.authz.component.ComponentType;
import org.jboss.security.authz.component.ComponentCategory;
@@ -50,7 +49,7 @@
type=ComponentType.LOGIC,
category=ComponentCategory.SUBJECT
)
-public class Roles implements ComponentMarker
+public class Roles
{
//make it package-level access so that unit tests can test these rules
static final String allowRule =