Chilkat Examples

ChilkatHOMEAndroid™Classic ASPCC++C#Mono C#.NET Core C#C# UWP/WinRTDataFlexDelphi ActiveXDelphi DLLVisual FoxProJavaLianjaMFCObjective-CPerlPHP ActiveXPHP ExtensionPowerBuilderPowerShellPureBasicCkPythonChilkat2-PythonRubySQL ServerSwift 2Swift 3/4TclUnicode CUnicode C++Visual Basic 6.0VB.NETVB.NET UWP/WinRTVBScriptXojo PluginNode.jsExcelGo

Android™ Examples

Web API Categories

ASN.1
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Service Bus
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Compression
DKIM / DomainKey
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
ECC
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
Geolocation
Google APIs
Google Calendar
Google Cloud Storage
Google Drive
Google Photos
Google Sheets
Google Tasks
Gzip
HTML-to-XML/Text

HTTP
HTTP Misc
IMAP
JSON
JSON Web Encryption (JWE)
JSON Web Signatures (JWS)
JSON Web Token (JWT)
Java KeyStore (JKS)
MHT / HTML Email
MIME
Microsoft Graph
NTLM
OAuth1
OAuth2
OneDrive
OpenSSL
Outlook
PEM
PFX/P12
POP3
PRNG
REST
REST Misc
RSA Encryption
SCP
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
SharePoint
Socket/SSL/TLS
Spider
Stream
Tar Archive
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl

 

 

 

(Android™) SOAP WS-Security Username Authentication

Demonstrates creating SOAP XML for WS-Security Username Authentication. The client user name and password are encapsulated in a WS-Security <wsse:UsernameToken>.

Chilkat Android™ Downloads

Android™ Java Libraries

Android C/C++ Libraries

// Important: Don't forget to include the call to System.loadLibrary
// as shown at the bottom of this code sample.
package com.test;

import android.app.Activity;
import com.chilkatsoft.*;

import android.widget.TextView;
import android.os.Bundle;

public class SimpleActivity extends Activity {

  private static final String TAG = "Chilkat";

  // Called when the activity is first created.
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    //  Generate this XML with the code that follows:

    //  	<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    //  	 <soap:Header>
    //  	  <wsse:Security xmlns:wsse="http://schemas.xmlsoap.org/ws/2003/06/secext">
    //  	   <wsse:UsernameToken wsu:Id="sample"
    //  	       xmlns:wsu="http://schemas.xmlsoap.org/ws/2003/06/utility">
    //  	    <wsse:Username>sample</wsse:Username>
    //  	    <wsse:Password Type="wsse:PasswordText">oracle</wsse:Password>
    //  	    <wsu:Created>2004-05-19T08:44:51Z</wsu:Created>
    //  	   </wsse:UsernameToken>
    //  	  </wsse:Security>
    //  	  <wsse:Security soap:actor="oracle"
    //  	      xmlns:wsse="http://schemas.xmlsoap.org/ws/2003/06/secext">
    //  	   <wsse:UsernameToken wsu:Id="oracle"
    //  	       xmlns:wsu="http://schemas.xmlsoap.org/ws/2003/06/utility">
    //  	    <wsse:Username>myUsername</wsse:Username>
    //  	    <wsse:Password Type="wsse:PasswordText">myPassword</wsse:Password>
    //  	    <wsu:Created>2004-05-19T08:46:04Z</wsu:Created>
    //  	   </wsse:UsernameToken>
    //  	  </wsse:Security>
    //  	 </soap:Header>
    //  	  <soap:Body>
    //  	   <getHello xmlns="http://www.oracle.com"/>
    //  	  </soap:Body>
    //  	</soap:Envelope>
    // 

    //  First build the outer housing:
    CkXml xml = new CkXml();
    xml.put_Tag("soap:Envelope");
    xml.AddAttribute("xmlns:soap","http://schemas.xmlsoap.org/soap/envelope/");
    xml.UpdateChildContent("soap:Header","");
    xml.UpdateAttrAt("soap:Body|getHello",true,"xmlns","http://www.oracle.com");

    //  Get the current date/time in a string with this format: 2004-05-19T08:46:04Z
    CkDateTime dt = new CkDateTime();
    dt.SetFromCurrentSystemTime();
    boolean bLocal = false;
    String created = dt.getAsTimestamp(bLocal);

    //  Now build each UsernameToken block:
    CkXml wsse1 = new CkXml();
    wsse1.put_Tag("wsse:Security");
    wsse1.AddAttribute("xmlns:wsse","http://schemas.xmlsoap.org/ws/2003/06/secext");
    wsse1.UpdateAttrAt("wsse:UsernameToken",true,"wsu:Id","sample");
    wsse1.UpdateAttrAt("wsse:UsernameToken",true,"xmlns:wsu","http://schemas.xmlsoap.org/ws/2003/06/utility");
    wsse1.UpdateChildContent("wsse:UsernameToken|wsse:Username","sample");
    wsse1.UpdateAttrAt("wsse:UsernameToken|wsse:Password",true,"Type","wsse:PasswordText");
    wsse1.UpdateChildContent("wsse:UsernameToken|wsse:Password","oracle");
    wsse1.UpdateChildContent("wsse:UsernameToken|wsu:Created",created);

    CkXml wsse2 = new CkXml();
    wsse2.put_Tag("wsse:Security");
    wsse2.AddAttribute("soap:actor","oracle");
    wsse2.AddAttribute("xmlns:wsse","http://schemas.xmlsoap.org/ws/2003/06/secext");
    wsse2.UpdateAttrAt("wsse:UsernameToken",true,"wsu:Id","oracle");
    wsse2.UpdateAttrAt("wsse:UsernameToken",true,"xmlns:wsu","http://schemas.xmlsoap.org/ws/2003/06/utility");
    wsse2.UpdateChildContent("wsse:UsernameToken|wsse:Username","oracle");
    wsse2.UpdateAttrAt("wsse:UsernameToken|wsse:Password",true,"Type","wsse:PasswordText");
    wsse2.UpdateChildContent("wsse:UsernameToken|wsse:Password","oracle");
    wsse2.UpdateChildContent("wsse:UsernameToken|wsu:Created",created);

    //  Insert the UsernameToken blocks:
    CkXml xHeader = xml.GetChildWithTag("soap:Header");
    xHeader.AddChildTree(wsse1);
    xHeader.AddChildTree(wsse2);

    //  Show the XML:
    Log.i(TAG, xml.getXml());

  }

  static {
      System.loadLibrary("chilkat");

      // Note: If the incorrect library name is passed to System.loadLibrary,
      // then you will see the following error message at application startup:
      //"The application <your-application-name> has stopped unexpectedly. Please try again."
  }
}

 

© 2000-2019 Chilkat Software, Inc. All Rights Reserved.