Web Service Basic Authorization with Axis 1.4 Java client - java

I want to create a Java client for a SOAP web service with Basic Authorization. I generate a client in the Eclipse Oxy (Web Service Client) with Apache Axis 1.4 runtime. Our cases use Basic Authorization with required username, password and domain (Figure 1: SOUP UI tool).
In SOAP UI the service return success status, while java code return status 401 Unauthorized.
The following code is used when making a call to service (I send null content, because I only want to get success answer from service just like in SOAP UI tool):
IntegrationService_AdEl service = locator.getBasicHttpBinding_IntegrationService_AdEl();
((Stub) service)._setProperty(Call.USERNAME_PROPERTY,"test");
((Stub) service)._setProperty(Call.PASSWORD_PROPERTY, "123");
((Stub) service)._setProperty("DOMAIN", "dmn");
IntegrationService_AdElPersonScreeningCreateResponse c = service.personScreeningCreate(null);
I am wondering how to make a successful call with the parameters for Basic Authorization.
Thanks for the help.

Related

How to achieve login in java consuming a web service?

I have a project in java which utilize j_security_check and ldap for authentication. Now my employer want to change it to an authentication using a webservice provided . What they gave me is actually a link as shown below
"http://11.111.111.111/ADManager/ADlogin.asmx"
I am a total newbie to java and webservice.All I know is if we provide some data to a webservice it will give a response. my doubts are
Is it possible to create a login consuming that link they provided?
Should I ask them for more info?
Is it posible to replace the j_security_check and ldap already configured in my java project?
P.S : The one who assigned me this task doesn't seems to have much knowledge either.
The short answer is you can.
You need to do the following:
Each web resource is protected by a (servlet) filter. This filter checks each incoming request and validates the token which needs to be on the http header. If the token is valid then the request is served. If the token is invalid the filter is going to send back http 401 unauthorized. Then redirect to the loin page.
Login with rest service:
1) Create a custom login page with username/password field.
2) Create a rest web service, receives username/password. It will check the credentials against an external access management infrastructure like OpenAM.
3) First, call auth(username, password) rest api to get the auth token. If the given credentials are okay then just send back the auth cookie to the client with HTTP 200 response code.
4) Then, you can call protected rest apis. You need to send auth cookie with your request each time.
5) Servlet filter (or something similar) checks each incoming request and validates the token. If the token is valid then the request goes forward to the rest method, if not you need to generate an http 401/403 response.
I suggest you not to write your own authentication layer, please use an existing one, for example OpenAM.
This forum topic explain everything you.

Java webservices - send object in request headers

I am using Jaxws to consume a webservice. while iam sending request i need to send an object in the request headers. When i am invoking the service from Soap-UI iam successfully getting the data. but the same in java i am unable to get it. I researched a lot on this any one know please help me how to do it.
Here is my java code
//getting the service
MyService servc = new MyService();
MyServiceSoap soap = servc.getMyServiceSoap();
//call the service
System.out.println(soap.SERVICE_A("123456789")); //getting null as response because i am not setting userid, password
I want to set the userid,password to the Authentication pojo object and set it to the soap headers and send the request. how i can do this.?
Here is my Soap-ui request screenshot
Please see the SoapUI request format
My Questions is : How to send a java object in the soap request headers.?
Thanks in Advance,
Praneeth.
From my understanding, what you're lacking is the Basic Authentication headers, where you pass the following in the HTTP header:
Authorization: Basic <Base64(username:password)>
Check in your SOAP-UI if the request sends this.
Here are some SO topics that may help you implement it:
Java Web Service client basic authentication
How do I consume a web service protected with HTTP basic authentication using the CXF framework?

Keycloak id_token is null with REST authentication

While using REST authentication with Keycloak, my id_token is null (server side). To connect to the application, I am using the following URI:http://localhost:port/auth/realms/{name}/protocol/openid-connect/token provided in the documentation (with the appropriate form params grant_type, username, password,... see here). In response (client side) I can retrieve the access_token and id_token. Then, I am using the "Bearer" authorization in the HTTP header to discuss with the server. While using my custom client, the id_token is null in the server side. Can someone explain me why?
(Just to be clear, all is working well by using the keycloak authentication page)
It seems that the id_token is only used while using the GUI authentication interface. To bypass my problem, I added my custom metadata to the access_token, then replaced all the reference to the id_token (on server side) to the access_token. By doing this, the application is fully compatible with the OAuth2 protocol.

Consuming a WCF service in a Java Client using wsHttpBinding

I'm trying to get a Java Client to communicate with a WCF wshttpbinding WebService. But I've been unsucesful so far. The call either hangs, or I get: “SOAPFaultException: The message could not be processed. This is most likely because the action 'http://tempuri.org/ISampleService/GetServiceName' is incorrect or because the message contains an invalid or expired security context token or because there is a mismatch between bindings. The security context token would be invalid if the service aborted the channel due to inactivity. To prevent the service from aborting idle sessions prematurely increase the Receive timeout on the service endpoint's binding.”
My Web Service is just the default Visual Studio 2010 generated "WCF Service Library Template".
My java client is generated in netBeans 7.0.1 and stubs have been generated using new Other --> Web Services --> Web Service Client and I’m referencing a local WSDL.
I've tried adding WebServiceFeature wsAddressing = new AddressingFeature(true); in the stub generated but it just throws the exception above.
I see other people with similar problems; however, I don't see any true resolution. Any suggestions would be greatly appreciated.
It sounds like you have a soap formatting issue. The java client isn't generating soap XML that makes sense to the WCF service. To get an idea of what the soap XML the service is expecting use the WcfTestClient command line app to call the service. This app dynamically creates a service proxy in a WinForm app. In the app, call the service operation and click the XML tab (next to the Formatted tab at the bottom of the right pane). You'll see both the request & response soap in this tab.
Next, configure the WCF service for message tracing and call it from the java client to see the soap XML it is being sent. Now you can compare the two soap messages to see what is different. The java client will need be configured to generate the soap format the WCF is expecting.
The WCF team recently released some WCF interop bindings specifically for java. These may not apply to your specific situation but they're probably worth reviewing.

Java client, SOAP and Exchange Web Services (EWS)

I'm working on creating a simple method that send SOAP request to EWS and it seems everything is OK. But when I run it I get error:
java.net.ProtocolException: Server
redirected too many times (20)
Any ideas why I get this when I try to connect to https://my.exchange.server/ews/Services.wsdl ?
Note: my.exchange.server is just a cover for my real URL
Make sure to enable Basic Authentication on EWS, sorry that's on the server side :).
I am using EWS Java Api http://archive.msdn.microsoft.com/ewsjavaapi and it works fine even cross domains:
ExchangeService service = new ExchangeService();
ExchangeCredentials credentials = new WebCredentials("Administrator#yourdomain.com", "Password",
"yourdomain.com");
service.setCredentials(credentials);
service.setUrl(new URI("http://yourserver/EWS/Exchange.asmx"));
service.setPreAuthenticate(true);
BTW, I am also successfully reaching it with plain SOAP using SoapUI, but the key factor is enabled Basic Authentication, and URL is "http://yourserver/EWS/Exchange.asmx"
Good luck,
Boris
Herndon, VA

Categories