Network Deployment (Distributed operating systems), v8.0 > Develop and deploying applications > Develop web services - Security (WS-Security) > Develop applications that use Web Services Security


Configure HTTP basic authentication for JAX-RPC web services programmatically

We can configure HTTP basic authentication for JAX-RPC web services by programmatically modifying HTTP properties.

This task is one of three ways that you can configure HTTP basic authentication. We can also configure HTTP basic authentication with an assembly tool or with the admin console.

If you programmatically configure HTTP basic authentication, the properties are configured in the Stub or Call instance. If you choose to configure HTTP basic authentication with the admin console or an assembly tool, the Web Services Security binding information is modified. The values that are set programmatically take precedence over the values defined in the binding.

The HTTP basic authentication that is discussed in this topic is orthogonal to WS-Security and is distinct from basic authentication that WS-Security supports. WS-Security supports basic authentication token, not HTTP basic authentication.

Configure HTTP basic authentication programmatically with the following steps.


Procedure

Set the properties in the Stub or Call instance for a Web service or a web service client. We can set properties with the following constant names:

javax.xml.rpc.Call.USERNAME_PROPERTY
javax.xml.rpc.Call.PASSWORD_PROPERTY
javax.xml.rpc.Stub.USERNAME_PROPERTY
javax.xml.rpc.Stub.PASSWORD_PROPERTY


Example

The following code enables you to configure basic authentication programmatically:
Properties prop = new Properties();
InitialContext ctx = new InitialContext(prop);
Service service = (Service)ctx.lookup("java:comp/env/service/StockQuoteService");
QName portQname = new QName("http:////publib.boulder.ibm.com/infocenter/wasinfo/v8r0/index.jsp?topic=/  channel.test.wsfvt.ws.ibm.com", "StockQuoteHttp");
StockQuote sq = (StockQuote)service.getPort(portQname, StockQuote.class);
((javax.xml.rpc.Stub) sq)._setProperty(javax.xml.rpc.Stub.USERNAME_PROPERTY, "myUser");
((javax.xml.rpc.Stub) sq)._setProperty(javax.xml.rpc.Stub.PASSWORD_PROPERTY, "myPwd");


Secure web services
Overview of standards and programming models for web services message-level security
Secure web services applications at the transport level
Authenticate web services clients using HTTP basic authentication
Configure a web services client to access resources using a web proxy


Related


HTTP SSL Configuration collection
HTTP basic authentication collection

+

Search Tips   |   Advanced Search