2 Mart 2018 Cuma

JAX-WS WebServiceContext Arayüzü

getMessageContext metodu
Açıklaması şöyle.
Clients can authenticate themselves with client certificates, or HTTP basic authentication.
The latter is too weak to be trustable on a non-encrypted channel, but works over HTTPS.
The MessageContext class will be configured with the username and password of the sender when SOAP messages are posted to the endpoint;*
Şöyle yaparız.
@WebService
public class Service{
  //Injected by whatever container you are using
  @Resource
  WebServiceContext wctx;

  @WebMethod
  public Integer fooServiceLocator(int x, int y){
    //Get The Message Context
    MessageContext mctx = wctx.getMessageContext();

    //Grab the HTTP Request Headers
    Map<Object, Object> object = (Map<Object, Object>)
      mctx.get(MessageContext.HTTP_REQUEST_HEADERS);

    //Grab the Authorization Values
    List<String> basicCredentials = (List<String>) object.get("Authorization");

    //Print out credentials
    basicCredentials.forEach(System.out::println);

    //Do a meaningful check of the credentials
  ...
}

Hiç yorum yok:

Yorum Gönder