This discussion is archived
1 Reply Latest reply: Nov 18, 2012 3:33 PM by user696 RSS

JAXWS EJB3.0 Based WebService Authentication and Authorization - Weblogic

Lother Newbie
Currently Being Moderated
Hi Experts,

I need to Create a EJB3.0 WS where this Service has static Authentication and Authorization. How can I achieve it, any pointer.

TIA
  • 1. Re: JAXWS EJB3.0 Based WebService Authentication and Authorization - Weblogic
    user696 Explorer
    Currently Being Moderated
    The below sample is for basic authentication and authorization.

    Web service
    ========
    import javax.ejb.Stateless;
    import javax.ejb.TransactionAttribute;
    import javax.ejb.Remote;
    import javax.jws.WebMethod;
    import javax.jws.WebService;
    import javax.annotation.security.RolesAllowed;
    import javax.ejb.SecurityRoles;

    @Stateless(mappedName="com.slsbBean")
    @Remote( { com.bea.Service.class})
    @WebService(name="TransactionPortType", serviceName="TransactionService",
    targetNamespace="http://example.org")

    public class ServiceBean implements Service {
    @WebMethod()
    @RolesAllowed ( {"Admin","Manager"})
    public void testMethod(String s) {
    System.out.println("inside ejb method");
    System.out.println("username : " + weblogic.security.SubjectUtils.getUserPrincipal(weblogic.security.Security.getCurrentSubject()));
    }
    }


    Client
    ====
    import java.util.Map;
    import javax.xml.ws.BindingProvider;

    public class Test {

    public static void main(String[] args) {

    TransactionService simple = new TransactionService();
    TransactionPortType port = simple.getTransactionPortTypePort();

    BindingProvider bindingProvider = (BindingProvider) port;
    Map<String, Object> reqContext = bindingProvider.getRequestContext();
    reqContext.put(BindingProvider.USERNAME_PROPERTY, "XXXXXX");
    reqContext.put(BindingProvider.PASSWORD_PROPERTY, "XXXXXX");

    port.testMethod("hello");

    }
    }

    Regards,
    Sunil P

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points