<?xml version="1.0" encoding="utf-8" ?>

<!--Policy in the EPAL language For the Direct Permissions Privacy Systems Example.-->

<epal-policy default-ruling="deny"
 version="1.2" xmlns="http://www.seas.upenn.edu/~mjmay/epal"
 xmlns:xs="http://www.w3.org/2001/XMLSchema"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://www.seas.upenn.edu/~mjmay/epal.xsd">
	<policy-information id="DP-Policy">
		<short-description language="en">Policy that enforces the rules of a Direct Permissions
		Privacy System.  It accomplishes this by using the Direct Time Limited Permissions
		vocabulary and just ignoring the time attributes.</short-description>
		<issuer>
			<name>Penn Security Lab</name>
			<organization>University of Pennsylvania</organization>
			<e-mail>mjmay@seas.upenn.edu</e-mail>
			<address>200 South 33rd Street, Philadelphia, PA 19104</address>
			<country>USA</country>
		</issuer>
		<location>http://securitylab.cis.upenn.edu/pdrm</location>
		<version-info end-date="2005-07-26T12:00:00" last-modified="2004-08-11T13:19:00" start-date="2004-07-26T12:19:00"
			test="true" />
	</policy-information>
	
	<epal-vocabulary-ref id="DTLP-Vocab" location="http://securitylab.cis.upenn.edu/pdrm/" />
	
	<!--Conditions for the privacy system-->
	<condition id="HasDirPermission">
		<short-description language="en">Checks that the requesting principal has direct permission set</short-description>
		
		<!--Permission is set to direct permission-->
		<predicate refid="http://www.research.ibm.com/privacy/epal#string-equal">
			<function refid="http://www.research.ibm.com/privacy/epal#string-bag-to-value">
				<attribute-reference container-refid="PrincipalPermissions" attribute-refid="Sigma" />
			</function>
			<attribute-value simpleType="http://www.w3.org/2001/XMLSchema#string">dir</attribute-value>
		</predicate>
	</condition>
	
	<!--If the event is a Transfer event:
        (a) The subscriber must have direct permission
        (b) The object being transfered must be about the subject of the direct permission
        (c) The name of the receiver must match the name of the permission-->
	<condition id="PublishSubscribeEventConditions">
		<short-description language="en">The conditions that must be true particularly for a publish subscribe event</short-description>
		
		<!--AND-ing all the conditions below together-->
		<predicate refid="http://www.research.ibm.com/privacy/epal#and">
		
		<!--Checking that the subscriber has direct permission.  This is done again because the PrincipalPermissions
         check in the normal direct permissions check is ambiguous about whose permission is being checked - whether
         it's the publisher or the subscriber-->
			<predicate refid="http://www.research.ibm.com/privacy/epal#string-equal">
				<function refid="http://www.research.ibm.com/privacy/epal#string-bag-to-value">
					<attribute-reference container-reference="TransferPermissions" attribute-refid="SubscriberSigma" />
				</function>
				<attribute-value simpleType="http://www.w3.org/2001/XMLSchema#string">dir</attribute-value>
			</predicate>
			
			<!--Checking the name of the subject in the permission against the name of the subject of the item being transfered-->
			<predicate refid="http://www.research.ibm.com/privacy/epal#string-equal">
				<function refid="http://www.research.ibm.com/privacy/epal#string-bag-to-value">
					<attribute-reference container-refid="PublishSubscribeEvent" attribute-refid="Subject" />
				</function>
				<function refid="http://www.research.ibm.com/privacy/epal#string-bag-to-value">
					<attribute-reference container-refid="TransferPermissions" attribute-refid="Subject" />
				</function>
			</predicate>
			
			<!--Checking the name of the Subscriber in the permission against the name of the Subscriber in the permission-->
			<predicate refid="http://www.research.ibm.com/privacy/epal#string-equal">
				<function refid="http://www.research.ibm.com/privacy/epal#string-bag-to-value">
					<attribute-reference container-refid="PublishSubscribeEvent" attribute-refid="Subscriber" />
				</function>
				<function refid="http://www.research.ibm.com/privacy/epal#string-bag-to-value">
					<attribute-reference container-refid="TransferPermissions" attribute-refid="Subscriber" />
				</function>
			</predicate>
		</predicate>
	</condition>
	
	<!--If the event is a Action event:
       (a) The actor must have direct permission
       (b) The name of the subject must match the name of the permission
       (c) The name of the actor must match the name of the permission-->
	<condition id="ActionEventCondition">
		<short-description language="en">The conditions that need to be checked for an Action event to proceed</short-description>
		
		<!--AND-ing all the conditions below together-->
		<predicate refid="http://www.research.ibm.com/privacy/epal#and">
		
		<!--Checking the name of the subject in the permission against the name of the subject of the action-->
		<predicate refid="http://www.research.ibm.com/privacy/epal#string-equal">
			<function refid="http://www.research.ibm.com/privacy/epal#string-bag-to-value">
				<attribute-reference container-refid="ActionEvent" attribute-refid="Subject" />
			</function>
			<function refid="http://www.research.ibm.com/privacy/epal#string-bag-to-value">
				<attribute-reference container-refid="PrincipalPermissions" attribute-refid="Subject" />
			</function>
		</predicate>
		
		<!--Checking the name of the owner in the permission against the name of the actor in the permission-->
			<predicate refid="http://www.research.ibm.com/privacy/epal#string-equal">
				<function refid="http://www.research.ibm.com/privacy/epal#string-bag-to-value">
					<attribute-reference container-refid="ActionEvent" attribute-refid="Actor" />
				</function>
				<function refid="http://www.research.ibm.com/privacy/epal#string-bag-to-value">
					<attribute-reference container-refid="PrincipalPermissions" attribute-refid="Owner" />
				</function>
			</predicate>
		</predicate>
	</condition>
	
	<!--If the event is a Creation event:
       (a) The creator must have direct permission
       (b) The name of the subject must match the name of the permission
       (c) The name of the creator must match the name of the permission-->
	<condition id="CreationEventCondition">
		<short-description language="en">Conditions necessary for the execution of a Creation event</short-description>
		
		<!--AND-ing all the conditions below together-->
		<predicate refid="http://www.research.ibm.com/privacy/epal#and">
		
		<!--Checking the name of the subject in the permission against the name of the subject of the action-->
		<predicate refid="http://www.research.ibm.com/privacy/epal#string-equal">
			<function refid="http://www.research.ibm.com/privacy/epal#string-bag-to-value">
				<attribute-reference container-refid="CreationEvent" attribute-refid="Subject" />
			</function>
			<function refid="http://www.research.ibm.com/privacy/epal#string-bag-to-value">
				<attribute-reference container-refid="PrincipalPermissions" attribute-refid="Subject" />
			</function>
		</predicate>
		
		<!--Checking the name of the owner in the permission against the name of the creator in the permission-->		
		<predicate refid="http://www.research.ibm.com/privacy/epal#string-equal">
			<function refid="http://www.research.ibm.com/privacy/epal#string-bag-to-value">
				<attribute-reference container-refid="CreationEvent" attribute-refid="Creator" />
			</function>
			<function refid="http://www.research.ibm.com/privacy/epal#string-bag-to-value">
				<attribute-reference container-refid="PrincipalPermissions" attribute-refid="Owner" />
			</function>
		</predicate>
	
		</predicate>
	</condition>
	
	<!--If the event is a Set Policy Establishment event:
       (a) The establisher must be the subject of the permissions-->
	<condition id="SetterIsSubjectCondition">
		<short-description language="en">Conditions necessary for a set policy event to be executed</short-description>
		
		<!--Checking the name of the establisher in the permission against the name of the subject of the set policy action-->
		<predicate refid="http://www.research.ibm.com/privacy/epal#string-equal">
			<function refid="http://www.research.ibm.com/privacy/epal#string-bag-to-value">
				<attribute-reference container-refid="SetPolicyEvent" attribute-refid="Setter" />
			</function>
			<function refid="http://www.research.ibm.com/privacy/epal#string-bag-to-value">
				<attribute-reference container-refid="SetPolicyEvent" attribute-refid="Subject" />
			</function>
		</predicate>
	</condition>
	
	<!--Rules for the direct permissions example-->
	
	<!--Publish/Subscribe event rule-->
	<rule id="PublishSubscribeRule" ruling="allow">
		<short-description language="en">Allows transfer of data provided that the receiver
        has direct permission and that the other conditions in the Publish/Subscribe event are met</short-description>

		<user-category refid="AnyUser" />
		<data-category refid="AnyCategory" />
		<purpose refid="AnyPurpose" />
		<action refid="PublishSubscribe" />
		<condition refid="PublishSubsribeEventCondition" />
		<condtion refid="HasDirPermission" />
	</rule>
	
	<!--Action event rule-->
	<rule id="ActionRule" ruling="allow">
		<short-description language="en">Allows action from one principal on a subject provided
         that the actor has direct permission to do so  and that the other conditions in the
         Action event are met</short-description>
		
		<user-category refid="AnyUser" />
		<data-category refid="AnyCategory" />
		<purpose refid="AnyPurpose" />
		<action refid="Action" />
		<condition refid="ActionEventCondition" />
		<condtion refid="HasDirPermission" />
	</rule>
	
	<!--Creation event rule-->
	<rule id="CreationRule" ruling="allow">
		<short-description language="en">Allows creation of data about a subject provided thar the 
         creator has direct permission and that the other conditions in the Creation
         event are met</short-description>
         
		<user-category refid="AnyUser" />
		<data-category refid="AnyCategory" />
		<purpose refid="AnyPurpose" />
		<action refid="Creation" />
		<condition refid="CreationEventCondition" />
		<condtion refid="HasDirPermission" />
	</rule>
	
	<!--Set Policy event rule-->
	<rule id="SetPolicyRule" ruling="allow">
		<short-description language="en">Allows a principal to set the permissions for a subject on
          another principal.  In this example we require direct permission for all events so only
          the subject may set permissions.</short-description>
		
		<user-category refid="AnyUser" />
		<data-category refid="AnyCategory" />
		<purpose refid="AnyPurpose" />
		<action refid="SetPolicy" />
		<condition refid="SetterIsSubjectCondition" />
	</rule>
</epal-policy>