Authenticate SOAP WebService - java

I'm trying to develop a SOAP WebService client in Java, and I'm unable to authenticate to it.
I have user and password from my provider and the wsdl is this:
https://www.ictower.net/Services/MasterService.svc?wsdl
With eclipse I generate the service clases and a Stub class, but when I try to authenticate, always get this message
An error occurred when verifying security for the message.
I have tried
IMasterServiceProxy ICTService = new IMasterServiceProxy();
MasterServiceLocator ICTLocator = new MasterServiceLocator();
URL urlServicio = new URL("https://www.ictower.net/Services/MasterService.svc");
BasicHttpBinding_IMasterServiceStub stub = new BasicHttpBinding_IMasterServiceStub(urlServicio, ICTLocator);
stub.setUsername("XXXXX");
stub.setPassword("XXXXX");
I also tried with _setProperty instead of the setters
stub._setProperty(BasicHttpBinding_IMasterServiceStub.USERNAME_PROPERTY, "XXXXX");
stub._setProperty(BasicHttpBinding_IMasterServiceStub.PASSWORD_PROPERTY, "XXXXX");
but always when I call any service method, always same return (error verifying security...)
I'm completly lost, I have expend hours trying and searching... Any help is welcome

Related

Security Token issue with WCF Service with wsHttpBinding Axis2 in Java Client

I have to use a WCF service in a Java client. I have generated proxy code using Axis2 library. I have successfully configured proxy classes but getting issue when calling WCF service method.
Following is the code in my java client.
ServiceXMLStub stub = new ServiceXMLStub("https://qa1-myservice.com/integration/ServiceXML.svc");
GetMetadata meta = new GetMetadata();
meta.setStateCode("WA");
meta.setUserName("tpstester1");
stub._getServiceClient().getOptions().setProperty(Constants.Configuration.MESSAGE_TYPE,HTTPConstants.MEDIA_TYPE_APPLICATION_ECHO_XML);
stub._getServiceClient().getOptions().setProperty(Constants.Configuration.DISABLE_SOAP_ACTION,Boolean.TRUE);
stub._getServiceClient().engageModule("addressing");
stub._getServiceClient().getOptions().setUserName("myuser");
stub._getServiceClient().getOptions().setPassword("myp#ssw0rd");
GetMetadataResponse response = stub.getMetadata(meta);
Following is the issue I am getting when calling this service from this client.
org.apache.axis2.AxisFault: The message could not be processed. This is most likely because the
action 'http://Integration.ContractsXML/IServiceXML/GetMetadata' 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.
I tested this code in .Net client and it works fine there
ServiceReference1.ServiceXMLClient serviceClient = new ServiceReference1.ServiceXMLClient();
serviceClient.ClientCredentials.UserName.UserName = "myuser";
serviceClient.ClientCredentials.UserName.Password = "myp#ssw0rd";
var result = serviceClient.GetMetadata("tpstester1", "SA");
What am I missing here ?

CA service DESK REST api using JAVA

Our infra team set up the ca service desk in machine and share the details. I need to make rest call to create the incident from java program. And here i want to use basic authentication by providing the access key. For this I tried to make the end point url to get the access key and after that to create incident as shown below.
http://Host:port/caisd-rest/rest_access
http://CAdeskHost:port/caisd-rest/in
String endpoint = "http://host:port/caisd-rest/rest_access";
HttpClient client = new HttpClient();
String encodedCredentials = new String(Base64.encodeBase64(("username" + ":" + "password").getBytes()));
PostMethod post = new PostMethod(endpoint);
post.addRequestHeader("Accept", "application/xml");
post.addRequestHeader("Content-Type", "application/xml; charset=UTF-8");
post.addRequestHeader("Authorization", "Basic " + encodedCredentials);
post.setRequestBody("<rest_access/>");
try {
System.out.println("Execute Basic Authentication request on " + endpoint);
// Execute request
int result = client.executeMethod(post);
But when I try to execute the above code, getting the 404 error
"The requested resource (/caisd-rest/rest_access) is not available".
Can any one please help me how to find the REST URL for ca service desk whether it is common url for all like /caisd-rest or it is different. Here my infra team just installed the CA service desk. So do we need to do any other steps to provide rest access?
Check in CA Technologies Website, it should be http://<host>:<REST port>/caisd-rest
I had the same issue, problem was that REST wasn't deployed properly, reconfiguring REST Service using this doc: REST API reconfiguration resolved the problem.
I folowed these steps:
Check for existence of NX_ROOT/bopcfg/www/CATALINA_BASE_REST/webapps/caisd-rest. If this directory does NOT exist, that's a very good indication that the REST deploy did not work properly.
Check for the errors in NX_ROOT/log/jrest.log file.
Try fix errors and redeploy REST Service using cmd:
pdm_rest_util -undeploy
pdm_rest_util -deploy

Unable to call webservice from Java in flex application

Hello I face some problem, I'm not able to to call webservice from java and send the result to flex side.
the process
the user launches the application and lands on an authentication form
The user enters login and password and submits the authentication form
Submission call on java side a remoteservice checkUserCredetialFromLdap()
inside this java method I try to call an external ldap webservice as shown below.
The class responsible for ldap ws call is in custom jar (Maven dependencies)
public User checkUserCredetialFromLdap(String identifiant, String password) throws EmmBusinessException, LdapServiceException{
User myUser = null;
User myCompleteUser = null;
//initialization of webservice with the endpoint URL failed
Axis1LdapWsAuth ws = new Axis1LdapWsAuth(Config.getProperties().getProperty("endpoint.url"));
try{
//authentication using webservice
String csif_sessionID =ws.login(identifiant, password);
....
}
}catch(LdapServiceException lse)
{
EmmBusinessException emmB = new EmmBusinessException(lse,this,"","Unable to get User",Level.WARNING);
log(emmB);
throw (emmB);
}
catch (Exception t) {
EmmBusinessException emmB = new EmmBusinessException(t,this,"","Unable to get User",Level.WARNING);
log(emmB);
throw (emmB);
} finally {
finish();
}
return myCompleteUser;
}
I know it's possible to call webservice on flex side using RPC, but I don't want to do that, but for some reason I need to and have to call webservice from java side.
is't possible ? How can I do that ?
I suggest you to:
Develop a kind of proxy ldap webservice whose will do the bridge between flex app and your custom ldap authentication process
Use HttpService from flex to send parameter to the proxy ldap
Use proxy ldap to consume the checkUserCredetialFromLdap api with parameter get from flex

CXF + wsdl2java + authentication

I created the jar from the WSDL for my client using the wsdl2java command. Now, I need to know how I can authenticate my client in order to complete an operation?
I am using CXF 2.7.16. I created my service using the generated class MyApp_Service, I am struggling with this. Isn't there a simple way to tell my client the credentials it should use to gain access to the web service?
I read about the Spring configuration, however I am unable to figure out if it applies to my case and how if yes. I tried to cast the MyApp_Service class to BindingProvider in order to use the method which consist to put the USERNAME and PASSWORD properties in the context with a value. However, MyApp_Service cannot be cast to BindingProvider.
This is my first web service client application ever. So, any help will be welcomed.
Update 2015-05-28: I tried to define the AuthenticationPolicy but is seems not working. Here is the code:
Client client = JaxWsDynamicClientFactory.newInstance().createClient(wsdlUrl);
ClientImpl clt = (ClientImpl) client;
HTTPConduit cc = (HTTPConduit) clt.getConduit();
org.apache.cxf.configuration.security.ObjectFactory secOF = new org.apache.cxf.configuration.security.ObjectFactory();
AuthorizationPolicy ap = secOF.createAuthorizationPolicy();
ap.setUserName(usagerWS);
ap.setPassword(mdpWS);
ap.setAuthorizationType("Basic");
cc.setAuthorization(ap);
Sniffing with WireShark, the Authorization header is clearly missing in the HTTP request.
What is missing?
Problem solved, here is the solution:
MyApp_Service service = new MyApp_Service(wsdlUrl, new QName(namespace, serviceName));
MyApp port = service.getMyApp();
// Set credentials
Map<String, Object> reqCtxt = ((javax.xml.ws.BindingProvider) port).getRequestContext();
reqCtxt.put(javax.xml.ws.BindingProvider.USERNAME_PROPERTY, username);
reqCtxt.put(javax.xml.ws.BindingProvider.PASSWORD_PROPERTY, password);
No more usage of the dynamic client. Only the classes generated with wsdl2java are used.

soap set parameter java

I am implementing a TV listing service and I have decided to use ROVI as my data provider.
They provide me with an API that allows me to exchange data between my application and their servers by means of SOAP requests.
Since I am programming in Java, I used wsimport to generate the classes that would enable me to interact with their server.
//Connection
service = new ListingsService();
port = service.getListingsServiceSoap();
I have come across a problem which Google doesn't seem to have the answer for.
According to their API, whenever I want to make a call to a SOAP service I have to add my API Key to the end of url.
The problem is, I don't know how to do that. Using the stubs generated by wsimport, I can create a request object as it should be; however the URL is not displayed as per their specification. The url I currently get is: http://api.rovicorp.com/v9/listingsservice.asmx and what is required is: http://api.rovicorp.com/v9/listingsservice.asmx?apikey=myAPIkey. I obtained that by printing the following code:
System.out.println(port.toString());
Trying to run the following code:
GetServicesRS servicesRS = port.getServices(getServicesRQ, auth)
Yields the following error:
Exception in thread "main" com.sun.xml.internal.ws.client.ClientTransportException: The server sent HTTP status code 403: Forbidden
What java method can I use to append this parameter into the SOAP request URL.
Thanks for your help.
Edit.
I am still struggling with this and haven't been lucky with responses, if anyone could point me in the direction of a framework or something that could facilitate this would be great!
Cheers
I manage to work around my problem using something called BindingProvider.
I added the following to my code:
//Connection
service = new ListingsService();
port = service.getListingsServiceSoap();
BindingProvider bindingProvider = (BindingProvider) port;
bindingProvider.getRequestContext()
.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
"http://api.rovicorp.com/v9/listingsservice.asmx?apikey=" + APIKey);
With the aforementioned code the call to the API is successful:
GetServicesRS servicesRS = port.getServices(getServicesRQ, auth)
Hope it helps someone in the future.

Categories

Resources