Advanced JAX-WS Security with Wildfly Client

Here too you start by consuming the published WSDL contract using the wsconsume tool(Eclipse or Maven. See our tutorial about how to use them). Then you simply invoke the the endpoint as a standard JAX-WS one:


import java.math.BigInteger;
import java.util.Map;


import org.junit.Assert;
import org.junit.Test;

import client.BASInscriptionWSService;
import client.EcoleApplicationInContext;
import client.Etudiant;
import client.GetEtudiantRequest;
import client.IBASinscriptionWS;

public class BASInscriptionWSIntegrationTest {

	public void testGetEtudiant() throws Exception {
		BASInscriptionWSService service = new BASInscriptionWSService(
				new URL(
		IBASinscriptionWS port = service.getBASInscriptionWSPort();
		setupWSSecurity(port, "kermit");
		Etudiant etudiant = port.getEtudiant(prepareGetEtudiantRequest("32")).getEtudiant();  
		Assert.assertEquals("Festado", etudiant.getPrenom());

		setupWSSecurity(port, "alice");
		try {
			port.getEtudiant(prepareGetEtudiantRequest("32")).getEtudiant();"Authorization exception expected!");
		} catch (Exception e) {
			Assert.assertTrue("Authorization error message expected, but got: "
					+ e.getMessage(), e.getMessage().contains("Unauthorised"));

	private GetEtudiantRequest prepareGetEtudiantRequest(String value) {
		GetEtudiantRequest request = new GetEtudiantRequest();
		request.setEtudiantId(new BigInteger(value));
		return request;

	private void setupWSSecurity(IBASinscriptionWS port, String value) {
		Map<String, Object> ctx = ((BindingProvider) port).getRequestContext();
				new ClientPasswordCallback());
		ctx.put(SecurityConstants.USERNAME, value);


The UsernamePasswordCallback class is shown below and is responsible for setting the passwords on client side just before performing the invocations:

import java.util.HashMap;
import java.util.Map;


public class ClientPasswordCallback extends PasswordCallbackHandler
   public ClientPasswordCallback()
   private static Map<String, String> getInitMap() {
      Map<String, String> passwords = new HashMap<String, String>();
      passwords.put("alice", "password");
      passwords.put("bob", "password");
      passwords.put("kermit", "thefrog");
      return passwords;


  • Do you need any kind of  support?
  • Do you need professional coaching?
  • Do you need samples code to start?
  • Do you have any question about our SOAP & REST Architecture and how to implement it?
  • Do you have any question about our API Infrastructure and how to install it?

    We are based in Germany and speak French, German and English

Then feel free to contact us today  

Thanks. Festado Team

Enregistrez vous aujoud'hui, achetez et vendre en ligne gratuitement Clickez ici