<?xml version="1.0" encoding="UTF-8"?>
<s:schema 
  xmlns:s="http://www.w3.org/2001/XMLSchema" 
  elementFormDefault="qualified" 
  attributeFormDefault="unqualified"

  targetNamespace="http://www.RecordsForLiving.com/Schemas/2009-04/HealthFrameWorks/SecurityPolicy_V1/" 
  xmlns:securitypolicy_V1="http://www.RecordsForLiving.com/Schemas/2009-04/HealthFrameWorks/SecurityPolicy_V1/"
  >

  <s:annotation>
    <s:documentation>These definitions comprise the HealthFrameWorks security policy objects.</s:documentation>
  </s:annotation>


  <s:import
     namespace="http://www.RecordsForLiving.com/Schemas/2009-04/HealthFrameWorks/"
     schemaLocation="Common_V1.xsd"
        />



  <s:simpleType name="UserNameType">
    <s:annotation>
      <s:documentation>
        A user name is something like Jim, or fred@RecordsForLiving.com. It can be basically any string the user chooses
        to uniquely identify himself.

        It does NOT need to be forever unique. UserNames are mapped to UserIDType, and the UserIDType is what is stored
        with objects to identify them.
      </s:documentation>
    </s:annotation>
    <s:restriction base="s:string"/>
  </s:simpleType>

  <s:simpleType name="UserIDType">
    <s:annotation>
      <s:documentation>
        A UserIDType is a GUID (need to refine this 'restriction' to be a GUID).
      </s:documentation>
    </s:annotation>
    <s:restriction base="s:string"/>
  </s:simpleType>

  <s:simpleType name="SecurityPrincipalType">
    <s:annotation>
      <s:documentation>
        A 'security principal' - SecurityPrincipalType - can be either a username, or a user-id. It is something recognized as uniquely describing a person or group to which permission specifications apply.

        The form of a user-id is a GUID. This is what is stored internally. But the username (e.g. fred@yahoo.com) can be any string.

        The way this is disambugiated (conceptually, not necesarily in the implementation), is that a name security principal is looked up in the user database, and mapped to a GUID. If its not found, but is already found to be in the form of a guid, its assumed it was really just a guid to begin with.

        Plus - there is the special SecurityPrincipalType - kWildcardPrincipal (*).

        This type SHOULD be redine to be a UNION of UserNameType, UserIDType, and some specials (like *).
      </s:documentation>
    </s:annotation>
    <s:restriction base="s:string"/>
  </s:simpleType>

  <s:complexType name="AccessControlAccessType">
    <s:annotation>
      <s:documentation>
        This defines the type of access an access control rule applies to. The values
        Read
        Write
        ReadMetaInfo
        WriteMetaInfo
        Delete
        Restore
        ReadSecurity
        WriteSecurity
        all define elemental types which can be combined by listing multiple AccessType elements.

        The value
          Full
        refers to all of the above permissions.
      </s:documentation>
    </s:annotation>
    <s:sequence>
      <s:element name="AccessType" minOccurs="1" maxOccurs="unbounded">
        <s:simpleType>
          <s:restriction base="s:string">
            <!--individual values-->
            <s:enumeration value="Read"/>
            <s:enumeration value="Write"/>
            <s:enumeration value="ReadMetaInfo"/>
            <s:enumeration value="WriteMetaInfo"/>
            <s:enumeration value="Delete"/>
            <s:enumeration value="Restore"/>
            <s:enumeration value="ReadSecurity"/>
            <s:enumeration value="WriteSecurity"/>
            <!--special values-->
            <s:enumeration value="Full"/>
          </s:restriction>
        </s:simpleType>
      </s:element>
    </s:sequence>
  </s:complexType>

  <s:simpleType name="AccessControlGrantDenyType">
    <s:annotation>
      <s:documentation/>
    </s:annotation>
    <s:restriction base="s:string">
      <s:enumeration value="grant"/>
      <s:enumeration value="deny"/>
    </s:restriction>
  </s:simpleType>

  <s:simpleType name="AccessControlObjectProtectedType">
    <s:annotation>
      <s:documentation/>
    </s:annotation>
    <s:restriction base="s:string">
      <s:enumeration value="HR"/>
      <s:enumeration value="Element"/>
      <s:enumeration value="Filter"/>
      <s:enumeration value="Report"/>
    </s:restriction>
  </s:simpleType>

  <s:complexType name="AccessControlObjectIDType">
    <s:annotation>
      <s:documentation>
        This is to describe the kind of object to which an ACL (access control list) applies. An ACL always refers to an implied HR (often the one its  stored with). The ACL can also apply either to an elmenet within that HR (such as a condition, or filter), or it can refer to a report. Which - is determined by the ReportID/RelativeID attributes.

        Note - we cannot use IDREF for RelativeID because this schema element (ACLs) could be stored separately from the HR to which it applies
      </s:documentation>
		</s:annotation>
    <s:attribute name="RelativeTo" type="securitypolicy_V1:AccessControlObjectProtectedType" use="required"/>
    <s:attribute name="RelativeID" type="s:string" use="optional"/>
	</s:complexType>

  <s:complexType name="AccessControlElementType">
		<s:sequence>
			<s:element name="ObjectID" type="securitypolicy_V1:AccessControlObjectIDType"/>
      <s:element name="Access" type="securitypolicy_V1:AccessControlAccessType" minOccurs="1" maxOccurs="1"/>
    </s:sequence>
    <s:attribute name="Principal" type="securitypolicy_V1:SecurityPrincipalType" use="required"/>
    <s:attribute name="Action" type="securitypolicy_V1:AccessControlGrantDenyType" use="required"/>
  </s:complexType>

  <s:complexType name="AccessControlListType">
		<s:sequence>
			<s:element name="ACE" type="securitypolicy_V1:AccessControlElementType" minOccurs="0" maxOccurs="unbounded"/>
		</s:sequence>
	</s:complexType>

  <s:simpleType name="PasswordEncoding">
    <s:annotation>
      <s:documentation>
        Use NONE for an unencoded password and primary for the default password encoding. Note - either one
        COULD fail - if unsupported.

        Use Primary to get/set the password in the form which is the native/default format for the given repository.
        Use this enumeration value if you dont need to know the format - just to 'pass though' an encoded password.
      </s:documentation>
    </s:annotation>
    <s:restriction base="s:string">
      <s:enumeration value="None" />
      <s:enumeration value="Primary" />
    </s:restriction>
  </s:simpleType>

  <s:complexType name="SecurityPolicyType">
		<s:sequence>
			<s:element name="AccessControlList" type="securitypolicy_V1:AccessControlListType" minOccurs="0"/>
		</s:sequence>
	</s:complexType>
</s:schema>

