Developer

Preparing the Hybrid SDK (Kapsel) Application for Afaria Provisioning

To prepare the Hybrid SDK (Kapsel) application to be provisioned through Afaria, provide an initial context to the Login plugin, and specify an application ID configured on SAP Mobile Platform Server with an X.509 security profile.

Context

Specify information needed for provisioning in these files:

  • The clienthub.properties file (for Android) or clienthub.plist file (for iOS) provide an initial context to the Login plugin and instruct the Login plugin that it is to use a certificate from Afaria for authentication.
  • The index.html file specifies an application ID that must match an application ID on the SAP Mobile Platform Server that is configured with a security profile for X.509 authentication.
  • The MAFLogonManagerOptions.plist file contains the setting, keyMAFUseAfaria, that affects the logon page when Afaria installed on a device.

Procedure

  1. Create an index.html which specifies an application ID that is configured on SAP Mobile Platform Server with a security profile for X.509 authentication. The following is a sample index.html:
    <html>
        <head>
            <script src="datajs-1.1.1beta2.js"></script>
            <script type="text/javascript" charset="utf-8" src="cordova.js"></script>
            <script>
                applicationContext = null;
                var appID = "certAuth"; // Change this to app id on server
                
                function init() {
                    
                    // Optional initial connection context
                    var context = {
                        "serverHost": "example.corp", //Place your SMP 3.0 server name here
                        "https": "false",
                        "serverPort": "8080",
                        "user": "username", //Place your user name for the OData Endpoint here
                        "password": "xxxxxxx",  //Place your password for the OData Endpoint here
                        "communicatorId": "REST",
                        "passcode": "password",
                        "unlockPasscode": "password"
                    };
                    sap.Logon.init(logonSuccessCallback, errorCallback, appID, context, sap.logon.IabUi);
                    console.log("init completed");
                }
            
                function read() {
                    var url = applicationContext.applicationEndpointURL;
    				var logonCert = new sap.AuthProxy.CertificateFromLogonManager(appID);
    				var headers = {};
    				headers["X-SMP-APPCID"]=applicationContext.applicationConnectionId;
    				var errorCB = function(errorInfo){
    					alert("error: " + JSON.stringify(errorInfo));
    				}
    				var successCB = function(result){
    					alert("success: " + JSON.stringify(result));
    				}
    		
    				sap.AuthProxy.get(url,headers,successCB,errorCB,null,null,null,logonCert);
                }
                
                function readSuccessCallback(data, response) {
    				alert("success: " + JSON.stringify(data));
                    /*var carrierTable = document.getElementById("carrierTable");
                    
                    for (var i = data.results.length -1; i >= 0; i--) {
                        var row = carrierTable.insertRow(1);
                        var cell1 = row.insertCell(0);
                        var cell2 = row.insertCell(1);
                        cell1.innerHTML = data.results[i].carrid;
                        cell2.innerHTML = data.results[i].CARRNAME;
                    }*/
                }
                
                function clearTable() {
                    var carrierTable = document.getElementById("carrierTable");
                    while(carrierTable.rows.length > 1) {
                        carrierTable.deleteRow(1);
                    }
                }
                
                function logonSuccessCallback(result) {
                    console.log("logonSuccessCallback " + JSON.stringify(result));
                    if (result) {  //calling registerOrUnlock returns null the second time it is called.
                        applicationContext = result;
                    }
                }
                
                function logonLockSuccessCallback(result) {
                    console.log("logonLockSuccessCallback " + JSON.stringify(result));
                    applicationContext = null;
                }
                
                function logonUnregisterSuccessCallback(result) {
                    console.log("logonUnregisterSuccessCallback " + JSON.stringify(result));
                    applicationContext = null;
                }
                
                function register() {
                    sap.Logon.registerOrUnlock(logonSuccessCallback, errorCallback);
                }
                
                function unRegister() {
                    sap.Logon.core.deleteRegistration(logonUnregisterSuccessCallback, errorCallback);
                    clearTable();
                }
                
                function lock() {
                
                function errorCallback(e) {
                    alert("An error occurred");
                    alert(JSON.stringify(e));
                }
                    sap.Logon.lock(logonLockSuccessCallback,errorCallback);
                    clearTable();
                }
                
                function unlock() {
                    sap.Logon.unlock(logonSuccessCallback,errorCallback);
                }
                
                document.addEventListener("deviceready", init, false);
                
                </script>
            
        </head>
        <body>
            <h1>Logon Sample</h1>
            <button id="register" onclick="register()">Register</button>
            <button id="read" onclick="read()">Read</button>
            <button id="unregister" onclick="unRegister()">Unregister</button>
            <button id="lock" onclick="lock()">Lock</button>
            <button id="unlock" onclick="unlock()">Unlock</button>
            <table id="carrierTable"><tr><th>Carrier ID</th><th>Carrier Name</th></tr></table>
        </body>
    </html>
    
  2. In the MAFLogonManagerOptions.plist file verify that the value of the keyMAFUseAfaria setting is NO to support the display of the logon screen in the Hybrid SDK (Kapsel) application.