<?xml version="1.0" encoding="UTF-8"?>
<!--
  ! CCPL HEADER START
  !
  ! This work is licensed under the Creative Commons
  ! Attribution-NonCommercial-NoDerivs 3.0 Unported License.
  ! To view a copy of this license, visit
  ! http://creativecommons.org/licenses/by-nc-nd/3.0/
  ! or send a letter to Creative Commons, 444 Castro Street,
  ! Suite 900, Mountain View, California, 94041, USA.
  !
  ! You can also obtain a copy of the license at
  ! src/main/resources/legal-notices/CC-BY-NC-ND.txt.
  ! See the License for the specific language governing permissions
  ! and limitations under the License.
  !
  ! If applicable, add the following below this CCPL HEADER, with the fields
  ! enclosed by brackets "[]" replaced with your own identifying information:
  !      Portions Copyright [yyyy] [name of copyright owner]
  !
  ! CCPL HEADER END
  !
  !      Copyright 2011-2012 ForgeRock AS
  !    
-->
<chapter xml:id='chap-entitlements'
 xmlns='http://docbook.org/ns/docbook'
 version='5.0' xml:lang='en'
 xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
 xsi:schemaLocation='http://docbook.org/ns/docbook http://docbook.org/xml/5.0/xsd/docbook.xsd'
 xmlns:xlink='http://www.w3.org/1999/xlink'
 xmlns:xinclude='http://www.w3.org/2001/XInclude'>
 <title>Defining Entitlements</title>
 
 <para>This chapter covers how to define entitlements for fine-grained
 authorization to access particular resources.</para>
 
 <section xml:id="about-entitlements">
  <title>About Entitlements</title>
  <indexterm><primary>Authorization</primary></indexterm>
  <indexterm><primary>Entitlements</primary></indexterm>
  <indexterm><primary>Policy</primary></indexterm>
  <para>OpenAM <firstterm>entitlements</firstterm> serve much the same purpose
  as OpenAM policies, defining who has access to what, under what conditions.
  You can define entitlements through the OpenAM console, and OpenAM stores and
  manages policies centrally using the standard eXtensible Access Control
  Markup Language (XACML). You can access OpenAM entitlements and policy
  decisions using the RESTful web interface, for even lighter weight policy
  enforcement than with OpenAM policy agents.</para>
  
  <itemizedlist>
   <para>The OpenAM entitlements service uses XACML terminology to refer to
   the different points dealing with policy.</para>
   
   <listitem>
    <para>OpenAM serves as a <firstterm>policy administration point</firstterm>
    (PAP) where you define, store, and manage policies. OpenAM uses the
    configuration directory to store entitlements, whereas profiles are stored
    in the identity repository (user data store).</para>
   </listitem>
   <listitem>
    <para>OpenAM also serves as a <firstterm>policy decision point</firstterm>
    (PDP), evaluating policies and issuing authorization decisions, and as a
    <firstterm>policy information point</firstterm>, providing the information
    needed for authorization decisions.</para>
   </listitem>
   <listitem>
    <para>OpenAM policy agents act as <firstterm>policy enforcement
    points</firstterm>, obtaining decisions from PDPs to protect access to
    resources.</para>
   </listitem>
  </itemizedlist>
  
  <para>Entitlement policies define who has who has access to what, under what
  conditions, in the same way that other OpenAM policies define policy.
  Entitlement policies do let you define virtual subjects and subjects based on
  attribute lookup to determine who has access to the resources.</para>
  
  <para>Entitlements apply for <firstterm>applications</firstterm>, which in
  this context mean protected resources that share a common set of actions
  and related policies. For example, the web agent application protects web
  resources accessed through HTTP GET and POST actions using a web policy
  agent to enforce decisions to allow or deny access. You can also define more
  specific applications as demonstrated by the examples delivered with
  OpenAM.</para>
  
  <para><firstterm>Delegations</firstterm> grant specific users privileges
  to manage policies.</para>
 </section>
 
 <section xml:id="managing-entitlements-console">
  <title>Managing Entitlements in OpenAM Console</title>
  <indexterm>
   <primary>Authorization</primary>
   <secondary>Configuring</secondary>
  </indexterm>
  <indexterm>
   <primary>Entitlements</primary>
   <secondary>Configuring</secondary>
  </indexterm>
  <indexterm>
   <primary>Policy</primary>
   <secondary>Configuring</secondary>
  </indexterm>
  <para>Use the nascent console to manage entitlements. After you login as
  OpenAM Administrator to OpenAM Console, click Test Beta Console, then
  Entitlements. You can return to the Standard Console by using the link at
  the upper right corner of the new console window.</para>
  
  <procedure xml:id="create-entitlements-policy-gui">
   <title>To Create an Entitlements Policy</title>
   
   <step>
    <para>Select Entitlements &gt; Policies &gt; Create Policies to start the
    new entitlement policy wizard.</para>
   </step>
   <step>
    <para>Give your policy a name and a description, and then select the
    application to protect from the drop-down list before clicking Next.</para>
   </step>
   <step>
    <para>Select the resources to protect with the entitlement policy, adding
    exceptions and additional resources as necessary before clicking
    Next.</para>
   </step>
   <step>
    <para>Build your list of subjects who are concerned by this policy using
    the Select Subjects drop box before clicking Next.</para>
   </step>
   <step>
    <para>Set permissions for actions, add conditions, user attributes to
    return in policy decisions and so forth in the advanced settings section
    before clicking Next.</para>
   </step>
   <step>
    <para>Review the entitlement policy summary, and then click Finish to
    create and store the policy in OpenAM.</para>
   </step>
  </procedure>
  
  <procedure xml:id="export-entitlements-policy-gui">
   <title>To Export an Entitlements Policy</title>
   
   <step>
    <para>Select Entitlements &gt; Policies &gt; Manage Policies to
    display the list of entitlement policies.</para>
   </step>
   <step>
    <para>Check the box next to the policy or policies to export.</para>
   </step>
   <step>
    <para>Click the Export link above the table, and then click OK in the
    alert box.</para>
    <para>OpenAM exports your policy in XML format.</para>
    <screen>&lt;Policy RuleCombiningAlgId="urn:oasis:names:tc:xacml:3.0:rule-
 combining-algorithm:deny-overrides" Version="2011.10.07.11.51.27.444"
 PolicyId="New Policy"&gt;
... policy content here ...
&lt;/Policy&gt;</screen>
    <para>What you see in the browser window depends on what your browser
    chooses to do with XML.</para>
   </step>
  </procedure>

  <procedure xml:id="create-entitlements-application-gui">
   <title>To Create an Entitlements Application</title>
   
   <step>
    <para>Select Entitlements &gt; Applications &gt; Create Applications to
    start the new entitlement application wizard.</para>
   </step>
   <step>
    <para>Give your application a name and a description, and then select the
    application type from the drop-down list before clicking Next.</para>
   </step>
   <step>
    <para>Add resources pertaining to the application, and then click
    Next.</para>
   </step>
   <step>
    <para>Select the subject types to which policies for the application apply,
    and then click Next.</para>
   </step>
   <step>
    <para>Select the appropriate permissions for actions the subjects can take
    on the application, and then click Next.</para>
   </step>
   <step>
    <para>Select the condition types allowed for policies that apply to this
    type of application, and then click Next.</para>
   </step>
   <step>
    <para>Configure how to resolve decisions when policies conflict, and then
    click Next.</para>
   </step>
   <step>
    <para>Review the application configuration summary, and then click Finish
    to create and store the application type in OpenAM.</para>
   </step>
  </procedure>
  
  <procedure xml:id="create-entitlements-delegation-gui">
   <title>To Create an Entitlements Delegation</title>
   <indexterm>
    <primary>Authorization</primary>
    <secondary>Delegating</secondary>
   </indexterm>
   <indexterm>
    <primary>Entitlements</primary>
    <secondary>Delegating</secondary>
   </indexterm>
   <indexterm>
    <primary>Policy</primary>
    <secondary>Delegating</secondary>
   </indexterm>
   <step>
    <para>Select Entitlements &gt; Delegations &gt; Create Delegations to
    start the new entitlement delegation wizard.</para>
   </step>
   <step>
    <para>Give you delegation a name and a description, and then click
    Next.</para>
   </step>
   <step>
    <para>Select the application types to delegate, and then click Next.</para>
    <para>You can click Show for each selected application type to further
    refine the resources for which you are delegating management.</para>
   </step>
   <step>
    <para>Select subjects to whom the delegation grants access to manage, and
    then click Next.</para>
   </step>
   <step>
    <para>Select the level of management delegated in terms of actions the
    subject can perform, and then click Next.</para>
   </step>
   <step>
    <para>Review the delegation configuration summary, and then click Finish to
    create and store the delegation in OpenAM.</para>
   </step>
  </procedure>
 </section>
 
 <section xml:id="managing-entitlements-cli">
  <title>Managing Entitlements on the Command Line</title>
  <indexterm>
   <primary>Authorization</primary>
   <secondary>Configuring</secondary>
  </indexterm>
  <indexterm>
   <primary>Entitlements</primary>
   <secondary>Configuring</secondary>
  </indexterm>
  <indexterm>
   <primary>Policy</primary>
   <secondary>Configuring</secondary>
  </indexterm>
  <para>To manage entitlements, you can use the <command>ssoadm</command>
  command. The <command>ssoadm</command> command provides several other
  subcommands for managing entitlements in addition to those shown here.</para>
  
  <procedure xml:id="export-entitlements-policy-cli">
   <title>To Export Policies</title>
   
   <step>
    <para>Use the <command>ssoadm list-xacml</command> command to export
    policies.</para>
    <screen>$ ssoadm list-xacml --realm / --adminid amadmin --password-file /tmp/pwd.txt

&lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?&gt;
&lt;PolicySet PolicyCombiningAlgId="urn:oasis:names:tc:xacml:3.0:
 rule-combining-algorithm:deny-overrides" Version="2011.10.07.12.22.04.705"
 PolicySetId="/:2011.10.07.12.22.04.704" xmlns="urn:oasis:names:tc:xacml:3.0:
 core:schema:cd-1"&gt;
    &lt;Target/&gt;
... other policies ...
    &lt;Policy RuleCombiningAlgId="urn:oasis:names:tc:xacml:3.0:
 rule-combining-algorithm:deny-overrides" Version="2011.10.07.11.51.27.444"
 PolicyId="New Policy"&gt;
... policy content here ...
    &lt;/Policy&gt;
&lt;/PolicySet&gt;</screen>
   </step>
  </procedure>
  
  <procedure xml:id="import-entitlements-policy-cli">
   <title>To Import an Entitlements Policy</title>
   
   <step>
    <para>Use the <command>ssoadm create-xacml</command> command to import
    a policy.</para>
    <screen>$ ssoadm
 create-xacml
 --realm /
 --xmlfile policy.xml
 --adminid amadmin
 --password-file /tmp/pwd.txt</screen>
   </step>
  </procedure>
  
  <procedure xml:id="create-entitlements-application-cli">
   <title>To Create an Application</title>
   
   <step>
    <para>Use the <command>ssoadm create-appl</command> command to create an
    application type.</para>
    <screen>$ cat application.txt
resources=http://myapp.example.com:80/*
subjects=com.sun.identity.admin.model.IdRepoUserViewSubject
subjects=com.sun.identity.admin.model.VirtualViewSubject
subjects=com.sun.identity.admin.model.OrViewSubject
subjects=com.sun.identity.admin.model.AndViewSubject
conditions=com.sun.identity.admin.model.DateRangeCondition
conditions=com.sun.identity.admin.model.DaysOfWeekCondition
conditions=com.sun.identity.admin.model.IpRangeViewCondition
conditions=com.sun.identity.admin.model.DnsNameViewCondition
conditions=com.sun.identity.admin.model.TimeRangeCondition
conditions=com.sun.identity.admin.model.TimezoneCondition
conditions=com.sun.identity.admin.model.OrViewCondition
conditions=com.sun.identity.admin.model.AndViewCondition
conditions=com.sun.identity.admin.model.NotViewCondition
entitlementCombiner=com.sun.identity.entitlement.DenyOverride
$ ssoadm
 create-appl
 --realm /
 --applicationtype iPlanetAMWebAgentService
 --name myApp
 --adminid amadmin
 --password-file /tmp/pwd.txt
 --datafile application.txt

myApp was created.</screen>
   </step>
  </procedure>
 </section>
</chapter>

