on Windows
cordova plugin add kapsel-plugin-logon --searchpath %KAPSEL_HOME%/plugins
on a Mac
cordova plugin add kapsel-plugin-logon --searchpath $KAPSEL_HOME/plugins
cordova plugin add cordova-plugin-dialogs
cordova plugin remove plugin_id
cordova plugins
cordova-plugin-device 1.1.6 "Device"
cordova-plugin-dialogs 1.3.3 "Notification"
cordova-plugin-whitelist 1.3.2 "Whitelist"
kapsel-plugin-authproxy 3.15.2 "AuthProxy"
kapsel-plugin-corelibs 3.15.2 "CoreLibs"
kapsel-plugin-i18n 3.15.2 "i18n"
kapsel-plugin-inappbrowser 3.15.2 "InAppBrowser"
kapsel-plugin-logon 3.15.2 "Logon"
kapsel-plugin-ui5 3.15.2 "ui5"
C:\Kapsel_Projects\KapselGSDemo\plugins\kapsel-plugin-logon\plugin.xml
<!DOCTYPE html>
<html>
<head>
<!--<meta http-equiv="Content-Security-Policy" content="default-src http://10.7.171.234:8080 'self' 'unsafe-inline' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *">-->
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
<script type="text/javascript" charset="utf-8" src="datajs-1.1.2.min.js"></script>
<script type="text/javascript" charset="utf-8" src="serverContext.js"></script>
<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
<script>
var t0 = Number(location.href.split("startTime=")[1]); //Time passed in from main activity.
var t1 = performance.now();
var t2; //onLoad
var t3; //deviceready
var readStartTime;
var logonInitTime;
var unlockTime;
var resumeTime;
var applicationContext = null;
window.onerror = onError;
function onError(msg, url, line) {
var idx = url.lastIndexOf("/");
var file = "unknown";
if (idx > -1) {
file = url.substring(idx + 1);
}
alert("An error occurred in " + file + " (at line # " + line + "): " + msg);
return false; //suppressErrorAlert;
}
function init() {
updateStatus2("EventLogging: deviceready called");
t3 = performance.now();
console.log("EventLogging Perf: " + ((t3 - t1)/1000).toFixed(3) + " seconds from onLoad until deviceready");
if (sap.Logger) {
sap.Logger.setLogLevel(sap.Logger.DEBUG); //enables the display of debug log messages from the Kapsel plugins.
sap.Logger.debug("EventLogging: Log level set to DEBUG");
}
if (navigator.notification) { // Override default HTML alert with native dialog. alert is not supported on Windows
window.alert = navigator.notification.alert;
}
register();
}
function logonSuccessCallback(result) {
updateStatus2("logonSuccessCallback called");
var endTime = performance.now();
var endTime2 = new Date();
console.log("EventLogging Perf: " + ((endTime - logonInitTime)/1000).toFixed(3) + " seconds for logon.init to complete");
console.log("EventLogging Perf: " + ((endTime - t1)/1000).toFixed(3) + " seconds from onload till datavault is unlocked");
console.log("EventLogging Perf: " + ((endTime2 - t0)/1000).toFixed(3) + " seconds from main activity till datavault is unlocked. Requires modifying MainActivity.java"); //loadUrl(launchUrl + "?startTime=" + new java.util.Date().getTime());
console.log("EventLogging: logonSuccessCallback " + JSON.stringify(result));
applicationContext = result;
showScreen("MainDiv");
}
//used when the logon plugin does not register with a server
function logon2SuccessCallback(result) {
console.log("EventLogging: logon2SuccessCallback " + JSON.stringify(result));
applicationContext = result;
applicationContext.applicationEndpointURL = "https://sapes4.sapdevcenter.com/sap/opu/odata/IWFND/RMTSAMPLEFLIGHT";
showScreen("MainDiv");
}
function logonErrorCallback(error) { //this method is called if the user cancels the registration.
alert("An error occurred: " + JSON.stringify(error));
if (device.platform == "Android") { //Not supported on iOS
navigator.app.exitApp();
}
}
function read() {
updateStatus2("Read request started");
readStartTime = performance.now();
if (!applicationContext) {
alert("Register or unlock before proceeding");
return;
}
clearTable();
sUrl = applicationContext.applicationEndpointURL + "/CarrierCollection?$format=json"; //JSON format is less verbose than atom/xml
var oHeaders = {};
//oHeaders['X-SMP-APPCID'] = applicationContext.applicationConnectionId; //not needed as this will be sent by the logon plugin
var request = {
headers : oHeaders,
requestUri : sUrl,
method : "GET"
};
if (device.platform == "windows") { //provided by the authproxy and logon plugins on Android and iOS but not on Windows
request.user = applicationContext.registrationContext.user;
request.password = applicationContext.registrationContext.password;
}
OData.read(request, readSuccessCallback, errorCallback);
}
function readSuccessCallback(data, response) {
var endTime = performance.now();
updateStatus2("Read " + data.results.length + " records in " + ((endTime - readStartTime)/1000).toFixed(3) + " seconds");
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 errorCallback(e) {
alert("An error occurred: " + JSON.stringify(e));
showScreen("MainDiv");
}
function register() {
logonInitTime = performance.now();
updateStatus2("Calling Logon.init");
sap.Logon.init(logonSuccessCallback, logonErrorCallback, appId, context);
//sap.Logon.initPasscodeManager(logon2SuccessCallback, errorCallback, appId); //initialize the datavault without registering with an SMP server
}
function unRegister() {
updateStatus2("Calling deleteRegistration");
showScreen("LoadingDiv");
sap.Logon.core.deleteRegistration(logonUnregisterSuccessCallback, errorCallback);
//sap.Logon.deletePasscodeManager(logonUnregisterSuccessCallback, errorCallback); //Used when the datavault is initialized with initPasscodeManager
clearTable();
}
function logonUnregisterSuccessCallback(result) {
updateStatus2("Successfully Unregistered");
console.log("EventLogging: logonUnregisterSuccessCallback " + JSON.stringify(result));
applicationContext = null;
register();
}
function lock() {
sap.Logon.lock(logonLockSuccessCallback, errorCallback);
clearTable();
}
function logonLockSuccessCallback(result) {
console.log("EventLogging: logonLockSuccessCallback " + JSON.stringify(result));
showScreen("LockedDiv");
}
function unlock() {
unlockTime = performance.now();
sap.Logon.unlock(unlockSuccessCallback, errorCallback);
}
function unlockSuccessCallback(result) {
updateStatus2("unLockSuccessCallback called");
var endTime = performance.now();
console.log("EventLogging Perf: " + ((endTime - unlockTime)/1000).toFixed(3) + " seconds to unlock the datavault");
showScreen("MainDiv");
}
function managePasscode() {
sap.Logon.managePasscode(managePasscodeSuccessCallback, errorCallback);
}
function managePasscodeSuccessCallback() {
console.log("EventLogging: managePasscodeSuccess");
}
function showScreen(screenIDToShow) {
var screenToShow = document.getElementById(screenIDToShow);
screenToShow.style.display = "block";
var screens = document.getElementsByClassName('screenDiv');
for (var i = 0; i < screens.length; i++) {
if (screens[i].id != screenToShow.id) {
screens[i].style.display = "none";
}
}
}
function updateStatus2(msg) {
var d = new Date();
document.getElementById('statusID2').innerHTML = msg + " at " + addZero(d.getHours()) + ":" + addZero(d.getMinutes()) + ":" + addZero(d.getSeconds());
console.log("EventLogging: " + msg + " at " + addZero(d.getHours()) + ":" + addZero(d.getMinutes()) + ":" + addZero(d.getSeconds() + "." + addZero(d.getMilliseconds())));
}
function addZero(input) {
if (input < 10) {
return "0" + input;
}
return input;
}
function onLoad() {
console.log("EventLogging: onLoad");
t2 = performance.now();
var endTime = new Date();
console.log("EventLogging Perf: " + ((endTime - t0)/1000).toFixed(3) + " seconds between MainActivity and onLoad");
}
function onBeforeUnload() {
console.log("EventLogging: onBeforeUnLoad");
}
function onUnload() {
console.log("EventLogging: onUnload");
}
function onPause() {
console.log("EventLogging: onPause");
}
function onResume() {
resumeTime = performance.now();
console.log("EventLogging: onResume");
}
function onSapResumeSuccess() {
console.log("EventLogging: onSapResumeSuccess");
var endTime = performance.now();
console.log("EventLogging Perf: " + ((endTime - resumeTime)/1000).toFixed(3) + " seconds from onresume to onSapResumeSuccess");
}
function onSapLogonSuccess() {
console.log("EventLogging: onSapLogonSuccess");
}
function onSapResumeError(error) {
console.log("EventLogging: onSapResumeError " + JSON.stringify(error));
}
document.addEventListener("deviceready", init, false);
document.addEventListener("pause", onPause, false);
document.addEventListener("resume", onResume, false);
document.addEventListener("onSapResumeSuccess", onSapResumeSuccess, false);
document.addEventListener("onSapLogonSuccess", onSapLogonSuccess, false);
document.addEventListener("onSapResumeError", onSapResumeError, false);
</script>
</head>
<body onload="onLoad()" onunload="onUnload()" onbeforeunload="onBeforeUnload()">
<div class="screenDiv" id="LoadingDiv">
<h1>Loading ...</h1>
</div>
<div class="screenDiv" id="LockedDiv" style="display: none">
<h1>Locked</h1>
<button id="unlock2" onclick="unlock()">Unlock</button>
</div>
<div class="screenDiv" id="MainDiv" style="display: none">
<h1>Logon Sample</h1>
<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>
<button id="managePasscode" onclick="managePasscode()">Manage Passcode</button><br>
<span id="statusID2"></span>
<table id="carrierTable"><tr><th>Carrier ID</th><th>Carrier Name</th></tr></table>
</div>
</body>
</html>
var appId = "com.kapsel.gs"; // Change this to app id on server
// Optional initial connection context
var context = {
//"serverHost": "10.7.168.212", //Place your SMP 3.0 server name here
"serverHost": "hcpms-XXXXXXXtrial.hanatrial.ondemand.com", //SAP Cloud Platform Mobile Services
"https": true,
"serverPort": "443", //443 for SAP Cloud Platform Mobile Services, may be different for an on premise SAP Mobile Platform server
//"multiUser": true,
//"useLocalStorage": false,
"user": "i82XXXX", //For demo purposes, specify the user name and password you wish to register with here to save typing on the device
"password": "XXXXX", //Note, if you wish to use this user name and password to be passed to the backend OData producer, choose Basic as the SSO mechanism
//The AuthProxy plugin with the Logon plugin can respond to 401 Authentication challenges if the same credentials used to register are also used to make OData requests
//Once set the credentials can be changed by calling sap.Logon.changePassword()
"passcode": "password", //Hardcoding passwords and unlock passcodes are strictly for ease of use during development
//Passcode can be changed by calling sap.Logon.managePasscode()
"unlockPasscode": "password",
"passcode_CONFIRM": "password",
"oldPasscode" : "password",
"communicatorId": "REST",
//"auth": [ { "type": "saml2.web.post" } ], //Indicates that a redirect to a SAML IDP should be used for registration
//"refreshSAMLSessionOnResume": "skip", // Useful for offline apps when you may not wish for a saml check to be performed when the app is resumed since you may be offline
"custom": {
"hiddenFields": ["farmId", "resourcePath", "securityConfig", "serverPort", "https"]
}
};
function logonSuccessCallback(result) {
...
applicationContext = result;
showScreen("MainDiv")
}
<preference name="windows-target-version" value="10.0" />
cordova run android
or
cordova run windows -- --archs=x64
or
cordova run windows --device -- --archs=arm --phone
or
cordova run ios
cordova prepare
adb shell input text some_text_to_enter
var context = {
"serverHost": "10.7.186.3", //Place your SMP 3.0 server name here
"https": "false",
"serverPort": "8080",
"custom": {
"hiddenFields": ["farmId", "resourcePath", "securityConfig", "serverPort", "https"]
}
};
adb -e emu finger touch 1
adb -e emu finger touch 1
http://SMP_Server_IP_Address:8080/sapui5/ or http://SMP_Server_IP_Address:8080
C:\SAP\MobileSDK3\KapselSDK\plugins\logon\www\common\assets\ui\iab.html
C:\Kapsel_Projects\KapselGSDemo\www\resources\sap-ui-core.js
src="../../../resources/sap-ui-core.js"
to
src="https://sapui5.hana.ondemand.com/resources/sap-ui-core.js"
C:\SAP\MobileSDK3\KapselSDK\plugins\logon\www\common\assets\i18n\i18n_en.properties
cordova plugin remove kapsel-plugin-logon
cordova plugin add kapsel-plugin-logon --searchpath %KAPSEL_HOME%/plugins
cordova run android
var context = {
"serverHost": "10.7.168.124", //Place your SMP 3.0 server name here
"https": "false",
"serverPort": "8080",
"custom": {
"hiddenFields": ["farmId", "resourcePath", "securityConfig", "serverPort", "https"],
"backgroundImage": "../../../nightsky.jpg",
"copyrightLogo":"../../../logo.png",
"styleSheet": "../../../custom.css",
"copyrightMsg": ["Copyright @2016 Mycompany Inc.", "All rights reserved."],
"hideLogoCopyright" : false,
"disablePasscode": true
}
}
};
/* company logo */
#panel_footer_hbox > .sapMFlexItem:not(#copyright) {
/* uncomment to hide logo */
/*display: none;*/
/* uncomment to right align logo */
/*position: absolute;
right: 0px;*/
}
#logo {
/* change size of logo */
height: 40px !important;
}
/* copyright message */
#copyright{
/* uncomment to hide copyright message */
/*visibility: hidden;*/
/* uncomment to right align text */
/*text-align: right;*/
/* uncomment to left align copyright message */
/*left: 0px;*/
}
/* copyright message first line */
#copyright1{
/* change text color */
color: white;
/* change text size */
font-size: 20px;
}
/* copyright message second line */
#copyright2 {
/* change text color */
color: yellow;
cordova run android
or
cordova run windows -- --archs=x64
or
cordova run ios
C:\Kapsel_Projects\KapselGSDemo\platforms\android\src\com\kapsel\gs\MainActivity.java
//loadUrl(launchUrl);
loadUrl(launchUrl + "?startTime=" + new java.util.Date().getTime());
"useLocalStorage": true,
var operation = {};
var appConfig = {};
appConfig.appID = appId;
appConfig.isForSMP = true;
appConfig.certificate = "com.sap.SystemCertProvider";
//appConfig.certificate = "com.sap.x509filecertprovider"; //iOS
//appConfig.certificate = "com.sap.keychaincertprovider"; //iOS
var context2 = {};
context2.smpConfig = context;
context2.appConfig = appConfig;
context2.operation = operation;
var appDelegate = {
onRegistrationSuccess: logonSuccessCallback,
onRegistrationError: logonErrorCallback,
};
operation.logonView = sap.logon.LogonJsView;
sap.Logon.startLogonInit(context2, appDelegate);
sap.Logon.core.reset()
keytool -import -trustcacerts -alias sapsso -file c:\certs\SSO_CA.cer -keystore hcpms_trusted_ca.jks
neo.bat upload-keystore --account i8XXXXtrial --application sapmobile:hcpms --user i82XXXX --location ./hcpms_trusted_ca.jks --host hanatrial.ondemand.com
var appConfig = {};
appConfig.appID = appId;
appConfig.isForSMP = true;
var operation = {};
var context2 = {};
context2.smpConfig = context;
context2.appConfig = appConfig;
context2.operation = operation;
var appDelegate = {
onRegistrationSuccess: logonSuccessCallback,
onRegistrationError: logonErrorCallback,
};
operation.logonView = sap.logon.LogonJsView;
sap.Logon.startLogonInit(context2, appDelegate);
function signOutSuccessCallback() {
console.log("signOutSuccess");
unlock(); //shows the pick user screen
}
<button id="signOut" onclick="sap.logon.Core.deactivateCurrentUser(signOutSuccessCallback, errorCallback)">Sign Out</button>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
12 | |
11 | |
10 | |
9 | |
8 | |
7 | |
6 | |
5 | |
5 | |
5 |