1 Reply Latest reply: Oct 23, 2012 12:05 PM by 965123 RSS

    web service authentication possible? Hoping for example code.

    944929
      I have a need to authenticate to a web service using a java console app. I have a working sample in perl, but I'd really like to do it with a java app. I've done a lot of searching on google and most of the stuff I've found seems very complicated. Maybe it just is tougher to do in java?.?.

      Can anyone point me to some sample code for this? The whole goal is to simply verify authentication to the web service, which means the site is working correctly.

      Thanks in advance.
      James

      perl code:

      use SOAP::Lite;

      $userName = "username";
      $password = "password";
      $url = "https://portal.company.com";

      ## Define the urls to the wsdl
      $wsdlPathCore = "$url/swWebServices/services/WebNetworkCoreService?wsdl";
      $wsdlPathPortal = "$url/swWebServices/services/WebNetworkPortalService?wsdl";
      $wsdlPathVersion = "$url/swWebServices/services/Version?wsdl";

      ## Connect and ask the server for its version using the Version service
      print "Getting server version \n";
      $ServerVersion = SOAP::Lite->proxy( $wsdlPathVersion )
      ->uri('http://soap.stoneware.com')
      ->soapversion('1.2')
      ->envprefix('soap12')
      ->readable(true)
      ->getVersion()
      ->result;

      ## Connect to the Core service
      print "Connecting to Core Service \n";
      $CoreService = SOAP::Lite->proxy( $wsdlPathCore )
      ->uri('http://soap.stoneware.com')
      ->soapversion('1.2')
      ->envprefix('soap12')
      ->readable(true);

      ## Get the sessionID
      $sessionID = $CoreService->authenticateUserNoContext( $userName, $password )
      ->result;

      ## Ask what version of soap we are speaking.
      $soapversion = $CoreService->soapversion;

      ## Connect to the Portal service
      print "Connecting to Portal Service \n";
      $portalService = SOAP::Lite->proxy( $wsdlPathPortal )
      ->uri('http://soap.stoneware.com')
      ->soapversion('1.2')
      ->envprefix('soap12')
      ->readable(true);

      print "\n";
      print "Soap Version : $soapversion \n";
      print "Server Version : $ServerVersion \n";
      print "\n";
      print "Your sessionID is $sessionID \n";

      $CoreService->voidUserSession( $sessionID );

      Edited by: jpifer on Oct 19, 2012 2:22 PM
        • 1. Re: web service authentication possible? Hoping for example code.
          965123
          Web services can be secured in many different ways. They are not Java specific. In terms of standards, we have WS-Security, WS-SecurityPolicy and they for themselves leads to many different configurations.

          While I am not familiar with Perl, I see that you are invoking two methods authenticateUserNoContext() and voidUserSession() of the web service you have identified as the core service. This probably indicates that you are not using any of the standard (WS-*) security approaches. Hence, just use wsimport tool and generate the web service stub code. You might just be able to use the generated code without any further configuration.