LearningDeveloper
LearningDeveloper

Reputation: 668

Java, access secure WSO2 web service with Username and Password

I have a Maven project and am successfully connected to an insecure web service that has been created with WSO2. When the security is enabled, how do I pass the credentials, namely the Username and Password, to connect to the service?

Firstly, can I do it quickly by introducing the Username and Password in the Java code itself?

Do I have to generate a certificate like I've seen in a few of the articles or is there any other way to get this done?

My pom.xml has the following entry

<execution>
    <id>getTestService</id>
    <goals>
        <goal>wsdl2code</goal>
    </goals>
    <configuration>
        <unpackClasses>true</unpackClasses>
        <databindingName>xmlbeans</databindingName>
        <packageName>com.test.esb</packageName>
        <wsdlFile>http://test:8080/services/getTestService?wsdl</wsdlFile>
        <syncMode>sync</syncMode>
    </configuration>
</execution>

and in my Java class, I am calling the service with the below code.

final TestServiceStub testStub = new TestServiceStub();
final TestServiceDocument testDoc = 
    TestServiceDocument.Factory.newInstance();

final TestService testReq = TestService.Factory.newInstance();

...

testDoc.setTestService(testReq);
testStub.TestService(testDoc);

Upvotes: 0

Views: 98

Answers (1)

chamilad
chamilad

Reputation: 1669

Not sure if this covers your scenario, but this blog post elaborates on how to access a Username-token secured service in Java. You need to have the certificate of the server in your trust store and you need to provide the username and the password to the stub.

Upvotes: 1

Related Questions