Secure Web Service with Basic Authentication in Jboss AS 7 Server

In this article we will implement a web service with basic authentication using Jboss AS 7 server.

  1. Create a Simple Web Service

    Start with implementing simple RPC servlet-based web service with JAX-WS.

  2. Create a User in Jboss AS 7

    New user in Jboss AS 7 is added with add-user utility. Run add-user.bat which is located in {jboss.home}/bin:


    More details about "Add-user utility" read at Jboss Documentation.

  3. Add allowed roles to Web Service Endpoint Implementation

    @WebService(endpointInterface = "example.ExamClouds")
    public class ExamCloudsImpl implements ExamClouds {
  4. Modify web.xml

    Add security-role, security-constraint and login-config elements.

  5. Create jboss-web.xml

  6. Add authentication credentials to the client

    ExamCloudsImplService service = new ExamCloudsImplService();
    ExamClouds port = service.getExamCloudsImplPort();
    BindingProvider prov = (BindingProvider) port;
    prov.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, "newuser");
    prov.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, "new");

Leave your comment: