The problem in most security schemes is that it will not give you the ability to fine grain your authorization scheme unless a substantial amount of work goes into implementing such a scheme from scratch. The WSO2 product platform relieves this burden off the system architect and allows you to integrate XACML based authorization into a deployment and have a full blown authorization scheme in place with minimum effort.
| WSO2 Identity Server | Version 3.0.0 and above |
| WSO2 ESB | Version 3.0.0 and above |
In this scheme for authorization we will be using the Identity Server (IS) as the PDP and the ESB as the PEP. Any request that comes in to the ESB will be checked for necessary authorization by generating a XACML request and sending it to IS. IS will then validate that request against the XACML policy and inform the ESB whether to allow or deny access to the request. The ESB will then act accordingly to deny or allow access to the request.

XACML expertise would be needed in defining a proper policy to accommodate complex requirements. Since this is an authorization checkpoint, extensive testing should be carried out to ensure the accuracy of the policy after a modification.
The request will be authorized according to the roles and groups set up in the IS. Therefore, if the XACML policy states that admin users have access to resource X. Then all users who need access to resource X must have user accounts belonging to the 'admin' role in the IS.
In this pattern, the guide explains first how to set up roles and groups in the Identity server according to authorization requirements, setup the Identity server with the XACML policy, the Entitlement mediator in the ESB and then set up the Entitlement Proxy Service. A sample Java client will be used to test this pattern. The communication between the IS and the ESB will be thorough HTTPS.
The following sections will explain each of these steps:
The WSO2 Identity Server and the WSO2 ESB both use the ports 9763 (http) and 9443 (https) by default. Therefore, we will change the ports used by the WSO2 Identity Server to 9765 (http) and 9763 (https). For this, please replace the mgt-transport.xml located at $IDENTITY_SERVER_HOME/repository/conf with the one provided here - wso2.org/files/mgt-transports.xml. Then start up both servers by going to the respective bin directories of each server and run the wso2server.sh (*nix) or wso2server.bat (Windows) to start the servers.
Setting up roles and groups is a simple process in the IS. But it is an important process as it determines which users get authorization to access which resource and so forth. Let us create a new role and add users into it as well as add users to an existing role.
In the next sections a XACML policy defined to give access to any user in an admin role is setup in the Identity Server.
<Request xmlns="urn:oasis:names:tc:xacml:2.0:context:schema:os" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Subject>
<Attribute AttributeId="urn:oasis:names:tc:xacml:1.0:subject:subject-id"
DataType="http://www.w3.org/2001/XMLSchema#string">
<AttributeValue>admin</AttributeValue>
</Attribute>
<Attribute AttributeId="group"
DataType="http://www.w3.org/2001/XMLSchema#string">
<AttributeValue>admin</AttributeValue>
</Attribute>
</Subject>
<Resource>
<Attribute AttributeId="urn:oasis:names:tc:xacml:1.0:resource:resource-id" DataType="http://www.w3.org/2001/XMLSchema#string">
<AttributeValue>http://localhost:8280/services/echo/echoString</AttributeValue>
</Attribute>
</Resource>
<Action>
<Attribute AttributeId="urn:oasis:names:tc:xacml:1.0:action:action-id" DataType="http://www.w3.org/2001/XMLSchema#string">
<AttributeValue>read</AttributeValue>
</Attribute>
</Action>
<Environment/>
</Request>
This request means that the 'admin' user from the user group is trying to access the http://localhost:8280/services/echo web service. This will result in a Permit/Deny/Not Applicable output. In this case, it will be permitted.
The Header mediator is configured to remove the Security header.
Click on the namespaceas and enter prefix as “wsse” and URI as “http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd”.
The in sequence is now completed with all the necessary mediators.
Enable Security in the drop down menu by setting option Yes. Click on Option 1: username token and click Next.
Give access to all roles. This further demonstrates that although any user will be able to access the proxy service, they will not be allowed to access the echo service due to the XACML based authorization that takes place.
This concludes all the steps necessary to setup XACML based authorization on the WSO2 platform.
The following client can be used to test the pattern for admin/admin credentials. The complete source package is attached to this article at http://wso2.org/files/WSEntitlementTestClient.zip. It can be opened up in an IDE and run against this setup without any modifications. Please add the jars in $ESB_HOME/repository/components/plugins to the classpath before running the project. NOTE: To test on any select users make sure the user exists on the ESB as well as on the IS. The roles that the user belongs to is evaluated according to the user data in the IS.
import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMFactory;
import org.apache.axiom.om.OMNamespace;
import org.apache.axiom.om.impl.builder.StAXOMBuilder;
import org.apache.axis2.Constants;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.client.ServiceClient;
import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.context.ConfigurationContextFactory;
import org.apache.neethi.Policy;
import org.apache.neethi.PolicyEngine;
import org.apache.rampart.RampartMessageData;
public class WSEntitlementTestClient {
final static String ADDR_URL = "http://localhost:8280/services/echo";
final static String TRANS_URL = "https://localhost:8243/services/EntitlementService";
public static void main(String[] args) throws Exception {
ServiceClient client = null;
Options options = null;
OMElement response = null;
ConfigurationContext context = null;
String trustStore = null;
// You need to import the ESBs public certificate to this key store.
trustStore = "wso2carbon.jks";
// We are accessing ESB over HTTPS - so need to set trustStore parameters.
System.setProperty("javax.net.ssl.trustStore", trustStore);
// Password of mykeystore.jks
System.setProperty("javax.net.ssl.trustStorePassword", "wso2carbon");
// Create configuration context - you will have Rampart module engaged in the client.axis2.xml
context = ConfigurationContextFactory.createConfigurationContextFromFileSystem("repo","repo/conf/axis2_client.xml");
// This is the security policy of the proxy service applied UT.
StAXOMBuilder builder = new StAXOMBuilder("policy.xml");
Policy policy = PolicyEngine.getPolicy(builder.getDocumentElement());
client = new ServiceClient(context, null);
options = new Options();
options.setAction("urn:echoString");
// This is the addressing URL pointing to the echo service deployed in ESB
options.setTo(new EndpointReference(ADDR_URL));
// To the ESB, the proxy service
options.setUserName("admin");
options.setPassword("admin");
// TRANS_URL points to proxy service
options.setProperty(Constants.Configuration.TRANSPORT_URL, TRANS_URL);
options.setProperty(RampartMessageData.KEY_RAMPART_POLICY, policy);
client.setOptions(options);
client.engageModule("addressing");
client.engageModule("rampart");
response = client.sendReceive(getPayload("Hello world"));
System.out.println(response);
}
private static OMElement getPayload(String value) {
OMFactory factory = null;
OMNamespace ns = null;
OMElement elem = null;
OMElement childElem = null;
factory = OMAbstractFactory.getOMFactory();
ns = factory.createOMNamespace("http://echo.services.core.carbon.wso2.org", "ns1");
elem = factory.createOMElement("echoString", ns);
childElem = factory.createOMElement("in", null);
childElem.setText(value);
elem.addChild(childElem);
return elem;
}
}
XACML is an open standard that brings a powerful and extensible fine grained authorization model to a deployment's security framework. The sample policy demonstrated in this article barely scratches the surface of what's possible with XACML based security. But, just as we have secured a simple web service with a simple XACML policy, a system developer just needs to follow the same steps to enable XACML based security in a large, complex deployment with the WSO2 product stack.
Tharindu Mathew, Software Engineer, WSO2 Inc.
| Attachment | Size |
|---|---|
| sample-xacml-request.xml | 943 bytes |
| mgt-transports.xml | 3.81 KB |
| WSEntitlementTestClient.zip | 29.34 KB |
| sample-xacml-policy.xml | 1.99 KB |
problem in running sample code
Great work, man! I always
http://www.atcoachoutletsonli
Apply Fine-grained authorization to existing axis2 services
Missing wsse:Security header in request
ESB proxy service not secured
My usertoken security is working well but.. IS does not work.
Entitlement Service is secured
Echo Service