Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The service provider needs to advertise those requirements through a WS-Policy. So, the starting point of our use case scenario is to configure a policy in the web serviceWeb Service.

Then, we need to look into the token provider, WSO2 Identity Server. As I have explained before, WSO2 IS comes with a Security Token Service. We need to configure it to issue tokens to the provider web service Web Service and secure STS using a WS-Security policy because the consumers should authenticate themselves to the STS when requesting tokens.

Finally, we will write a client/consumer (or just use a service invocation tool such as soapUI) to request a security token from STS and append it to the actual web service Web Service request message to authenticate to the web service Web Service which is deployed in WSO2 Application Server.

The following are the steps to follow in order to use this feature:

Table of Contents
minLevel4

 

Step 1 - Secure Web Service with a Claim-aware Security Policy

  1. Start WSO2 Application Server and log in to the management console as a default admin user.
  2. Go to Manage > Services > Add > AAR Service.
  3. Deploy Axis2Service.aar which can be downloaded from here.
  4. Once the service is deployed, we need to associate a security policy for our service. You can find a set of default Web Service security policies in security configuration wizard. However, we you cannot use any of them for our scenario.

Our Web Service should be associated with a trust based security policy. A security token which is offered by STS represents a set of claims. A claim defines a specific information about a particular user. For example, first name or email address of the user.

In our example, Axis2Service (the Web Service deployed in service provider, WSO2 Application Server) needs to be made as a claim-aware Web Service. The users who consume the service need to present the claims defined in WS-Security policy.

...

  • The sp:IssuedToken element defines that the requester must talk to an STS to obtain the token.
  • The sp:IncludeToken attribute value is defined as ../AlwaysToRecipient, which says the token must be included as part of all messages sent from the initiator (service consumer) to the recipient.
  • The Address attribute of sp:Issuer element defines the token issuer whom the consumer must be contacted to get the security token. In other words, the endpoint address of the Security Token Service. In this scenario, it must be the STS URL of IS.

    Info

    This is while running WSO2 IS with port-offset 1, hence the https port is 9444.

  • The sp:RequestSecurityTokenTemplate element specifies the structure/type of the token which has to be issued by the STS. Later, you will observe the children of this element will be included as the part of RequestSecurityToken (RST) message which will be sent to the STS by consumer.
  • The t:TokenType element represents the type of the token such as UserNameToken, SAML-1.1, SAML-2.0. In our example, we ask STS To generate SAML-2.0 token by specifying SAML-2.0 token type URL.
  • t:KeyType represents the type of the key desired in security token, can be either public key, symmetric key or bearer. We will ask STS to generate the relatively simple key, bearer token. Bearer token does not require a proof of possession hence it is quite easy to dealt with.
  • t:Claims element defines the claims that must be included in the security token. We will request Request the First Name and email Email address claims from the consumer.

The First Name claim is mapped to the "http://wso2.org/claims/givenname" URI. We will be are able to clear ourselves once we configure the token provider in the next step.

OKWith this, now we understood should have an understanding of all elements of the SupportingToken assertion of our custom web service Web Service policy. Let's upload the policy to embedded the registry in WSO2 Application Service.

  1. Locate /_system/config collection in registry browser and click on Add Resource.
  2. Navigate to the axis2service.policy.xml which you have downloaded from the above location.
  3. Click Add. Now, we have our custom policy in WSO2 Application Server. We can associate the policy to Axis2Service.
  4. Click on the Unsecured link associated with Axis2Service in the Deployed Services page. You are directed to the Security for the service page. 
  5. Navigate to the Policy From Registry section which can be found at the bottom of the page. 
  6. Click on the Configuration Registry icon and select the axis2service.policy.xml from the /_system/config collection.
  7. Click on Next to proceed with the wizard. You are directed to the Activate Security page where you can specify a trusted key store for the Web Service.
  8. Select wso2carbon.jks as the trusted key store. 
  9. As discussed, STS is responsible for issuing tokens. Therefore, the STS is trusted by both the consumer as well as the service provider. In order to do sothis, the public key certificate of STS should be imported to the trusted key store defined here. We do not explicitly do key exchanges in this example because as we are using the same wso2carbon.jks keystore in both WSO2 Application Server and WSO2 Identity Server.

...

  1. Start WSO2 Identity Server and log in to the management console using the default admin credentials.
  2. Select Secure Token Service from the left menu under the Manage section.
  3. First, we should secure the STS. There are multiple ways to authenticate using the Secure Token Service. The consumer can just present his username and password as UserNameTokens or X509 certificates to the STS. In this example, we will configure the STS using UserNameToken Authentication authentication policy so that the clients should talk to can communicate with STS by presenting their credentials.
  4. Click on Apply Security Policy in the above screen.
  5. Select UsernameToken from the list of default security policies in the Security for the service page.
  6. Click on Next. Now, we need to select a user group to which the service consumer belongs. We will incorporate our consumer into the admin group and request tokens from STS by presenting the default admin user credentials.
  7. Select admin as the user group and click on Finish.
  8. Next, we need to configure Configure STS to add Axis2Service as a trusted service. In Enter the above screen, enter the HTTP endpoint url of the Axis2Service as the Endpoint Address. 

    Panel

    Endpoint Address = http://localhost:9765/services/Axis2Service/

  9. Usually, the security token is signed by STS. Thus, it is necessary to select a certificate alias to sign the token. Select the default wso2carbon certificate alias.
  10. Now, check the user profile of admin user who is going to authenticate to the STS. Click on My Profiles at the left menu. The Update Profile form is displayed displays where you can enter various user attributes such as First Name, Last Name, etc.
  11. Make sure to add some values to the First Name and Email address fields since we are going to use those as the required claims.
  12. Click on Configure in the left menu and select Claim Management. You find a set of claim dialects associated with the internal user store in IS. Click on the default claim dialect, http://wso2.org/claims
  13. Click on the First Name claim mapping.
  14. As you can see in the following screen shot, First Name is mapped to givenName attribute.
     

Now, you should be able to understand why we have specified http://wso2.org/claims/givenName as the Claim Uri for First Name attribute in the service policy.

Step 3 - Preparing the Service Consumer

Now, all what left is to work on the service consumer. Basically, we you need to generate the RequestSecurityToken programmatically using a client, insert this into the web service Web Service request, and send it to Axis2Service.
The wst:RequestSecurityToken element is used to request a security token from STS.

It will be This is a child of SOAP body. At the minimum level, the wst:RequestSecurityToken element will be is similar to the following.:

Code Block
languagehtml/xml
<wst:RequestSecurityToken xmlns:wst="http://schemas.xmlsoap.org/ws/2005/02/trust">
            <wst:RequestType>http://schemas.xmlsoap.org/ws/2005/02/trust/Issue</wst:RequestType>
            <wst:TokenType>http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV2.0
            </wst:TokenType>
            <wst:KeyType>http://schemas.xmlsoap.org/ws/2005/02/trust/Bearer</wst:KeyType>
            <wst:Claims xmlns:wsp="http://schemas.xmlsoap.org/ws/2005/02/trust"
                        wsp:Dialect="http://wso2.org">
                <wsid:ClaimType xmlns:wsid="http://schemas.xmlsoap.org/ws/2005/05/identity"
                                Uri="http://wso2.org/claims/givenname"/>
                <wsid:ClaimType xmlns:wsid="http://schemas.xmlsoap.org/ws/2005/05/identity"
                                Uri="http://wso2.org/claims/emailaddress"/>
            </wst:Claims>
    
   </wst:RequestSecurityToken>

You would like to compare Compare this with the SupportingToken policy assertion which we defined in step 1. In this, Here we will request a SAML2 token from STS (see wst:TokenType element) and indicate that the keytype wst:KeyType is bearer. We also define the two claims we would present presented to the Web Service, givenname and emailaddress.

You can include the wst:RequestSecurityToken element into a SOAP message body and send it to STS. You can use the soapUI SOAP request editor as shown below.:

Since we are using usernametoken authentication when submitting token request to STS, specify the username and password under the "Aut" tab in the soapUI. Also specify WSS-passwordType as plaintext and WSS timeto live to some integer value. Make sure to enable WS-Addressing for the token request.

With all these, when you submit the request to the STS endpoint (in our case, https://localhost:9444/services/wso2carbon-sts), you will get a response with the generated token (RequestSecurityTokenResponse). You will notice it can view this in the response view of the above screen shot.

Now, you can extract the saml2:Assertion element from the response and embed it with the actual web service Web Service request message. For that, you can try adding a SAML WSS entry for to the soapUI request and copy the extracted saml2:Assertion element into the Enter SAML Assertion text area as shown in the following screen shot. However, I was unsuccessful sending a message with bearer confirmation method with soapUI-4.5.2. It seems soapUI .

Info

SoapUI still supports sender vouches confirmation method only.

...

Image Removed

...

 

Image Added

Because of this limitation, we need to follow a programmatic approach to insert the token into the Web Service request and forward to Axis2Service. You can find the complete working client in this sourceforge account.

Steps to Run the Client

  1. Check out the complete source from https://sourceforge.net/p/charithablogsam/code/ci/master/tree/ and import the source into your IDE.
  2. Go to <IS_HOME>/bin and type ant. This copies the necessary client libraries into <IS_HOME>/repository/lib directory.
  3. Add <IS_HOME>/repository/lib directory to your IDE class path.
  4. Also add <IS_HOME>/repository/components/lib/bcprov-jdk15-132.jar to the class path.
  5. Modify Axis2ServiceClient according to the file paths in your system wherever necessary. E.g., policy stsPolicy = loadSTSPolicy ("/resources/policies/sts.ut.policy.xml").
  6. Run the client.


The output you get should be similar to the following:

Code Block
languagehtml/xml
<saml2:Assertion xmlns:saml2="urn:oasis:names:tc:SAML:2.0:assertion" xmlns:xs="http://www.w3.org/2001/XMLSchema" ID="urn:uuid:D6511FA799FD47AC4D1373081003469" IssueInstant="2013-07-06T03:23:23.465Z" Version="2.0"><saml2:Issuer>localhost</saml2:Issuer><ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
	<ds:SignedInfo>
		<ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"></ds:CanonicalizationMethod>
		<ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"></ds:SignatureMethod>
		<ds:Reference URI="#urn:uuid:D6511FA799FD47AC4D1373081003469">
			<ds:Transforms>
				<ds:Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"></ds:Transform>
				<ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"><ec:InclusiveNamespaces xmlns:ec="http://www.w3.org/2001/10/xml-exc-c14n#" PrefixList="xs"></ec:InclusiveNamespaces></ds:Transform>
			</ds:Transforms>
			<ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"></ds:DigestMethod>
			<ds:DigestValue>MO6PnDsz+lbXsvuFRmMBwa7r0j4=</ds:DigestValue>
		</ds:Reference>
	</ds:SignedInfo>
	<ds:SignatureValue>
		i8S8BFxLJ59DpYUF8s8/Glt8x0n2plGPgCJKigB6eopRt7Y52LLnSqRimkWTWx57wdwjOFENMTPaZsYgBJ3AlxKRDQoy23OBOjrRA+S0WQ4Pq3EGcmM5XGKxU9pTNnh/xEhT4lDN9QE12Z1rttFz6RkUAgFt3nmvqNqZvbNMga4=
	</ds:SignatureValue>
	<ds:KeyInfo><ds:X509Data><ds:X509Certificate>MIICNTCCAZ6gAwIBAgIES343gjANBgkqhkiG9w0BAQUFADBVMQswCQYDVQQGEwJVUzELMAkGA1UECAwCQ0ExFjAUBgNVBAcMDU1vdW50YWluIFZpZXcxDTALBgNVBAoMBFdTTzIxEjAQBgNVBAMMCWxvY2FsaG9zdDAeFw0xMDAyMTkwNzAyMjZaFw0zNTAyMTMwNzAyMjZaMFUxCzAJBgNVBAYTAlVTMQswCQYDVQQIDAJDQTEWMBQGA1UEBwwNTW91bnRhaW4gVmlldzENMAsGA1UECgwEV1NPMjESMBAGA1UEAwwJbG9jYWxob3N0MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCUp/oV1vWc8/TkQSiAvTou
sMzOM4asB2iltr2QKozni5aVFu818MpOLZIr8LMnTzWllJvvaA5RAAdpbECb+48FjbBe0hseUdN5HpwvnH/DW8ZccGvk53I6Orq7hLCv1ZHtuOCokghz/ATrhyPq+QktMfXnRS4HrKGJTzxaCcU7OQID
AQABoxIwEDAOBgNVHQ8BAf8EBAMCBPAwDQYJKoZIhvcNAQEFBQADgYEAW5wPR7cr1LAdq+IrR44iQlRG5ITCZXY9hI0PygLP2rHANh+PYfTmxbuOnykNGyhM6FjFLbW2uZHQTY1jMrPprjOrmyK5sjJR
O4d1DeGHT/YnIjs9JogRKv4XHECwLtIVdAbIdWHEtVZJyMSktcyysFcvuhPQK8Qc/E/Wq8uHSCo=</ds:X509Certificate></ds:X509Data></ds:KeyInfo></ds:Signature><saml2:Subject><saml2:NameID Format="urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress">admin</saml2:NameID><saml2:SubjectConfirmation Method="urn:oasis:names:tc:SAML:2.0:cm:bearer"></saml2:SubjectConfirmation></saml2:Subject><saml2:Conditions NotBefore="2013-07-06T03:23:23.465Z" NotOnOrAfter="2013-07-06T03:28:23.465Z"></saml2:Conditions><saml2:AuthnStatement AuthnInstant="2013-07-06T03:23:23.465Z"><saml2:AuthnContext><saml2:AuthnContextClassRef>urn:oasis:names:tc:SAML:2.0:ac:classes:Password</saml2:AuthnContextClassRef></saml2:AuthnContext></saml2:AuthnStatement><saml2:AttributeStatement><saml2:Attribute Name="http://wso2.org/claims/emailaddress" NameFormat="http://wso2.org/claims/emailaddress"><saml2:AttributeValue xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xs:string">charitha@wso2.com</saml2:AttributeValue></saml2:Attribute><saml2:Attribute Name="http://wso2.org/claims/givenname" NameFormat="http://wso2.org/claims/givenname"><saml2:AttributeValue xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xs:string">charitha</saml2:AttributeValue></saml2:Attribute></saml2:AttributeStatement></saml2:Assertion>
Response  : <ns:echoStringResponse xmlns:ns="http://service.carbon.wso2.org"><ns:return>Hello world1</ns:return></ns:echoStringResponse>