I have created web services and trying to add security part of it. I'm using RAD and wondering how to add the username token in the webservices.xml extension tab?
Any help is appreciated.
Thanks.
I have created web services and trying to add security part of it. I'm using RAD and wondering how to add the username token in the webservices.xml extension tab?
Any help is appreciated.
Thanks.
A comment was added by @parthkansara asking about how to do this for a JAX-WS application. I'm answering that comment as an additional answer to this topic since there aren't enough characters to do so in the comment field.
You can add a WS-Security Policy and Bindings for a JAX-WS application in RAD. However, its not the most straightforward thing. Also, if you apply the policy/bindings with RAD and deploy, then modify them with the admin console, what you did with the admin console won't take effect. This is very confusing behavior and something I would frequently get trouble reports for until I wrote a troubleshooting article about it. If you are going to deploy your app with RAD, I suggest that you apply your policy/bindings with the admin console, NOT with RAD. If you do this, your policy/bindings will stay throughout redeploys; they'll only disappear if you uninstall your app.
I only suggest that you apply policy/bindings using RAD if you intend to export your ear, then install the ear with the admin console, not by deploying directly with RAD.
So, I'm going to give you the instructions for adding a UsernameToken on a RAD deployed application using the admin console.
The first thing that you need to do is make sure that your RAD is using resources on server, not workspace:
On the right, expand 'Publishing settings for WebSphere Application Server'
After changing to 'Run server with resources on Server', you must uninstall, then re-install the application. Just doing a redeploy does not suffice. Do the following:
Create a jax-ws custom policy set:
Edit the custom policy set
Configure the client to use the UntPolicy policy set.
Create a custom binding for the client.
Edit the custom binding for the client.
Restart the application
Test the application.
To see the inbound/outbound SOAP messages in a trace, do the following
Add the following trace spec:
Restart the application server.
Search the trace in (profileRoot)/logs/(serverName)/trace.log for the following string:
Source: These steps were taken from this task in the WebSphere knowledge center:
https://www.ibm.com/support/knowledgecenter/SSAW57_9.0.0/com.ibm.websphere.nd.multiplatform.doc/ae/twbs_stand_alone_security_token.html
In the WebSphere WS-Security troubleshooting guide, there is a page that contains a list of the jax-ws policy/binding examples that are available:
WebSphere WS-Security Examples : JAX-WS Policy/Binding Configuration and Code Samples
There are a lot on that page including, but not limited to:
I do this all the time, but I use the wizard because doing it manually is error-prone.
You didn't say if you were adding constraints to the client, provider or both. I'll give you instructions for both. I'm using HelloService and HelloSvcClient in my examples:
Add the stand-alone UsernameToken to the client:
1) Switch to the J2EE Perspective
a) Window->Open Perspective->Other->Java EE
b) Ok
2) Select the Services tab on the left
3) Expand JAX-RPC->Clients
4) Right click on HelloSvcClient: service/HelloService ->Secure Web Service Client->Add Stand Alone Security Token
Token type: Username Token
Callback handler: (choose one)
** NonPromptCallbackHandler (default -- hardcode username/password)
** GUIPromptCallbackHandler (to prompt the user for the username/password -- can't run on an app server)
** StdinPromptCallbackHandler (to get the uid/pw from stdin -- can't run on an app server)
5) Next
6) User Name and Password
User ID: (userid)
Password: (password)
7) Finish
Add the stand-alone UsernameToken to the provider:
1) Select the Services tab on the left
2) Expand JAX-RPC
3) Right click on HelloSvc: HelloService->Secure Web Service->Add Stand Alone Security Token
4) WS-Security Add a Service Side Security Token
Token type: choose Username Token
JAAS configuration name: system.wssecurity.UsernameToken
5) Finish
Remove the Caller Part from the Service Configuration if Necessary
If security is not enabled on your server, your service won't be able to authenticate. In this case, in the service consumer configuration, you'll have to remove the caller part for your token so that you don't get an error when you make your request. If you do have security enabled on your server, skip this step.
1) Select the Services tab on the left
2) Expand JAX-RPC
3) Right click on HelloSvc: HelloService->Show->Web Service Extensions Editor
4) Extensions tab
Request Consumer Service Configuration Details->Caller Part
If there's only one there, delete it
If there's more than one there, find the one who's "Local name" entry corresponds to the token type that you added and delete it (for example, http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#UsernameToken for UsernameToken)
Re-Publish the Applications
1) Go to the Servers pane
2) Right click on the desired server->publish