Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8418387
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T02:18:47+00:00 2026-06-10T02:18:47+00:00

I created a proxied service in WSO2 ESB and setup a UsernameToken authentication. However

  • 0

I created a proxied service in WSO2 ESB and setup a UsernameToken authentication. However looks like it is not that easy to configure UsernameToken with JAX-WS bundled within the JDK (as described here), the JDK has to be patched and so on. Is there a way to use a Basic HTTP Authentication with the credentials of the ESB just like the UsernameToken?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T02:18:49+00:00Added an answer on June 10, 2026 at 2:18 am

    According to the article “Securing Web Service Integration” by Amila Suriarachchi “WSO2 carbon supports UT even with HTTP basic authentication by converting the POX message”, but I am not sure whether this is relevant to your interests.

    However configuring UsernameToken authorization with a JAX-WS client is not as hard as it seems. All you have to do is create a class that implements javax.xml.ws.handler.soap.SOAPHandler and add the security header in the outbound messages by overriding the handleMessage(SOAPMessageContext messageContext) method.

    My java version is 1.6.0_26 (with none of the above mentioned patches applied) and the web service client stub classes are generated by JAX-WS RI 2.1.7 according to the wsdl of a web service, secured by the UsernameToken scenario and exposed by a WSO2 Carbon Server (namely Data Services Server-2.6.3)

    I use Apache WSS4J for creating the security header – in this case by simply instantiating a org.apache.ws.security.message.WSSecUsernameToken object and setting the username and password via the setUserInfo(String user, String password) method. Also a timestamp element should be added to the security header of the outgoing SOAP message.
    A sample implementation could look like this:

    public boolean handleMessage(SOAPMessageContext messageContext) {
        Boolean isOutboundMessage = (Boolean) messageContext.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
    
        if (isOutboundMessage) {
            SOAPPart messageSoapPart = messageContext.getMessage().getSOAPPart();
    
            WSSecHeader securityHeader = new WSSecHeader();
            securityHeader.insertSecurityHeader(messageSoapPart);
            WSSecUsernameToken usernameToken = new WSSecUsernameToken();
    
            usernameToken.setPasswordType(WSConstants.PASSWORD_TEXT);
            usernameToken.setUserInfo("root", "top_secret");
    
            WSSecTimestamp timestamp = new WSSecTimestamp();
    
            usernameToken.build(messageSoapPart, securityHeader);
            timestamp.build(messageSoapPart, securityHeader);
        }
    
        return true;
    }
    

    Another important thing to mention is that SOAP header elements may come with a mustUnderstand global SOAP attribute. Referring to the article Working with Headers in JAX-WS SOAPHandlers by Jim White this attribute is used to indicate whether or not the web service receiver or intermediary is required to understand the header element before processing the message.

    In case the mustUnderstand element is set to true (soapenv:mustUnderstand=”1″) the getHeaders() method should be coded to tell the runtime environment that the SOAP handler is going to take care of the mustUnderstand header elements by returning a set of QName (qualified name) objects that match the mustUnderstand header elements. Below is the getHeaders() method that handles the Security header.

    public Set<QName> getHeaders() {
        final String NAMESPACE_URI = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd";
        final String LOCAL_PART = "Security";
        final String PREFIX = "wsse";
    
        final QName wssecurity = new QName(NAMESPACE_URI, LOCAL_PART, PREFIX);  
        final Set<QName> headers = new HashSet<QName>();
        headers.add(wssecurity);  
    
        return headers;  
    }
    

    Lastly, before getting the service port and invoking any of its methods you should register an instance of the above mentioned class (let’s say – UsernameTokenSecuritySoapHandler) to the handler chain of your web service client. This can be done by using the following code:

        Service service = new Service();
        service.setHandlerResolver(new HandlerResolver() {
            public List<Handler> getHandlerChain(PortInfo portInfo) {
                List<Handler> handlers = new ArrayList<Handler>();
                handlers.add(new UsernameTokenSecuritySoapHandler());
                return handlers;
            }
        });
    

    In addition – you could find here an excellent article by Young Yang about the JAX-WS API’s handler framework.

    Hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Created .NET WCF service, tested it - works. Generated schemas from Data and service
I want to create an autogenerated proxy for WCF service that allows me to
I’ve inherited a rather convoluted project. The original designer created a cookie that appears
I have a windows service that uses WCF to connect to other services. It
I am developing a wcf service . I have created two dll's one for
Setup: I have two trees of scripts that run on Oracle 11g - one
Hi would like to create a function that takes one argument (a function) and
Created Private Key & Self signed certficate in a Key Store keytool -genkey -alias
Created an OpenGraph action and object. Trying to submit my action. When I click
I created a python server on port 8000 using python -m SimpleHTTPServer . When

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.