Java Web Service client basic authentication

German :

I have created a JAX-WS Web Service on top of Glassfish which requires basic HTTP authentication.

Now I want to create a standalone java application client for that Web Service but I don't have a clue of how to pass the username and password.

It works with Eclipse's Web Service explorer, and examining the wire I found this:

POST /SnaProvisioning/SnaProvisioningV1_0 HTTP/1.1
Host: localhost:8080
Content-Type: text/xml; charset=utf-8
Content-Length: 311
Accept: application/soap+xml, application/dime, multipart/related, text/*
User-Agent: IBM Web Services Explorer
Cache-Control: no-cache
Pragma: no-cache
SOAPAction: ""
Authorization: Basic Z2VybWFuOmdlcm1hbg==
Connection: close

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:q0="http://ngin.ericsson.com/sna/types/v1.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <soapenv:Body>
    <q0:listServiceScripts/>
  </soapenv:Body>
</soapenv:Envelope>

How do I pass the username and password in this "Authorization" header using java code? Is it hashed or something like that? What is the algorithm?

Without security involved I have a working standalone java client:

SnaProvisioning myPort = new SnaProvisioning_Service().getSnaProvisioningV10Port();
myPort.listServiceScripts();
German :

It turned out that there's a simple, standard way to achieve what I wanted:

import java.net.Authenticator;
import java.net.PasswordAuthentication;

Authenticator myAuth = new Authenticator() 
{
    @Override
    protected PasswordAuthentication getPasswordAuthentication()
    {
        return new PasswordAuthentication("german", "german".toCharArray());
    }
};

Authenticator.setDefault(myAuth);

No custom "sun" classes or external dependencies, and no manually encode anything.

I'm aware that BASIC security is not, well, secure, but we are also using HTTPS.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Error when compiling a basic web service client in Java

Consuming web service with c# and basic authentication

Spring Boot web service client authentication

Android client for REST web service with basic security

Basic authentication with WordPress RESTful service from external client app

web service/api supporting basic, anonymous and windows authentication

How to set password connecting to a web service with client-authentication for KeyFile?

How to pass Windows Authentication credential from client to Web API service

write a client in Python to call a rest web service using JWT authentication

Client part of the Digest Authentication using PHP POST to Web Service

dynamic proxy soap web service client in java?

java web service client, adding http headers

Connection details & timeouts in a java web service client

Java Spring Web Service Client Fault Handling

Client artifacts generated in a java web service

How to call web service client in java eclipse

Web Service Authentication - PHP

github service hook and basic authentication

java: basic web service interface without a web server

SPNEGO Authentication Works from a Custom Java Client, but NOT from a Web Browser

Java Rest Basic Authentication

Client Certificate authentication in Java

NoSuchMethodError when adding basic authentication in Spring Boot Soap Web service project

401 error when consuming a Web service with HTTP Basic authentication using CXF

How do I consume a web service protected with HTTP basic authentication using the CXF framework?

Apache CXF: How to secure JAX-RS web service with basic authentication

How to specify basic authentication in PL/SQL SOAP WSDL web service call

Client in REstful web service

Dynamic Web Service Client