<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: agamgupta6</title>
    <description>The latest articles on DEV Community by agamgupta6 (@agamgupta6).</description>
    <link>https://dev.to/agamgupta6</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F284164%2F681a844c-4d1c-4efe-94bc-c3c6876e664f.png</url>
      <title>DEV Community: agamgupta6</title>
      <link>https://dev.to/agamgupta6</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/agamgupta6"/>
    <language>en</language>
    <item>
      <title>XACML with WSO2 Identity Server</title>
      <dc:creator>agamgupta6</dc:creator>
      <pubDate>Sun, 27 Sep 2020 03:10:14 +0000</pubDate>
      <link>https://dev.to/agamgupta6/xacml-with-wso2-identity-server-1lb1</link>
      <guid>https://dev.to/agamgupta6/xacml-with-wso2-identity-server-1lb1</guid>
      <description>&lt;h1&gt;
  
  
  XACML with WSO2 Identity Server
&lt;/h1&gt;

&lt;p&gt;Photo by Martin Olsen on Unsplash&lt;/p&gt;

&lt;h3&gt;
  
  
  What is XACML?
&lt;/h3&gt;

&lt;p&gt;According to Wikipedia, “XACML stands for “eXtensible Access Control Markup Language”. The standard defines a declarative fine-grained, attribute-based access control policy language, an architecture, and a processing model describing how to evaluate access requests according to the rules defined in policies.”&lt;/p&gt;

&lt;p&gt;The definition is pretty much clear. We are not going to discuss about the architecture and terminology in this post. If you want to understand the architecture of XACML in more detail, there are already plenty of great articles on INTERNET. I will provide the list of few at the end of this post. &lt;br&gt;
 In this post we will see how we can create a sample XACML policy and use it in applications to achieve fine-grained access control. Also, I am going to demonstrate how WSO2IS has made it extremely simple to define and manage XACML policies and has an extremely fast XACML engine to evaluate the XACML policies against XACML requests. So let’s get started.&lt;/p&gt;

&lt;h3&gt;
  
  
  Create a simple XACML policy
&lt;/h3&gt;

&lt;p&gt;First thing first, we have to define an XACML policy. XACML policies are defined in XML. But no one wants to write complicated XML. WSO2IS to the rescue. If you do not know about WSO2IS, read it &lt;a href="https://wso2.com/identity-and-access-management/"&gt;here&lt;/a&gt;. So before we continue, make sure you have downloaded the latest version of WSO2IS (it is free!!) from the official website and it is up and running. Open the management console (&lt;a href="https://localhost:9443/carbon/admin/login.jsp"&gt;https://localhost:9443/carbon/admin/login.jsp&lt;/a&gt;) and login with default admin user (admin:admin).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--N53WSfn5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2672/1%2AguBEOKKczwk3lufjlc0aJQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--N53WSfn5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2672/1%2AguBEOKKczwk3lufjlc0aJQ.png" alt="Admin Console of WSO2IS"&gt;&lt;/a&gt;&lt;em&gt;Admin Console of WSO2IS&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Click on “Policy Administration” in the left menu under “Entitlement”. Here you can see that WSO2IS has already defined several predefined XACML policy templates to help us. Good job WSO2IS team. For now we will focus on creating a new policy.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--AuXnfRB1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2362/1%2Aoi8sCaiJoxfpC0mt00H0AA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--AuXnfRB1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2362/1%2Aoi8sCaiJoxfpC0mt00H0AA.png" alt="Policy templates provided by WSO2IS"&gt;&lt;/a&gt;&lt;em&gt;Policy templates provided by WSO2IS&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;To define a new policy, click on “Add New Entitlement Policy” and choose one of the GUI editor provided by WSO2 to create a new policy. Lets, try “Simple Policy Editor”. Click on it, and let us move to the next section.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_x7l-25R--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2264/1%2Ar80vn8Skk3moAWW36w7WHQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_x7l-25R--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2264/1%2Ar80vn8Skk3moAWW36w7WHQ.png" alt="Policy Editors in WSO2IS"&gt;&lt;/a&gt;&lt;em&gt;Policy Editors in WSO2IS&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Scenario
&lt;/h3&gt;

&lt;p&gt;Let us consider a very basic scenario where we want to protect an URL “/api/users/” that we will refer as &lt;strong&gt;resource&lt;/strong&gt;. We want that only users having role “admin” can make a POST request to this URL. We will refer this POST request as &lt;strong&gt;action&lt;/strong&gt;. All other roles must be denied to make POST request to this resource.&lt;/p&gt;

&lt;p&gt;Enter following details in the screen and click Finish.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--QSpyN2Yw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AuDfB3W8gyIC268z2-Lqr-Q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--QSpyN2Yw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AuDfB3W8gyIC268z2-Lqr-Q.png" alt="Simple Policy Editor"&gt;&lt;/a&gt;&lt;em&gt;Simple Policy Editor&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Congratulations! you have created your first XACML policy without even writing a single line of XML, all from a simple UI.&lt;/p&gt;

&lt;h3&gt;
  
  
  Understand the generated XML
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--kBBHz00g--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2492/1%2Axtc7sxnqQ_y3itlHiioJzQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--kBBHz00g--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2492/1%2Axtc7sxnqQ_y3itlHiioJzQ.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Click on the newly created policy to see the policy definition in XML. The XML has two main sections, Target and Rule. The “Target” part as highlighted in the above image defines the condition for which this policy will be evaluated. In our case, the XACML request must have a parameter “resource-id” with value “/api/users/”. If the this condition is not satisfied, the policy engine will not consider this policy to evaluate when it will receive the XACML request. This is great, because it will help the policy engine to response fast as it will not evaluate each and every policy defined in the policy engine. &lt;/p&gt;

&lt;p&gt;The next part is “Rule”. In this part we can define multiple rules. Each “Rule” has its own “Target” and “Condition”. In our case, we have created a rule that will be evaluated if the XACML request will have parameter “action-id” with value “post”. And this rule will return **true **when XACML request will have parameter role with value “admin”. &lt;/p&gt;

&lt;p&gt;That is enough for now to understand the XML structure of the policy. Let us continue and see how we can make use of this policy.&lt;/p&gt;

&lt;h3&gt;
  
  
  Publish the policy
&lt;/h3&gt;

&lt;p&gt;So far we have successfully created a policy, but it is not ready to use. For that, we have to publish the policy to PDP (Policy Decision Point). Follow the below steps to do that:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Xl2xEaDh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2012/1%2AqgKXlwMhmQ7llaKOEFK8og.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Xl2xEaDh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2012/1%2AqgKXlwMhmQ7llaKOEFK8og.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--YSc2iiYi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2156/1%2AMMg3-yqNi4JdZtYU5lIn9g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YSc2iiYi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2156/1%2AMMg3-yqNi4JdZtYU5lIn9g.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--zlepPCmo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2A8m9k6sDikWsBmkUEpxfeRA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--zlepPCmo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2A8m9k6sDikWsBmkUEpxfeRA.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Evaluating the policy
&lt;/h3&gt;

&lt;p&gt;WSO2IS allows us to send the XACML request as JSON or XML. Let us create a JSON request. We will use Postman to send XACML request to PEP (Policy Enforcement Point). Enter following details in Postman:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;URL:&lt;/strong&gt; &lt;a href="https://localhost:9443/api/identity/entitlement/decision/pdp"&gt;https://localhost:9443/api/identity/entitlement/decision/pdp&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;Body: *&lt;/em&gt;{“Request”: {“AccessSubject”: {“Attribute”: [{“AttributeId”: “&lt;a href="http://wso2.org/claims/role"&gt;http://wso2.org/claims/role&lt;/a&gt;","Value": “user”,”DataType”: “string”,”IncludeInResult”: false}]},”Resource”: {“Attribute”: [{“AttributeId”: “resource-id”,”Value”: “/api/users1/”,”DataType”: “string”,”IncludeInResult”: false}]},”Action”: {“Attribute”: [{“AttributeId”: “action-id”,”Value”: “post”,”DataType”: “string”,”IncludeInResult”: false}]}}}&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Authorization:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--TVd6bC8O--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2ACdcvf_R9nQFXyAUjqBXSyA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--TVd6bC8O--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2ACdcvf_R9nQFXyAUjqBXSyA.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ixsCo_iX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2186/1%2AeuBgCkKc8hHtD-uncwjhxA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ixsCo_iX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2186/1%2AeuBgCkKc8hHtD-uncwjhxA.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Pay attention to the highlighted parts.&lt;/p&gt;

&lt;p&gt;In the above request, we are sending the information about the &lt;strong&gt;Resource&lt;/strong&gt;, **Action **and a attribute of **Subject **i.e. Role. If you remember, we used these three parameters to define our XACML policy. Let’s send the request and analyze the response.&lt;/p&gt;

&lt;p&gt;We have received the following response:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Ra70uOvS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2196/1%2ALew5JBbPCCbSvrENhs4M4A.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Ra70uOvS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2196/1%2ALew5JBbPCCbSvrENhs4M4A.png" alt="Postman Response Not Applicable"&gt;&lt;/a&gt;&lt;em&gt;Postman Response Not Applicable&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Notice the “Decision” parameter. We have received “NotApplicable” because we sent “/api/users1/” (check the Body) and our request is not matching with “Target” of any published policy. Let us change the value of resource to “/api/users/” and send the request again. This time we have received following response:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--2Dkr8SxE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AYY3f6fCv12KPr74_ybb-6w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--2Dkr8SxE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AYY3f6fCv12KPr74_ybb-6w.png" alt="Request Denied"&gt;&lt;/a&gt;&lt;em&gt;Request Denied&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;This time we have received the Decision as “Deny”. This is because we have sent “user” (check the Body) as role, and the Rule in the XACML policy is expecting “admin”. So this user with role “user” is denied to make POST request to resource “/api/users/”. Let’s change the role to “admin” and send the request again. Now we have following response:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--lvZEErnC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AWZ0L-07cFLaSLrSoqHkFnw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--lvZEErnC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AWZ0L-07cFLaSLrSoqHkFnw.png" alt="Request Permitted"&gt;&lt;/a&gt;&lt;em&gt;Request Permitted&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Tada! We have received “Permit”. It means, the request has fulfilled all conditions in the policy and we can allow this request in the our application. Now when we know how easy it is to define and evaluate the XACML policies in WSO2IS, let’s discuss about some use cases.&lt;/p&gt;

&lt;h3&gt;
  
  
  Use Cases
&lt;/h3&gt;

&lt;p&gt;Here are few use cases of XACML policies.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Use XACML as ABAC (Attribute Based Access Control) in any application irrespective of technology. For example, you can create a filter in your spring boot application that will invoke PEP every time when it receives the request. Thinking about extra network call for each request? Well, you do not need to protect each and every resource. For example, anyone can see the list of users (GET) but only “admin” can make the update (POST) request. So no need to invoke the policy engine for GET requests. This will avoid unnecessary network calls.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Use XACML in the authentication flow of WSO2IS to restrict the user based on attribute, role, time etc. For example, in WSO2IS you can use XACML policy to restrict users to take login in the application on weekend. Cool.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Enable guest accounts, for more details refer this: &lt;a href="https://medium.com/identity-beyond-borders/how-to-enable-guest-accounts-in-wso2-identity-server-af17b2ca7b2c"&gt;https://medium.com/identity-beyond-borders/how-to-enable-guest-accounts-in-wso2-identity-server-af17b2ca7b2c&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Performance
&lt;/h3&gt;

&lt;p&gt;There is a nice article from WSO2 team that explains how the performance can be improved with help of cache: &lt;a href="https://is.docs.wso2.com/en/latest/learn/improving-xacml-pdp-performance-with-caching-techniques/"&gt;https://is.docs.wso2.com/en/latest/learn/improving-xacml-pdp-performance-with-caching-techniques/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Another article discuss about the performance test done by WSO2 team: &lt;a href="https://docs.wso2.com/display/IS570/XACML+Performance+in+the+Identity+Server"&gt;https://docs.wso2.com/display/IS570/XACML+Performance+in+the+Identity+Server&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Architecture,Pros n cons
&lt;/h3&gt;

&lt;p&gt;There is a nice article about this.&lt;br&gt;
&lt;a href="https://medium.com/@yvonne.wicks/merry-xacml-and-happy-access-control-1add93c2a23a"&gt;&lt;strong&gt;Merry XACML and Happy Access Control!&lt;/strong&gt;&lt;br&gt;
*I know it’s a bit late for this, but It’s better late than never! :D*medium.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the next post, we will create some more advance XACML policies and will see some advanced use cases. We will also integrate the XACML with Spring Boot.&lt;/p&gt;

&lt;p&gt;I will be writing more on XACML, WSO2IS, Angular, Spring Boot, AZURE, AWS etc. Do leave your feedback in the comments. If you liked this post, click on claps and follow me to see more stuff on above mentioned topics.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Stay Home, Stay Safe.&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>xacml</category>
      <category>wso2</category>
      <category>rbac</category>
      <category>abac</category>
    </item>
  </channel>
</rss>
