<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>Question Re: CAP: Instance-based Authorization based on user attribute in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/cap-instance-based-authorization-based-on-user-attribute/qaa-p/12731169#M4778055</link>
    <description>&lt;P&gt;Thank you Matthias! &lt;/P&gt;&lt;P&gt;The quotes did the trick.&lt;/P&gt;&lt;P&gt;Kind regards,&lt;BR /&gt;Philipp&lt;/P&gt;</description>
    <pubDate>Tue, 25 Jul 2023 12:48:06 GMT</pubDate>
    <dc:creator>former_member869401</dc:creator>
    <dc:date>2023-07-25T12:48:06Z</dc:date>
    <item>
      <title>CAP: Instance-based Authorization based on user attribute</title>
      <link>https://community.sap.com/t5/technology-q-a/cap-instance-based-authorization-based-on-user-attribute/qaq-p/12731167</link>
      <description>&lt;P&gt;Hello experts,&lt;/P&gt;
  &lt;P&gt;in the last days I tried to implement the instance-based authorization into our CAP application by following this Capire information: &lt;A href="https://cap.cloud.sap/docs/guides/authorization#instance-based-auth" target="_blank"&gt;Instance-Based Authorization&lt;/A&gt;&lt;/P&gt;
  &lt;P&gt;Our users have multiple attributes, by which the access is restricted.&lt;/P&gt;
  &lt;P&gt;Attributes defined in the xs-security.json file:&lt;/P&gt; 
  &lt;PRE&gt;&lt;CODE&gt;"attributes": [&lt;BR /&gt;    {&lt;BR /&gt;        "name": "Application",&lt;BR /&gt;        "description": "Application",&lt;BR /&gt;        "valueType": "string"&lt;BR /&gt;    },&lt;BR /&gt;    {&lt;BR /&gt;        "name": "CompanyCode",&lt;BR /&gt;        "description": "CompanyCode",&lt;BR /&gt;        "valueType": "string"&lt;BR /&gt;    },&lt;BR /&gt;    {&lt;BR /&gt;        "name": "RecordType",&lt;BR /&gt;        "description": "RecordType",&lt;BR /&gt;        "valueType": "string"&lt;BR /&gt;    }&lt;BR /&gt;]&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;Our entity is restricted as follows:&lt;/P&gt; 
  &lt;PRE&gt;&lt;CODE&gt;annotate srv.Application with @(restrict: [&lt;BR /&gt;    {&lt;BR /&gt;        grant: 'READ',&lt;BR /&gt;        to: ['Display'],&lt;BR /&gt;        where: 'application = $user.Application'&lt;BR /&gt;    }&lt;BR /&gt;]);&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;This restriction works fine. The users can only read the applications contained in the users Application attribute.&lt;/P&gt;
  &lt;P&gt;Now we have a new requirement: There should be a way for a user to be configured to get access to all applications. To do this, the Application attribute will get a special value (e.g. "ALL"). If a user has this value inside of their Application attribute, he should be able to see all applications.&lt;/P&gt;
  &lt;P&gt;To achieve this, we tried the following restriction:&lt;/P&gt; 
  &lt;PRE&gt;&lt;CODE&gt;annotate srv.Application with @(restrict: [&amp;lt;br&amp;gt;   {&amp;lt;br&amp;gt;       grant: 'READ',&amp;lt;br&amp;gt;       to: ['Display'],&amp;lt;br&amp;gt;       where: 'application = $user.Application or $user.Application = ALL'&amp;lt;br&amp;gt;   }&amp;lt;br&amp;gt;]);&amp;lt;br&amp;gt;&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;Unfortunatly, this did not work and produce the following error message upon reading the entity:&lt;/P&gt; 
  &lt;PRE&gt;&lt;CODE&gt;No CXN expression found for where condition 'application = $user.Application or $user.Application = ALL' used for instance-based authorization of entity 'srv.Application'&amp;lt;br&amp;gt;&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;We already looked at alternative ways of doing this:&lt;/P&gt;
  &lt;UL&gt; 
   &lt;LI&gt;Unrestricted user attributes: This is not suitable, because this way, every user who has not yet set their Application attribute would have access by default. We want to restrict access by default and explicitly allow the access via the ALL value&lt;/LI&gt; 
  &lt;/UL&gt;
  &lt;UL&gt; 
   &lt;LI&gt;Separate roles for unrestricted access, like an "ApplicationALL" role: This does also not seem suitable, since this would be required for every attribute (currently we are at 3, but there might be more in the future) and make the restrict annotations very clustered and hard to manage.&lt;/LI&gt; 
  &lt;/UL&gt;
  &lt;P&gt;Is there any way to achieve our goal using the posted restriction annotation? If not, what would be the best way to tackle this?&lt;/P&gt;
  &lt;P&gt;Thank you for your input.&lt;/P&gt;
  &lt;P&gt;Kind regards,&lt;BR /&gt;Philipp&lt;/P&gt;</description>
      <pubDate>Tue, 25 Jul 2023 08:39:40 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/cap-instance-based-authorization-based-on-user-attribute/qaq-p/12731167</guid>
      <dc:creator>former_member869401</dc:creator>
      <dc:date>2023-07-25T08:39:40Z</dc:date>
    </item>
    <item>
      <title>Re: CAP: Instance-based Authorization based on user attribute</title>
      <link>https://community.sap.com/t5/technology-q-a/cap-instance-based-authorization-based-on-user-attribute/qaa-p/12731168#M4778054</link>
      <description>&lt;P&gt;Constant values need quotes. Please retest with&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;[...]&lt;BR /&gt;where: 'application = $user.Application or $user.Application = `ALL`'&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 25 Jul 2023 11:13:44 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/cap-instance-based-authorization-based-on-user-attribute/qaa-p/12731168#M4778054</guid>
      <dc:creator>former_member227670</dc:creator>
      <dc:date>2023-07-25T11:13:44Z</dc:date>
    </item>
    <item>
      <title>Re: CAP: Instance-based Authorization based on user attribute</title>
      <link>https://community.sap.com/t5/technology-q-a/cap-instance-based-authorization-based-on-user-attribute/qaa-p/12731169#M4778055</link>
      <description>&lt;P&gt;Thank you Matthias! &lt;/P&gt;&lt;P&gt;The quotes did the trick.&lt;/P&gt;&lt;P&gt;Kind regards,&lt;BR /&gt;Philipp&lt;/P&gt;</description>
      <pubDate>Tue, 25 Jul 2023 12:48:06 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/cap-instance-based-authorization-based-on-user-attribute/qaa-p/12731169#M4778055</guid>
      <dc:creator>former_member869401</dc:creator>
      <dc:date>2023-07-25T12:48:06Z</dc:date>
    </item>
  </channel>
</rss>

