As you all know The WSO2 Identity Server provides entitlement
management by XACML fine-grained policy based access control. In this post I will introduce a Proxy Components for use this functionality in JAVA applications. This will make the users life easy in following ways,
Here XACML PEP can be any JAVA application. I have given a example application in my previous blog posts, http://www.insightforfuture.blogspot.com/2012/07/providing-xacml-fine-grained.html and http://www.insightforfuture.blogspot.com/2012/07/providing-xacml-fine-grained_22.html. In that I have described a Servlet Filter which uses this PEP proxy for give authorization to webapps.
The following list will show the API methods given in PEP Proxy,
Following JAVA class will give a example to use PEP Proxy. I used a Sample XACML policy hosted in WSO IS. That policy is given below Also,
JAVA Class :
- User have to invoke a method in the proxy to get a entitlement decision.
- User don't have to implement XACML request related things to use a XACML policy hosted in IS. The proxy hides those complexity from user.
- Entitlement requests can be sent either using XACML 3.0 or XACML 2.0.
- The proxy provides list of methods which will most of the authorization request scenarios which a user can have.
- User can use SOAP, Thrift or JSON to PDP PEP communication. User doesn't have to worry about the communication implementation.
- Several PEPs can use same Proxy to communicate with several PDPs(WSO2 IS instances) at the same time.
Here XACML PEP can be any JAVA application. I have given a example application in my previous blog posts, http://www.insightforfuture.blogspot.com/2012/07/providing-xacml-fine-grained.html and http://www.insightforfuture.blogspot.com/2012/07/providing-xacml-fine-grained_22.html. In that I have described a Servlet Filter which uses this PEP proxy for give authorization to webapps.
The following list will show the API methods given in PEP Proxy,
- String getDecision(Attribute[] attributes)
- String getDecision(Attribute[] attributes, String appId)
- String getDecision(String subject, String resource, String action, String environment)
- String getDecision(String subject, String resource, String action, String environment, String appId)
- boolean subjectCanActOnResource(String subjectType, String alias, String actionId,
String resourceId, String domainId) - boolean subjectCanActOnResource(String subjectType, String alias, String actionId,
String resourceId, String domainId, String appId) - boolean subjectCanActOnResource(String subjectType, String alias, String actionId,
String resourceId, Attribute[] attributes, String domainId) - boolean subjectCanActOnResource(String subjectType, String alias, String actionId,
String resourceId, Attribute[] attributes, String domainId, String appId) - List<String> getActionableChidResourcesForAlias(String alias, String parentResource,
String action) - List<String> getActionableChidResourcesForAlias(String alias, String parentResource,
String action, String appId) - List<String> getResourcesForAlias(String alias)
- List<String> getResourcesForAlias(String alias, String appId)
- List<String> getActionableResourcesForAlias(String alias)
- List<String> getActionableResourcesForAlias(String alias, String appId)
- List<String> getActionsForResource(String alias, String resources)
- List<String> getActionsForResource(String alias, String resources, String appId)
Following JAVA class will give a example to use PEP Proxy. I used a Sample XACML policy hosted in WSO IS. That policy is given below Also,
JAVA Class :
package org.wso2.carbon.identity.entitlement.proxy; import java.util.HashMap; import java.util.Map; public class Test { public static void main(String arg[]) throws Exception { PEPProxy pepProxy; //Initializing the PEP Proxy System.setProperty("javax.net.ssl.trustStore", "wso2carbon.jks"); System.setProperty("javax.net.ssl.trustStorePassword", "wso2carbon"); Map<String,Map<String,String>> appToPDPClientConfigMap = new HashMap<String, Map<String,String>>(); //Configuration to Initialize SOAP Client Map<String,String> clientConfigMapSOAP = new HashMap<String, String>(); clientConfigMapSOAP.put("client", "soap"); clientConfigMapSOAP.put("serverUrl", "https://localhost:9443/services"); clientConfigMapSOAP.put("userName", "admin"); clientConfigMapSOAP.put("password", "admin"); clientConfigMapSOAP.put("reuseSession", "false"); appToPDPClientConfigMap.put("SOAP_APP", clientConfigMapSOAP); //Configuration to Initialize Basic Authentication Client Map<String,String> clientConfigMapBasicAuth = new HashMap<String, String>(); clientConfigMapBasicAuth.put("client", "basicAuth"); clientConfigMapBasicAuth.put("serverUrl", "https://localhost:9443/services"); clientConfigMapBasicAuth.put("userName", "admin"); clientConfigMapBasicAuth.put("password", "admin"); appToPDPClientConfigMap.put("BasicAuth_APP", clientConfigMapBasicAuth); //Configuration to Initialize Thrift Client Map<String,String> clientConfigMapThrift = new HashMap<String, String>(); clientConfigMapThrift.put("client", "soap"); clientConfigMapThrift.put("serverUrl", "https://localhost:9443/services"); clientConfigMapThrift.put("userName", "admin"); clientConfigMapThrift.put("password", "admin"); clientConfigMapThrift.put("reuseSession", "false"); clientConfigMapThrift.put("thriftHost", "localhost"); clientConfigMapThrift.put("thriftPort", "10500"); appToPDPClientConfigMap.put("Thrift_App", clientConfigMapThrift); PEPProxyConfig config = new PEPProxyConfig(appToPDPClientConfigMap,"SOAP_APP", "Simple", 10000, 100); pepProxy = new PEPProxy(config); String result = pepProxy.getDecision("admin", "/Entitlement_Sample_WebApp/protected.jsp", "GET", ""); System.out.println(result); result = pepProxy.getDecision("admin", "/Entitlement_Sample_WebApp/protected.jsp", "GET", "", "BasicAuth_APP"); System.out.println(result); result = pepProxy.getDecision("admin", "/Entitlement_Sample_WebApp/protected.jsp", "GET", "", "Thrift_App"); System.out.println(result); boolean bResult = pepProxy.subjectCanActOnResource("urn:oasis:names:tc:xacml:1.0:subject:subject-id", "admin", "GET", "/Entitlement_Sample_WebApp/protected.jsp", ""); System.out.println(bResult); } }Samples XACML Policy :
<Policy xmlns="urn:oasis:names:tc:xacml:3.0:core:schema:wd-17" PolicyId="Entitlement_Filter_Sample_Policy" RuleCombiningAlgId="urn:oasis:names:tc:xacml:1.0:rule-combining-algorithm:first-applicable" Version="1.0"> <Target></Target> <Rule Effect="Permit" RuleId="Rule1"> <Target> <AnyOf> <AllOf> <Match MatchId="urn:oasis:names:tc:xacml:1.0:function:string-equal"> <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">/Entitlement_Sample_WebApp/protected.jsp</AttributeValue> <AttributeDesignator AttributeId="urn:oasis:names:tc:xacml:1.0:resource:resource-id" Category="urn:oasis:names:tc:xacml:3.0:attribute-category:resource" DataType="http://www.w3.org/2001/XMLSchema#string" MustBePresent="true"></AttributeDesignator> </Match> <Match MatchId="urn:oasis:names:tc:xacml:1.0:function:string-equal"> <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">GET</AttributeValue> <AttributeDesignator AttributeId="urn:oasis:names:tc:xacml:1.0:action:action-id" Category="urn:oasis:names:tc:xacml:3.0:attribute-category:action" DataType="http://www.w3.org/2001/XMLSchema#string" MustBePresent="true"></AttributeDesignator> </Match> <Match MatchId="urn:oasis:names:tc:xacml:1.0:function:string-equal"> <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">admin</AttributeValue> <AttributeDesignator AttributeId="urn:oasis:names:tc:xacml:1.0:subject:subject-id" Category="urn:oasis:names:tc:xacml:1.0:subject-category:access-subject" DataType="http://www.w3.org/2001/XMLSchema#string" MustBePresent="true"></AttributeDesignator> </Match> </AllOf> </AnyOf> </Target> </Rule> </Policy>To test the PEP Proxy, You can do following steps,
- Run a WSO2 IS Server
- Host the given sample policy
- Run this Java Class with the dependency jar of PEPProxy. You can get that by building the source given below. That will give you the latest jar of PEPProxy. What you have to do is run mvn clean install in the source folder.
- http://wso2.com/products/identity-server/
- http://xacmlinfo.com/
- http://xacmlinfo.com/2012/06/13/pdp-pep-communication-wso2is/
- http://xacmlinfo.com/2012/06/14/pep-client-for-wso2is-pdp/
- http://srinathsview.blogspot.com/2012/05/authentication-and-authorization.html
- http://www.insightforfuture.blogspot.com/2012/07/providing-xacml-fine-grained.html
- http://www.insightforfuture.blogspot.com/2012/07/providing-xacml-fine-grained_22.html