Enforcing Authentication and Authorization on a JAX-WS web service using Picketlink

Introduction

The following article describes how to enforce authentication with SAML and authorization with XACML on a JAX-WS Web Service on JBoss Enterprise Application Platform with Picketlink. I combined several articles listed in the References section to make this one demonstration. The source code is on github.

Note: Future updates will the latest versions of EAP/Picketlink/Fuse and moving the projects to maven.

Server Project
Contains the Web Service to take the assertion out of the wsse, validate it, verify authorization and process the request. The files contained in the project are the SAML2ServerHandler.java, WSTest.java, WSTestBean.java, jboss.xml, jbossxacml-config.xml,standard-jaxws-endpoint-config.xml,xacml-policy.xml,sts-config.properties,sts-roles.properties,sts-security-domain-jboss-beans.xml,sts-users.properties. All the XML is displayed to the console.

Client Project
Contains the Client to get an assertion from the STS, add it to the wsse in the SOAP header and call the test web service. The files contained in the project are the STSWSClient.java, SAML2ClientHandler.java and standard-jaxws-client-config.xml. All the XML is displayed to the console.

Architecture Overview

Web Service (Server Side)

In our sample we created a simple EJB3 stateless session bean called WSTest. The implementation class in our sample is WSTestBean.

The session requires authentication using the sts security domain and just prints whatever string the client sent and also the Principal on the server side. The security domain is within the deployment for authentication and authorization. The application-policy defines two (SAML2STSLoginModule and UsersRolesLoginModules) login modules and one (XACMLAuthorizationModule) authorization module. The former will be responsible for validating the assertion with the STS in order to authenticate the client and the latter is responsible for adding roles.

To validate the SAML assertions the login module needs information about the STS like its endpoint URL, service, etc. Setup the sts-config property file. The last two properties specify the username and password that will be used to authenticate the JBoss server to the STS when the WS-Trust validate message is dispatched. In other words, SAML2STSLoginModule needs to authenticate to the STS when validating the SAML assertions and these properties specify the username and password that will be
used for that.

The deployment wstest.jar also contains the files to map roles to the Subject. The file sts-users.properties is just an empty file as authentication is handled by PicketLink’s login module. sts-roles.properties contains the sts roles.

The endpoint definition is included in the /META-INF/standard-jaxws-endpoint-config.xml. This will contain the jax-ws handler class, webservice.jaxws.server.handler.SAML2ServerHandler, which contains the handleMessage method.

The jbossxacml-config.xml file contains the policy locators and policy location. In our example we used JBossPolicySetLocator and JBossPolicyLocator. We put our XACML policy in xacml-policy.xml. The authorization module acts as a Policy Enforcement Point (PEP) to setup the XACML request to send to the Policy Decision Point (PDP) for evaluation.

STS (Server Side)

The STS has a new security domain for the STS in the jboss-web.xml, includes an application policy for the new domain that uses the UsersRolesLoginModule to authenticate STS clients, includes the users and roles properties files, and the required role in web.xml to STSClient.

The STS accept only stsclient roles which is in the web.xml. In the jboss-web.xml the application domain should point to the sts-users and roles properties files located within the login-config.xml. Notice that the JBoss user represents the JBoss server during the SAML validation process. All other users are the clients of the WS sample application – they send a message to the STS to acquire a SAML assertion before calling the methods on the WS application. JBoss and UserA from our sample are both STSClient roles.

Web Service (Client Side)

The STSWSClient acquires a SAML assertion from the PicketLink STS and invokes the echo method of the WS.

The assertion is first obtained using the WSTrustClient API. Notice the client then adds the SAML assertion in the SAML2Constants.SAML2_ASSERTION_PROPERTY
(“org.picketlink.trust.saml.assertion”) property in the request context before invoking the echo method. The client also uses a custom endpoint configuration (SAML WSSecurity Client) that must be included in the client’s META-INF/standard-jaxws-client-config.xml. The SAML2ClientHandler defined in the client config inserts the assertion into the WSSE in the SOAP Header.

To run the project the classpath should contain the classes similar to below if run from command line (this is for EAP 5.0) or similar to the ones in the project if running the project from JBDS 6 with EAP 5.2.

Share this:

Like this:

In your sample, on the server side, you perform authentication and authorization both at the jax-ws handler level (in your SAML2ClientHandler you create a security context from the assertion propagated in SOAP Security header) and the loginmodule level (by mean of SAML2STSLoginModule and UsersRolesLoginModule. Why do you need both ? The handlers chain should be sufficient. You also add the SAML assertion in a request context property on the client side (probably because SAML2STSLoginModule needs this on serverside). By doing so, SAML assertion is propagated both on request and on SOAP message : jax-ws handler should be sufficient.

They are selling new technology from leading networking equipment companies that enable homeowners to wirelessly connect their Personal Computers to their
Home Entertainment centers. Your modem will also
likely be connected to a wireless router and it is this that allows
your laptops, tablets, e-readers, smartphones and other wireless enabled
devices to be connected to the internet via your home broadband connection.
This is a bit much for a service you aren”t aware will work or not.

You actually make it appear really easy together with your presentation
however I in finding this matter to be actually something that I feel I would never understand.
It kind of feels too complicated and very broad for me. I’m having a look ahead in your next post, I will try to get the hang of it!