Author: sohil.shah(a)jboss.com
Date: 2009-07-11 14:15:40 -0400 (Sat, 11 Jul 2009)
New Revision: 13545
Added:
modules/authorization/trunk/agent/src/test/java/org/jboss/security/authz/agent/features/
modules/authorization/trunk/agent/src/test/java/org/jboss/security/authz/agent/features/TestHierarchialPropagation.java
modules/authorization/trunk/agent/src/test/java/org/jboss/security/authz/agent/features/TestImpliedActions.java
modules/authorization/trunk/agent/src/test/java/org/jboss/security/authz/agent/features/TestImpliesHierarchialPropagation.java
modules/authorization/trunk/agent/src/test/java/org/jboss/security/authz/agent/features/TestPolicyServer.java
Removed:
modules/authorization/trunk/policy-server/src/test/java/org/jboss/security/authz/policy/server/TestHierarchialPropagation.java
modules/authorization/trunk/policy-server/src/test/java/org/jboss/security/authz/policy/server/TestImpliedActions.java
modules/authorization/trunk/policy-server/src/test/java/org/jboss/security/authz/policy/server/TestImpliesHierarchialPropagation.java
modules/authorization/trunk/policy-server/src/test/java/org/jboss/security/authz/policy/server/TestPolicyServer.java
Log:
testsuite refactoring
Copied:
modules/authorization/trunk/agent/src/test/java/org/jboss/security/authz/agent/features/TestHierarchialPropagation.java
(from rev 13544,
modules/authorization/trunk/policy-server/src/test/java/org/jboss/security/authz/policy/server/TestHierarchialPropagation.java)
===================================================================
---
modules/authorization/trunk/agent/src/test/java/org/jboss/security/authz/agent/features/TestHierarchialPropagation.java
(rev 0)
+++
modules/authorization/trunk/agent/src/test/java/org/jboss/security/authz/agent/features/TestHierarchialPropagation.java 2009-07-11
18:15:40 UTC (rev 13545)
@@ -0,0 +1,253 @@
+/*
+* 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.features;
+
+import java.net.URI;
+
+import junit.framework.TestCase;
+import org.apache.log4j.Logger;
+
+import org.jboss.security.authz.model.Policy;
+import org.jboss.security.authz.model.PolicyMetaData;
+import org.jboss.security.authz.model.Resource;
+import org.jboss.security.authz.policy.client.enforcement.Request;
+import org.jboss.security.authz.policy.client.enforcement.Response;
+import org.jboss.security.authz.policy.server.Server;
+
+import org.jboss.security.authz.agent.enforcement.PolicyEnforcementPoint;
+import org.jboss.security.authz.agent.provisioning.PolicyProvisioner;
+import org.jboss.security.authz.components.resource.URIResource;
+import org.jboss.security.authz.components.subject.Roles;
+import org.jboss.security.authz.components.action.Read;
+
+
+/**
+ * @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
+ */
+public class TestHierarchialPropagation extends TestCase
+{
+ private static Logger log = Logger.getLogger(TestHierarchialPropagation.class);
+
+ private PolicyEnforcementPoint enforcer;
+ private PolicyProvisioner provisioner;
+
+ public void setUp() throws Exception
+ {
+ Server.bootstrap();
+ this.enforcer =
(PolicyEnforcementPoint)Server.lookup("/enforcement/localEnforcementPoint");
+ this.provisioner =
(PolicyProvisioner)Server.lookup("/provisioning/localProvisioner");
+ }
+
+ public void tearDown() throws Exception
+ {
+ }
+
+ //TODO: Rewrite these tests with the new Developer Framework
+ /*public void testExplicitPermit() throws Exception
+ {
+ //SetUp Resource
+ URIResource resource = new URIResource();
+ resource.setUri(new URI("/root/level1/level2/index.html"));
+ resource.setOperation(new Read());
+ resource.addAllowed("user");
+
+ //Provision the new policy
+ PolicyMetaData metadata = resource.getPolicyMetaData();
+ this.provisioner.newPolicy(metadata);
+
+ //Go ahead and produce a RequestContext for a "Permit" Enforcement
+ URIResource contextResource = new URIResource();
+ contextResource.setUri(new URI("/root/level1/level2/index.html"));
+ contextResource.setOperation(new Read());
+
+ //Perform enforcement
+ this.enforce(this.createRequest(contextResource), true);
+ }
+
+ public void testExplicitDeny() throws Exception
+ {
+ //SetUp Resource
+ URIResource resource = new URIResource();
+ resource.setUri(new URI("/root/level1/level2/index.html"));
+ resource.setOperation(new Read());
+ resource.addDenied("user");
+
+ //Provision the new policy
+ PolicyMetaData metadata = resource.getPolicyMetaData();
+ this.provisioner.newPolicy(metadata);
+ this.assertServerState();
+
+ //Go ahead and produce a RequestContext for a "Permit" Enforcement
+ URIResource contextResource = new URIResource();
+ contextResource.setUri(new URI("/root/level1/level2/index.html"));
+ contextResource.setOperation(new Read());
+
+ //Perform enforcement
+ this.enforce(this.createRequest(contextResource), false);
+ }
+
+ public void testPermitInheritance() throws Exception
+ {
+ //SetUp Resource
+ URIResource resource = new URIResource();
+ resource.setUri(new URI("/root/level1"));
+ resource.setOperation(new Read());
+ resource.addAllowed("user");
+
+ //Provision the new policy
+ PolicyMetaData metadata = resource.getPolicyMetaData();
+ this.provisioner.newPolicy(metadata);
+
+ //Go ahead and produce a RequestContext for a "Permit" Enforcement
+ URIResource contextResource = new URIResource();
+ contextResource.setUri(new URI("/root/level1/level2/index.html"));
+ contextResource.setOperation(new Read());
+
+ //Perform enforcement
+ this.enforce(this.createRequest(contextResource), true);
+ }
+
+ public void testDenyInheritance() throws Exception
+ {
+ //SetUp Resource
+ URIResource resource = new URIResource();
+ resource.setUri(new URI("/root/level1"));
+ resource.setOperation(new Read());
+ resource.addDenied("user");
+
+ //Provision the new policy
+ PolicyMetaData metadata = resource.getPolicyMetaData();
+ this.provisioner.newPolicy(metadata);
+
+ //Go ahead and produce a RequestContext for a "Permit" Enforcement
+ URIResource contextResource = new URIResource();
+ contextResource.setUri(new URI("/root/level1/level2/index.html"));
+ contextResource.setOperation(new Read());
+
+ //Perform enforcement
+ this.enforce(this.createRequest(contextResource), false);
+ }
+
+ public void testDenyOverridesPermitInheritance() throws Exception
+ {
+ //SetUp Permit policy
+ URIResource resource = new URIResource();
+ resource.setUri(new URI("/root/level1"));
+ resource.setOperation(new Read());
+ resource.addAllowed("user");
+
+ //Provision the new policy
+ PolicyMetaData metadata = resource.getPolicyMetaData();
+ this.provisioner.newPolicy(metadata);
+
+ //Setup denied policy
+ resource = new URIResource();
+ resource.setUri(new URI("/root/level1/level2"));
+ resource.setOperation(new Read());
+ resource.addDenied("user");
+
+ //Provision the new policy
+ metadata = resource.getPolicyMetaData();
+ this.provisioner.newPolicy(metadata);
+
+ //Go ahead and produce a RequestContext for a "Permit" Enforcement
+ URIResource contextResource = new URIResource();
+ contextResource.setUri(new URI("/root/level1/level2/index.html"));
+ contextResource.setOperation(new Read());
+
+ //Perform enforcement
+ this.enforce(this.createRequest(contextResource), false);
+ }
+
+ public void testNotApplicable() throws Exception
+ {
+ //SetUp Resource
+ URIResource resource = new URIResource();
+ resource.setUri(new URI("/root2"));
+ resource.setOperation(new Read());
+ resource.addAllowed("user");
+
+ //Provision the new policy
+ PolicyMetaData metadata = resource.getPolicyMetaData();
+ this.provisioner.newPolicy(metadata);
+
+ //Go ahead and produce a RequestContext for a "Permit" Enforcement
+ URIResource contextResource = new URIResource();
+ contextResource.setUri(new URI("/root/level1/level2/index.html"));
+ contextResource.setOperation(new Read());
+
+ //Perform enforcement
+ this.enforce(this.createRequest(contextResource), false);
+ }
+ //------------------------------------------------------------------------------------------------------------------------------------------------------
+ private Request createRequest(URIResource uriResource) throws Exception
+ {
+ //Create a RequestType
+ Request request = new Request();
+
+ //Enable Hierarchial Enforcement
+ request.setActivateHierarchialEnforcement(true);
+
+ //Create Resource
+ Resource urlResource = uriResource.getResource();
+ request.addResource(urlResource);
+
+ //Create Subjects
+ Roles roles = new Roles();
+ roles.addName("user");
+ request.addSubject(roles.getSubject());
+
+ //Create Action
+ request.setAction(uriResource.getOperation().getAction());
+
+ return request;
+ }
+
+ private void enforce(Request request, boolean mustBePermitted) throws Exception
+ {
+
+ Response response = this.enforcer.checkAccess(request);
+
+ assertNotNull(response);
+ log.info("-----------------------------------");
+ log.info("Decision="+response.getMessage());
+
+ if(mustBePermitted)
+ {
+ assertTrue("Access must be granted!!!", response.isAccessGranted());
+ }
+ else
+ {
+ assertFalse("Access must be denied!!!", response.isAccessGranted());
+ }
+ }
+
+ private void assertServerState() throws Exception
+ {
+ //Assert Policy State of the Server
+ Policy[] policies = this.provisioner.readAllPolicies();
+
+ assertTrue("Policy Store must not be empty!!", (policies != null &&
policies.length == 1));
+ log.info("------------------------------------------------------------------------------");
+ log.info(policies[0].generateSystemPolicy());
+ }*/
+}
Property changes on:
modules/authorization/trunk/agent/src/test/java/org/jboss/security/authz/agent/features/TestHierarchialPropagation.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied:
modules/authorization/trunk/agent/src/test/java/org/jboss/security/authz/agent/features/TestImpliedActions.java
(from rev 13544,
modules/authorization/trunk/policy-server/src/test/java/org/jboss/security/authz/policy/server/TestImpliedActions.java)
===================================================================
---
modules/authorization/trunk/agent/src/test/java/org/jboss/security/authz/agent/features/TestImpliedActions.java
(rev 0)
+++
modules/authorization/trunk/agent/src/test/java/org/jboss/security/authz/agent/features/TestImpliedActions.java 2009-07-11
18:15:40 UTC (rev 13545)
@@ -0,0 +1,170 @@
+/*
+* 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.features;
+
+import java.net.URI;
+
+import junit.framework.TestCase;
+import org.apache.log4j.Logger;
+
+import org.jboss.security.authz.model.Policy;
+import org.jboss.security.authz.model.PolicyMetaData;
+import org.jboss.security.authz.model.Resource;
+import org.jboss.security.authz.policy.client.enforcement.Request;
+import org.jboss.security.authz.policy.client.enforcement.Response;
+import org.jboss.security.authz.policy.server.Server;
+
+import org.jboss.security.authz.agent.enforcement.PolicyEnforcementPoint;
+import org.jboss.security.authz.agent.provisioning.PolicyProvisioner;
+import org.jboss.security.authz.components.resource.URIResource;
+import org.jboss.security.authz.components.subject.Roles;
+import org.jboss.security.authz.components.action.Operation;
+import org.jboss.security.authz.components.action.Read;
+import org.jboss.security.authz.components.action.Write;
+import org.jboss.security.authz.components.action.Manage;
+
+
+/**
+ * @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
+ */
+public class TestImpliedActions extends TestCase
+{
+ private static Logger log = Logger.getLogger(TestImpliedActions.class);
+
+ private PolicyEnforcementPoint enforcer;
+ private PolicyProvisioner provisioner;
+
+ public void setUp() throws Exception
+ {
+ Server.bootstrap();
+ this.enforcer =
(PolicyEnforcementPoint)Server.lookup("/enforcement/localEnforcementPoint");
+ this.provisioner =
(PolicyProvisioner)Server.lookup("/provisioning/localProvisioner");
+ }
+
+ public void tearDown() throws Exception
+ {
+ }
+
+ //TODO: Rewrite these tests with the new Developer Framework
+ /*public void testReadImpliedWithWrite() throws Exception
+ {
+ //SetUp Resource
+ URIResource resource = new URIResource();
+ resource.setUri(new URI("/blah/index.html"));
+ resource.setOperation(new Write());
+ resource.addAllowed("user");
+
+
+ PolicyMetaData metadata = resource.getPolicyMetaData();
+
+ this.provisioner.newPolicy(metadata);
+ this.assertServerState();
+
+ //Go ahead and produce a RequestContext for a "Permit" Enforcement
+ this.enforce(this.createRequest(resource, new Read()), true);
+ }
+
+ public void testWriteImpliedWithManage() throws Exception
+ {
+ //SetUp Resource
+ URIResource resource = new URIResource();
+ resource.setUri(new URI("/blah/index.html"));
+ resource.setOperation(new Manage());
+ resource.addAllowed("user");
+
+
+ PolicyMetaData metadata = resource.getPolicyMetaData();
+
+ this.provisioner.newPolicy(metadata);
+ this.assertServerState();
+
+ //Go ahead and produce a RequestContext for a "Permit" Enforcement
+ this.enforce(this.createRequest(resource, new Write()), true);
+ }
+
+ public void testWriteNotImpliedWithRead() throws Exception
+ {
+ //SetUp Resource
+ URIResource resource = new URIResource();
+ resource.setUri(new URI("/blah/index.html"));
+ resource.setOperation(new Read());
+ resource.addAllowed("user");
+
+
+ PolicyMetaData metadata = resource.getPolicyMetaData();
+
+ this.provisioner.newPolicy(metadata);
+ this.assertServerState();
+
+ //Go ahead and produce a RequestContext for a "Deny" Enforcement
+ this.enforce(this.createRequest(resource, new Write()), false);
+ }
+ //------------------------------------------------------------------------------------------------------------------------------------------------------
+ private Request createRequest(URIResource uriResource, Operation operation) throws
Exception
+ {
+ //Create a RequestType
+ Request request = new Request();
+
+ //Create Resource
+ Resource urlResource = uriResource.getResource();
+ request.addResource(urlResource);
+
+ //Create Subjects
+ Roles roles = new Roles();
+ roles.addName("user");
+ request.addSubject(roles.getSubject());
+
+ //Create Action
+ request.setAction(operation.getAction());
+
+ return request;
+ }
+
+ private void enforce(Request request, boolean mustBePermitted) throws Exception
+ {
+
+ Response response = this.enforcer.checkAccess(request);
+
+ assertNotNull(response);
+ log.info("-----------------------------------");
+ log.info("Decision="+response.getMessage());
+
+ if(mustBePermitted)
+ {
+ assertTrue("Access must be granted!!!", response.isAccessGranted());
+ }
+ else
+ {
+ assertFalse("Access must be denied!!!", response.isAccessGranted());
+ }
+ }
+
+ private void assertServerState() throws Exception
+ {
+ //Assert Policy State of the Server
+ Policy[] policies = this.provisioner.readAllPolicies();
+
+ assertTrue("Policy Store must not be empty!!", (policies != null &&
policies.length == 1));
+ log.info("------------------------------------------------------------------------------");
+ log.info(policies[0].generateSystemPolicy());
+ }*/
+}
Property changes on:
modules/authorization/trunk/agent/src/test/java/org/jboss/security/authz/agent/features/TestImpliedActions.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied:
modules/authorization/trunk/agent/src/test/java/org/jboss/security/authz/agent/features/TestImpliesHierarchialPropagation.java
(from rev 13544,
modules/authorization/trunk/policy-server/src/test/java/org/jboss/security/authz/policy/server/TestImpliesHierarchialPropagation.java)
===================================================================
---
modules/authorization/trunk/agent/src/test/java/org/jboss/security/authz/agent/features/TestImpliesHierarchialPropagation.java
(rev 0)
+++
modules/authorization/trunk/agent/src/test/java/org/jboss/security/authz/agent/features/TestImpliesHierarchialPropagation.java 2009-07-11
18:15:40 UTC (rev 13545)
@@ -0,0 +1,234 @@
+/*
+* 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.features;
+
+import java.net.URI;
+
+import junit.framework.TestCase;
+import org.apache.log4j.Logger;
+
+import org.jboss.security.authz.model.Policy;
+import org.jboss.security.authz.model.PolicyMetaData;
+import org.jboss.security.authz.model.Resource;
+import org.jboss.security.authz.policy.client.enforcement.Request;
+import org.jboss.security.authz.policy.client.enforcement.Response;
+import org.jboss.security.authz.policy.server.Server;
+
+import org.jboss.security.authz.agent.enforcement.PolicyEnforcementPoint;
+import org.jboss.security.authz.agent.provisioning.PolicyProvisioner;
+import org.jboss.security.authz.components.resource.URIResource;
+import org.jboss.security.authz.components.subject.Roles;
+import org.jboss.security.authz.components.action.Read;
+import org.jboss.security.authz.components.action.Write;
+import org.jboss.security.authz.components.action.Manage;
+
+
+/**
+ * @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
+ */
+public class TestImpliesHierarchialPropagation extends TestCase
+{
+ private static Logger log = Logger.getLogger(TestImpliesHierarchialPropagation.class);
+
+ private PolicyEnforcementPoint enforcer;
+ private PolicyProvisioner provisioner;
+
+ public void setUp() throws Exception
+ {
+ Server.bootstrap();
+ this.enforcer =
(PolicyEnforcementPoint)Server.lookup("/enforcement/localEnforcementPoint");
+ this.provisioner =
(PolicyProvisioner)Server.lookup("/provisioning/localProvisioner");
+ }
+
+ public void tearDown() throws Exception
+ {
+ }
+
+ //TODO: Rewrite these tests with the new Developer Framework
+ /*public void testExplicitPermitReadImpliedWithWrite() throws Exception
+ {
+ //SetUp Resource
+ URIResource resource = new URIResource();
+ resource.setUri(new URI("/root/level1/level2/index.html"));
+ resource.setOperation(new Write());
+ resource.addAllowed("user");
+
+ //Provision the new policy
+ PolicyMetaData metadata = resource.getPolicyMetaData();
+ this.provisioner.newPolicy(metadata);
+
+ //Go ahead and produce a RequestContext for a "Permit" Enforcement
+ URIResource contextResource = new URIResource();
+ contextResource.setUri(new URI("/root/level1/level2/index.html"));
+ contextResource.setOperation(new Read());
+
+ //Perform enforcement
+ this.enforce(this.createRequest(contextResource), true);
+ }
+
+ public void testExplicitDenyWriteNotImpliedWithRead() throws Exception
+ {
+ //SetUp Resource
+ URIResource resource = new URIResource();
+ resource.setUri(new URI("/root/level1/level2/index.html"));
+ resource.setOperation(new Read());
+ resource.addAllowed("user");
+
+ //Provision the new policy
+ PolicyMetaData metadata = resource.getPolicyMetaData();
+ this.provisioner.newPolicy(metadata);
+
+ //Go ahead and produce a RequestContext for a "Permit" Enforcement
+ URIResource contextResource = new URIResource();
+ contextResource.setUri(new URI("/root/level1/level2/index.html"));
+ contextResource.setOperation(new Write());
+
+ //Perform enforcement
+ this.enforce(this.createRequest(contextResource), false);
+ }
+
+ public void testPermitInheritanceWriteImpliedWithManage() throws Exception
+ {
+ //SetUp Resource
+ URIResource resource = new URIResource();
+ resource.setUri(new URI("/root/level1"));
+ resource.setOperation(new Manage());
+ resource.addAllowed("user");
+
+ //Provision the new policy
+ PolicyMetaData metadata = resource.getPolicyMetaData();
+ this.provisioner.newPolicy(metadata);
+
+ //Go ahead and produce a RequestContext for a "Permit" Enforcement
+ URIResource contextResource = new URIResource();
+ contextResource.setUri(new URI("/root/level1/level2/index.html"));
+ contextResource.setOperation(new Write());
+
+ //Perform enforcement
+ this.enforce(this.createRequest(contextResource), true);
+ }
+
+ public void testDenyInheritanceManageNotImpliedWithWrite() throws Exception
+ {
+ //SetUp Resource
+ URIResource resource = new URIResource();
+ resource.setUri(new URI("/root/level1"));
+ resource.setOperation(new Write());
+ resource.addAllowed("user");
+
+ //Provision the new policy
+ PolicyMetaData metadata = resource.getPolicyMetaData();
+ this.provisioner.newPolicy(metadata);
+
+ //Go ahead and produce a RequestContext for a "Permit" Enforcement
+ URIResource contextResource = new URIResource();
+ contextResource.setUri(new URI("/root/level1/level2/index.html"));
+ contextResource.setOperation(new Manage());
+
+ //Perform enforcement
+ this.enforce(this.createRequest(contextResource), false);
+ }
+
+ public void testDenyOverridesPermitInheritance() throws Exception
+ {
+ //SetUp Permit policy...User can write to level1
+ URIResource resource = new URIResource();
+ resource.setUri(new URI("/root/level1"));
+ resource.setOperation(new Write());
+ resource.addAllowed("user");
+
+ //Provision the new policy
+ PolicyMetaData metadata = resource.getPolicyMetaData();
+ this.provisioner.newPolicy(metadata);
+
+ //Setup denied policy....User can only read level2
+ resource = new URIResource();
+ resource.setUri(new URI("/root/level1/level2"));
+ resource.setOperation(new Read());
+ resource.addAllowed("user");
+
+ //Provision the new policy
+ metadata = resource.getPolicyMetaData();
+ this.provisioner.newPolicy(metadata);
+
+ //Go ahead and produce a RequestContext for a "Permit" Enforcement
+ //Trying to "Write" to level2 should be Denied
+ URIResource contextResource = new URIResource();
+ contextResource.setUri(new URI("/root/level1/level2/index.html"));
+ contextResource.setOperation(new Write());
+
+ //Perform enforcement
+ this.enforce(this.createRequest(contextResource), false);
+ }
+ //------------------------------------------------------------------------------------------------------------------------------------------------------
+ private Request createRequest(URIResource uriResource) throws Exception
+ {
+ //Create a RequestType
+ Request request = new Request();
+
+ //Enable Hierarchial Enforcement
+ request.setActivateHierarchialEnforcement(true);
+
+ //Create Resource
+ Resource urlResource = uriResource.getResource();
+ request.addResource(urlResource);
+
+ //Create Subjects
+ Roles roles = new Roles();
+ roles.addName("user");
+ request.addSubject(roles.getSubject());
+
+ //Create Action
+ request.setAction(uriResource.getOperation().getAction());
+
+ return request;
+ }
+
+ private void enforce(Request request, boolean mustBePermitted) throws Exception
+ {
+
+ Response response = this.enforcer.checkAccess(request);
+
+ assertNotNull(response);
+ log.info("-----------------------------------");
+ log.info("Decision="+response.getMessage());
+
+ if(mustBePermitted)
+ {
+ assertTrue("Access must be granted!!!", response.isAccessGranted());
+ }
+ else
+ {
+ assertFalse("Access must be denied!!!", response.isAccessGranted());
+ }
+ }
+
+ private void assertServerState() throws Exception
+ {
+ //Assert Policy State of the Server
+ Policy[] policies = this.provisioner.readAllPolicies();
+
+ assertTrue("Policy Store must not be empty!!", (policies != null &&
policies.length == 1));
+ log.info("------------------------------------------------------------------------------");
+ log.info(policies[0].generateSystemPolicy());
+ }*/
+}
Property changes on:
modules/authorization/trunk/agent/src/test/java/org/jboss/security/authz/agent/features/TestImpliesHierarchialPropagation.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied:
modules/authorization/trunk/agent/src/test/java/org/jboss/security/authz/agent/features/TestPolicyServer.java
(from rev 13544,
modules/authorization/trunk/policy-server/src/test/java/org/jboss/security/authz/policy/server/TestPolicyServer.java)
===================================================================
---
modules/authorization/trunk/agent/src/test/java/org/jboss/security/authz/agent/features/TestPolicyServer.java
(rev 0)
+++
modules/authorization/trunk/agent/src/test/java/org/jboss/security/authz/agent/features/TestPolicyServer.java 2009-07-11
18:15:40 UTC (rev 13545)
@@ -0,0 +1,68 @@
+/*
+* 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.features;
+
+import java.net.URI;
+import junit.framework.TestCase;
+import org.apache.log4j.Logger;
+
+import org.jboss.security.authz.agent.provisioning.PolicyProvisioner;
+import org.jboss.security.authz.model.Policy;
+import org.jboss.security.authz.policy.server.Server;
+
+/**
+ * @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
+ */
+public class TestPolicyServer extends TestCase
+{
+ private static Logger log = Logger.getLogger(TestPolicyServer.class);
+
+ private PolicyProvisioner provisioner;
+
+
+ public void setUp() throws Exception
+ {
+ Server.bootstrap();
+ this.provisioner =
(PolicyProvisioner)Server.lookup("/provisioning/localProvisioner");
+ }
+
+ public void tearDown() throws Exception
+ {
+ }
+
+ //TODO: Rewrite these tests with the new Developer Framework
+ /*public void testNewPolicy() throws Exception
+ {
+ HttpResource httpResource = new HttpResource();
+ httpResource.setUri(new URI("/blah/index.html"));
+ httpResource.addParameter("param1", "param1Value");
+
+ this.provisioner.newPolicy(httpResource.getPolicyMetaData());
+
+ //Assert Policy State of the Server
+ Policy[] policies = this.provisioner.readAllPolicies();
+
+ assertTrue("Policy Store must not be empty!!", (policies != null &&
policies.length == 1));
+ log.info("------------------------------------------------------------------------------");
+ log.info(policies[0].generateSystemPolicy());
+ }*/
+}
Property changes on:
modules/authorization/trunk/agent/src/test/java/org/jboss/security/authz/agent/features/TestPolicyServer.java
___________________________________________________________________
Name: svn:mergeinfo
+
Deleted:
modules/authorization/trunk/policy-server/src/test/java/org/jboss/security/authz/policy/server/TestHierarchialPropagation.java
===================================================================
---
modules/authorization/trunk/policy-server/src/test/java/org/jboss/security/authz/policy/server/TestHierarchialPropagation.java 2009-07-11
18:09:49 UTC (rev 13544)
+++
modules/authorization/trunk/policy-server/src/test/java/org/jboss/security/authz/policy/server/TestHierarchialPropagation.java 2009-07-11
18:15:40 UTC (rev 13545)
@@ -1,252 +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.policy.server;
-
-import java.net.URI;
-
-import junit.framework.TestCase;
-import org.apache.log4j.Logger;
-
-import org.jboss.security.authz.model.Policy;
-import org.jboss.security.authz.model.PolicyMetaData;
-import org.jboss.security.authz.model.Resource;
-import org.jboss.security.authz.policy.client.enforcement.Request;
-import org.jboss.security.authz.policy.client.enforcement.Response;
-
-import org.jboss.security.authz.agent.enforcement.PolicyEnforcementPoint;
-import org.jboss.security.authz.agent.provisioning.PolicyProvisioner;
-import org.jboss.security.authz.components.resource.URIResource;
-import org.jboss.security.authz.components.subject.Roles;
-import org.jboss.security.authz.components.action.Read;
-
-
-/**
- * @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
- */
-public class TestHierarchialPropagation extends TestCase
-{
- private static Logger log = Logger.getLogger(TestHierarchialPropagation.class);
-
- private PolicyEnforcementPoint enforcer;
- private PolicyProvisioner provisioner;
-
- public void setUp() throws Exception
- {
- Server.bootstrap();
- this.enforcer =
(PolicyEnforcementPoint)Server.lookup("/enforcement/localEnforcementPoint");
- this.provisioner =
(PolicyProvisioner)Server.lookup("/provisioning/localProvisioner");
- }
-
- public void tearDown() throws Exception
- {
- }
-
- //TODO: Rewrite these tests with the new Developer Framework
- /*public void testExplicitPermit() throws Exception
- {
- //SetUp Resource
- URIResource resource = new URIResource();
- resource.setUri(new URI("/root/level1/level2/index.html"));
- resource.setOperation(new Read());
- resource.addAllowed("user");
-
- //Provision the new policy
- PolicyMetaData metadata = resource.getPolicyMetaData();
- this.provisioner.newPolicy(metadata);
-
- //Go ahead and produce a RequestContext for a "Permit" Enforcement
- URIResource contextResource = new URIResource();
- contextResource.setUri(new URI("/root/level1/level2/index.html"));
- contextResource.setOperation(new Read());
-
- //Perform enforcement
- this.enforce(this.createRequest(contextResource), true);
- }
-
- public void testExplicitDeny() throws Exception
- {
- //SetUp Resource
- URIResource resource = new URIResource();
- resource.setUri(new URI("/root/level1/level2/index.html"));
- resource.setOperation(new Read());
- resource.addDenied("user");
-
- //Provision the new policy
- PolicyMetaData metadata = resource.getPolicyMetaData();
- this.provisioner.newPolicy(metadata);
- this.assertServerState();
-
- //Go ahead and produce a RequestContext for a "Permit" Enforcement
- URIResource contextResource = new URIResource();
- contextResource.setUri(new URI("/root/level1/level2/index.html"));
- contextResource.setOperation(new Read());
-
- //Perform enforcement
- this.enforce(this.createRequest(contextResource), false);
- }
-
- public void testPermitInheritance() throws Exception
- {
- //SetUp Resource
- URIResource resource = new URIResource();
- resource.setUri(new URI("/root/level1"));
- resource.setOperation(new Read());
- resource.addAllowed("user");
-
- //Provision the new policy
- PolicyMetaData metadata = resource.getPolicyMetaData();
- this.provisioner.newPolicy(metadata);
-
- //Go ahead and produce a RequestContext for a "Permit" Enforcement
- URIResource contextResource = new URIResource();
- contextResource.setUri(new URI("/root/level1/level2/index.html"));
- contextResource.setOperation(new Read());
-
- //Perform enforcement
- this.enforce(this.createRequest(contextResource), true);
- }
-
- public void testDenyInheritance() throws Exception
- {
- //SetUp Resource
- URIResource resource = new URIResource();
- resource.setUri(new URI("/root/level1"));
- resource.setOperation(new Read());
- resource.addDenied("user");
-
- //Provision the new policy
- PolicyMetaData metadata = resource.getPolicyMetaData();
- this.provisioner.newPolicy(metadata);
-
- //Go ahead and produce a RequestContext for a "Permit" Enforcement
- URIResource contextResource = new URIResource();
- contextResource.setUri(new URI("/root/level1/level2/index.html"));
- contextResource.setOperation(new Read());
-
- //Perform enforcement
- this.enforce(this.createRequest(contextResource), false);
- }
-
- public void testDenyOverridesPermitInheritance() throws Exception
- {
- //SetUp Permit policy
- URIResource resource = new URIResource();
- resource.setUri(new URI("/root/level1"));
- resource.setOperation(new Read());
- resource.addAllowed("user");
-
- //Provision the new policy
- PolicyMetaData metadata = resource.getPolicyMetaData();
- this.provisioner.newPolicy(metadata);
-
- //Setup denied policy
- resource = new URIResource();
- resource.setUri(new URI("/root/level1/level2"));
- resource.setOperation(new Read());
- resource.addDenied("user");
-
- //Provision the new policy
- metadata = resource.getPolicyMetaData();
- this.provisioner.newPolicy(metadata);
-
- //Go ahead and produce a RequestContext for a "Permit" Enforcement
- URIResource contextResource = new URIResource();
- contextResource.setUri(new URI("/root/level1/level2/index.html"));
- contextResource.setOperation(new Read());
-
- //Perform enforcement
- this.enforce(this.createRequest(contextResource), false);
- }
-
- public void testNotApplicable() throws Exception
- {
- //SetUp Resource
- URIResource resource = new URIResource();
- resource.setUri(new URI("/root2"));
- resource.setOperation(new Read());
- resource.addAllowed("user");
-
- //Provision the new policy
- PolicyMetaData metadata = resource.getPolicyMetaData();
- this.provisioner.newPolicy(metadata);
-
- //Go ahead and produce a RequestContext for a "Permit" Enforcement
- URIResource contextResource = new URIResource();
- contextResource.setUri(new URI("/root/level1/level2/index.html"));
- contextResource.setOperation(new Read());
-
- //Perform enforcement
- this.enforce(this.createRequest(contextResource), false);
- }
- //------------------------------------------------------------------------------------------------------------------------------------------------------
- private Request createRequest(URIResource uriResource) throws Exception
- {
- //Create a RequestType
- Request request = new Request();
-
- //Enable Hierarchial Enforcement
- request.setActivateHierarchialEnforcement(true);
-
- //Create Resource
- Resource urlResource = uriResource.getResource();
- request.addResource(urlResource);
-
- //Create Subjects
- Roles roles = new Roles();
- roles.addName("user");
- request.addSubject(roles.getSubject());
-
- //Create Action
- request.setAction(uriResource.getOperation().getAction());
-
- return request;
- }
-
- private void enforce(Request request, boolean mustBePermitted) throws Exception
- {
-
- Response response = this.enforcer.checkAccess(request);
-
- assertNotNull(response);
- log.info("-----------------------------------");
- log.info("Decision="+response.getMessage());
-
- if(mustBePermitted)
- {
- assertTrue("Access must be granted!!!", response.isAccessGranted());
- }
- else
- {
- assertFalse("Access must be denied!!!", response.isAccessGranted());
- }
- }
-
- private void assertServerState() throws Exception
- {
- //Assert Policy State of the Server
- Policy[] policies = this.provisioner.readAllPolicies();
-
- assertTrue("Policy Store must not be empty!!", (policies != null &&
policies.length == 1));
- log.info("------------------------------------------------------------------------------");
- log.info(policies[0].generateSystemPolicy());
- }*/
-}
Deleted:
modules/authorization/trunk/policy-server/src/test/java/org/jboss/security/authz/policy/server/TestImpliedActions.java
===================================================================
---
modules/authorization/trunk/policy-server/src/test/java/org/jboss/security/authz/policy/server/TestImpliedActions.java 2009-07-11
18:09:49 UTC (rev 13544)
+++
modules/authorization/trunk/policy-server/src/test/java/org/jboss/security/authz/policy/server/TestImpliedActions.java 2009-07-11
18:15:40 UTC (rev 13545)
@@ -1,169 +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.policy.server;
-
-import java.net.URI;
-
-import junit.framework.TestCase;
-import org.apache.log4j.Logger;
-
-import org.jboss.security.authz.model.Policy;
-import org.jboss.security.authz.model.PolicyMetaData;
-import org.jboss.security.authz.model.Resource;
-import org.jboss.security.authz.policy.client.enforcement.Request;
-import org.jboss.security.authz.policy.client.enforcement.Response;
-
-import org.jboss.security.authz.agent.enforcement.PolicyEnforcementPoint;
-import org.jboss.security.authz.agent.provisioning.PolicyProvisioner;
-import org.jboss.security.authz.components.resource.URIResource;
-import org.jboss.security.authz.components.subject.Roles;
-import org.jboss.security.authz.components.action.Operation;
-import org.jboss.security.authz.components.action.Read;
-import org.jboss.security.authz.components.action.Write;
-import org.jboss.security.authz.components.action.Manage;
-
-
-/**
- * @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
- */
-public class TestImpliedActions extends TestCase
-{
- private static Logger log = Logger.getLogger(TestImpliedActions.class);
-
- private PolicyEnforcementPoint enforcer;
- private PolicyProvisioner provisioner;
-
- public void setUp() throws Exception
- {
- Server.bootstrap();
- this.enforcer =
(PolicyEnforcementPoint)Server.lookup("/enforcement/localEnforcementPoint");
- this.provisioner =
(PolicyProvisioner)Server.lookup("/provisioning/localProvisioner");
- }
-
- public void tearDown() throws Exception
- {
- }
-
- //TODO: Rewrite these tests with the new Developer Framework
- /*public void testReadImpliedWithWrite() throws Exception
- {
- //SetUp Resource
- URIResource resource = new URIResource();
- resource.setUri(new URI("/blah/index.html"));
- resource.setOperation(new Write());
- resource.addAllowed("user");
-
-
- PolicyMetaData metadata = resource.getPolicyMetaData();
-
- this.provisioner.newPolicy(metadata);
- this.assertServerState();
-
- //Go ahead and produce a RequestContext for a "Permit" Enforcement
- this.enforce(this.createRequest(resource, new Read()), true);
- }
-
- public void testWriteImpliedWithManage() throws Exception
- {
- //SetUp Resource
- URIResource resource = new URIResource();
- resource.setUri(new URI("/blah/index.html"));
- resource.setOperation(new Manage());
- resource.addAllowed("user");
-
-
- PolicyMetaData metadata = resource.getPolicyMetaData();
-
- this.provisioner.newPolicy(metadata);
- this.assertServerState();
-
- //Go ahead and produce a RequestContext for a "Permit" Enforcement
- this.enforce(this.createRequest(resource, new Write()), true);
- }
-
- public void testWriteNotImpliedWithRead() throws Exception
- {
- //SetUp Resource
- URIResource resource = new URIResource();
- resource.setUri(new URI("/blah/index.html"));
- resource.setOperation(new Read());
- resource.addAllowed("user");
-
-
- PolicyMetaData metadata = resource.getPolicyMetaData();
-
- this.provisioner.newPolicy(metadata);
- this.assertServerState();
-
- //Go ahead and produce a RequestContext for a "Deny" Enforcement
- this.enforce(this.createRequest(resource, new Write()), false);
- }
- //------------------------------------------------------------------------------------------------------------------------------------------------------
- private Request createRequest(URIResource uriResource, Operation operation) throws
Exception
- {
- //Create a RequestType
- Request request = new Request();
-
- //Create Resource
- Resource urlResource = uriResource.getResource();
- request.addResource(urlResource);
-
- //Create Subjects
- Roles roles = new Roles();
- roles.addName("user");
- request.addSubject(roles.getSubject());
-
- //Create Action
- request.setAction(operation.getAction());
-
- return request;
- }
-
- private void enforce(Request request, boolean mustBePermitted) throws Exception
- {
-
- Response response = this.enforcer.checkAccess(request);
-
- assertNotNull(response);
- log.info("-----------------------------------");
- log.info("Decision="+response.getMessage());
-
- if(mustBePermitted)
- {
- assertTrue("Access must be granted!!!", response.isAccessGranted());
- }
- else
- {
- assertFalse("Access must be denied!!!", response.isAccessGranted());
- }
- }
-
- private void assertServerState() throws Exception
- {
- //Assert Policy State of the Server
- Policy[] policies = this.provisioner.readAllPolicies();
-
- assertTrue("Policy Store must not be empty!!", (policies != null &&
policies.length == 1));
- log.info("------------------------------------------------------------------------------");
- log.info(policies[0].generateSystemPolicy());
- }*/
-}
Deleted:
modules/authorization/trunk/policy-server/src/test/java/org/jboss/security/authz/policy/server/TestImpliesHierarchialPropagation.java
===================================================================
---
modules/authorization/trunk/policy-server/src/test/java/org/jboss/security/authz/policy/server/TestImpliesHierarchialPropagation.java 2009-07-11
18:09:49 UTC (rev 13544)
+++
modules/authorization/trunk/policy-server/src/test/java/org/jboss/security/authz/policy/server/TestImpliesHierarchialPropagation.java 2009-07-11
18:15:40 UTC (rev 13545)
@@ -1,233 +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.policy.server;
-
-import java.net.URI;
-
-import junit.framework.TestCase;
-import org.apache.log4j.Logger;
-
-import org.jboss.security.authz.model.Policy;
-import org.jboss.security.authz.model.PolicyMetaData;
-import org.jboss.security.authz.model.Resource;
-import org.jboss.security.authz.policy.client.enforcement.Request;
-import org.jboss.security.authz.policy.client.enforcement.Response;
-
-import org.jboss.security.authz.agent.enforcement.PolicyEnforcementPoint;
-import org.jboss.security.authz.agent.provisioning.PolicyProvisioner;
-import org.jboss.security.authz.components.resource.URIResource;
-import org.jboss.security.authz.components.subject.Roles;
-import org.jboss.security.authz.components.action.Read;
-import org.jboss.security.authz.components.action.Write;
-import org.jboss.security.authz.components.action.Manage;
-
-
-/**
- * @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
- */
-public class TestImpliesHierarchialPropagation extends TestCase
-{
- private static Logger log = Logger.getLogger(TestImpliesHierarchialPropagation.class);
-
- private PolicyEnforcementPoint enforcer;
- private PolicyProvisioner provisioner;
-
- public void setUp() throws Exception
- {
- Server.bootstrap();
- this.enforcer =
(PolicyEnforcementPoint)Server.lookup("/enforcement/localEnforcementPoint");
- this.provisioner =
(PolicyProvisioner)Server.lookup("/provisioning/localProvisioner");
- }
-
- public void tearDown() throws Exception
- {
- }
-
- //TODO: Rewrite these tests with the new Developer Framework
- /*public void testExplicitPermitReadImpliedWithWrite() throws Exception
- {
- //SetUp Resource
- URIResource resource = new URIResource();
- resource.setUri(new URI("/root/level1/level2/index.html"));
- resource.setOperation(new Write());
- resource.addAllowed("user");
-
- //Provision the new policy
- PolicyMetaData metadata = resource.getPolicyMetaData();
- this.provisioner.newPolicy(metadata);
-
- //Go ahead and produce a RequestContext for a "Permit" Enforcement
- URIResource contextResource = new URIResource();
- contextResource.setUri(new URI("/root/level1/level2/index.html"));
- contextResource.setOperation(new Read());
-
- //Perform enforcement
- this.enforce(this.createRequest(contextResource), true);
- }
-
- public void testExplicitDenyWriteNotImpliedWithRead() throws Exception
- {
- //SetUp Resource
- URIResource resource = new URIResource();
- resource.setUri(new URI("/root/level1/level2/index.html"));
- resource.setOperation(new Read());
- resource.addAllowed("user");
-
- //Provision the new policy
- PolicyMetaData metadata = resource.getPolicyMetaData();
- this.provisioner.newPolicy(metadata);
-
- //Go ahead and produce a RequestContext for a "Permit" Enforcement
- URIResource contextResource = new URIResource();
- contextResource.setUri(new URI("/root/level1/level2/index.html"));
- contextResource.setOperation(new Write());
-
- //Perform enforcement
- this.enforce(this.createRequest(contextResource), false);
- }
-
- public void testPermitInheritanceWriteImpliedWithManage() throws Exception
- {
- //SetUp Resource
- URIResource resource = new URIResource();
- resource.setUri(new URI("/root/level1"));
- resource.setOperation(new Manage());
- resource.addAllowed("user");
-
- //Provision the new policy
- PolicyMetaData metadata = resource.getPolicyMetaData();
- this.provisioner.newPolicy(metadata);
-
- //Go ahead and produce a RequestContext for a "Permit" Enforcement
- URIResource contextResource = new URIResource();
- contextResource.setUri(new URI("/root/level1/level2/index.html"));
- contextResource.setOperation(new Write());
-
- //Perform enforcement
- this.enforce(this.createRequest(contextResource), true);
- }
-
- public void testDenyInheritanceManageNotImpliedWithWrite() throws Exception
- {
- //SetUp Resource
- URIResource resource = new URIResource();
- resource.setUri(new URI("/root/level1"));
- resource.setOperation(new Write());
- resource.addAllowed("user");
-
- //Provision the new policy
- PolicyMetaData metadata = resource.getPolicyMetaData();
- this.provisioner.newPolicy(metadata);
-
- //Go ahead and produce a RequestContext for a "Permit" Enforcement
- URIResource contextResource = new URIResource();
- contextResource.setUri(new URI("/root/level1/level2/index.html"));
- contextResource.setOperation(new Manage());
-
- //Perform enforcement
- this.enforce(this.createRequest(contextResource), false);
- }
-
- public void testDenyOverridesPermitInheritance() throws Exception
- {
- //SetUp Permit policy...User can write to level1
- URIResource resource = new URIResource();
- resource.setUri(new URI("/root/level1"));
- resource.setOperation(new Write());
- resource.addAllowed("user");
-
- //Provision the new policy
- PolicyMetaData metadata = resource.getPolicyMetaData();
- this.provisioner.newPolicy(metadata);
-
- //Setup denied policy....User can only read level2
- resource = new URIResource();
- resource.setUri(new URI("/root/level1/level2"));
- resource.setOperation(new Read());
- resource.addAllowed("user");
-
- //Provision the new policy
- metadata = resource.getPolicyMetaData();
- this.provisioner.newPolicy(metadata);
-
- //Go ahead and produce a RequestContext for a "Permit" Enforcement
- //Trying to "Write" to level2 should be Denied
- URIResource contextResource = new URIResource();
- contextResource.setUri(new URI("/root/level1/level2/index.html"));
- contextResource.setOperation(new Write());
-
- //Perform enforcement
- this.enforce(this.createRequest(contextResource), false);
- }
- //------------------------------------------------------------------------------------------------------------------------------------------------------
- private Request createRequest(URIResource uriResource) throws Exception
- {
- //Create a RequestType
- Request request = new Request();
-
- //Enable Hierarchial Enforcement
- request.setActivateHierarchialEnforcement(true);
-
- //Create Resource
- Resource urlResource = uriResource.getResource();
- request.addResource(urlResource);
-
- //Create Subjects
- Roles roles = new Roles();
- roles.addName("user");
- request.addSubject(roles.getSubject());
-
- //Create Action
- request.setAction(uriResource.getOperation().getAction());
-
- return request;
- }
-
- private void enforce(Request request, boolean mustBePermitted) throws Exception
- {
-
- Response response = this.enforcer.checkAccess(request);
-
- assertNotNull(response);
- log.info("-----------------------------------");
- log.info("Decision="+response.getMessage());
-
- if(mustBePermitted)
- {
- assertTrue("Access must be granted!!!", response.isAccessGranted());
- }
- else
- {
- assertFalse("Access must be denied!!!", response.isAccessGranted());
- }
- }
-
- private void assertServerState() throws Exception
- {
- //Assert Policy State of the Server
- Policy[] policies = this.provisioner.readAllPolicies();
-
- assertTrue("Policy Store must not be empty!!", (policies != null &&
policies.length == 1));
- log.info("------------------------------------------------------------------------------");
- log.info(policies[0].generateSystemPolicy());
- }*/
-}
Deleted:
modules/authorization/trunk/policy-server/src/test/java/org/jboss/security/authz/policy/server/TestPolicyServer.java
===================================================================
---
modules/authorization/trunk/policy-server/src/test/java/org/jboss/security/authz/policy/server/TestPolicyServer.java 2009-07-11
18:09:49 UTC (rev 13544)
+++
modules/authorization/trunk/policy-server/src/test/java/org/jboss/security/authz/policy/server/TestPolicyServer.java 2009-07-11
18:15:40 UTC (rev 13545)
@@ -1,67 +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.policy.server;
-
-import java.net.URI;
-import junit.framework.TestCase;
-import org.apache.log4j.Logger;
-
-import org.jboss.security.authz.agent.provisioning.PolicyProvisioner;
-import org.jboss.security.authz.model.Policy;
-
-/**
- * @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
- */
-public class TestPolicyServer extends TestCase
-{
- private static Logger log = Logger.getLogger(TestPolicyServer.class);
-
- private PolicyProvisioner provisioner;
-
-
- public void setUp() throws Exception
- {
- Server.bootstrap();
- this.provisioner =
(PolicyProvisioner)Server.lookup("/provisioning/localProvisioner");
- }
-
- public void tearDown() throws Exception
- {
- }
-
- //TODO: Rewrite these tests with the new Developer Framework
- /*public void testNewPolicy() throws Exception
- {
- HttpResource httpResource = new HttpResource();
- httpResource.setUri(new URI("/blah/index.html"));
- httpResource.addParameter("param1", "param1Value");
-
- this.provisioner.newPolicy(httpResource.getPolicyMetaData());
-
- //Assert Policy State of the Server
- Policy[] policies = this.provisioner.readAllPolicies();
-
- assertTrue("Policy Store must not be empty!!", (policies != null &&
policies.length == 1));
- log.info("------------------------------------------------------------------------------");
- log.info(policies[0].generateSystemPolicy());
- }*/
-}