[jboss-user] UsernameToken authentication using JBossWS

Leandro Sales leandroal at gmail.com
Thu Dec 6 16:52:36 EST 2007


Hi folks,

 I need to consume a certain webservice that use a UsernameToken
authentication method. Using SOAPui it generate the following SOAP
envelop:

<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:sec="http://www.vaisala.com/security"
xmlns:vais="http://www.vaisala.com/">
   <soapenv:Header>
      <sec:UsernameToken>
         <sec:username>?</sec:username>
         <sec:password>?</sec:password>
      </sec:UsernameToken>
   </soapenv:Header>
   <soapenv:Body>
      <vais:GetStations/>
   </soapenv:Body>
</soapenv:Envelope>

I use the wsconsumer.sh and jboss generated all the java classes
necessary to have the objects, and I have the following code:

(... some imports ...)

@Stateless
@WebService(endpointInterface="bean.WeatherInfoIF")
@WebServiceClient(name = "Vaisala", targetNamespace = "http://www.xxx.com/",
		 wsdlLocation = "http://xxx/WebS/xxx.asmx?WSDL")
public class MyInfoBean implements InfoIF {

	public MyInfoBean() {
		
	}

	public String makeRequest(int arg0) {
		Service service = null;
		
        try {
            URL wsdlLocation = new URL("http://xxx/WebS/xxx.asmx?WSDL");
            QName serviceName = new QName("http://www.xxx.com/", "TheService");
            service = Service.create(wsdlLocation, serviceName);
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }

        ServiceSOAP serviceSoap = service.getPort(ServiceSOAP.class);

        URL url = null;
		try {
			url = new File("/home/leandro/jboss-wsse-client.xml").toURL();
			((StubExt)serviceSoap).setSecurityConfig(url.toExternalForm());
		} catch (MalformedURLException e) {
			e.printStackTrace();
		}

        ((StubExt)serviceSoap).setConfigName("Standard WSSecurity Client");

        UsernameToken usernameToken = new UsernameToken();
        usernameToken.setUsername("user");
        usernameToken.setPassword("pass");

        // I NEED TO PASS THE UsernameToken information to be inserted
into the SOAP-Header of the SOAP envelop, how to do this?

        String stations = serviceSoap.getName();


        return "";
	}
	
}

I can't call serviceSoap.getName() because I don't know how to pass
the UsernameToken object. Anyone to help me?

Thank you,
Leandro.



More information about the jboss-user mailing list