Implementing Auto Log-on
Perform the following steps to enable Auto Log-on for the Child App:
Select the SSO provider for your Parent and Child apps. For example, ARX.
The procedure is explained by using a sample property file called ARXTicketValidationStatus.properties file as the ARX SSO provider.
This property file contains the following details:
#Mon Jun 12 11:54:34 IST 2017 STATUS=SUCCESS SHOULDLOGINTOARX=true USERPIN=canvas ARMORTICKET=919874-RO9NL LOGINID=terrim
The SSO provider selected by you will replace this dummy properties file.
- Read the services offered by the SSO provider and select the services that you want for your Parent and Child Apps.
- Create a custom authentication provider by implementing the Java Interface, IAuthenticationServiceProvider.
Mention the authentication provider to Canvas framework by providing a value for the AUTH_SERV_PROV_CLASS key in the securityconfig.properties file.
Here, CTAutoLoginAuthenticationProvider.java is the custom authentication provider file created for the ARX SSO.# The following key indicates the default authentication provider that is to # be used during log-in, log-out or re-authentication purposes. AUTH_SERV_PROV_CLASS=com.intellectdesign.modelhouse.CTAutoLoginAuthenticationProvider
- Refer the CTAutoLoginAuthenticationProvider.java file for the sample implementation of the ARX SSO.
- You will be using a real SSO provider and therefore, you must properly read and understand the SSO services and consume it accordingly instead of reading and writing the dummy properties file.
- Few changes are required in the Parent and Child Apps' JavaScript files to retrieve and set the armor cookie. Sample codes with respect to the CTAutoLoginAuthenticationProvider.java file and the ARX SSO provider - ARXTicketValidationStatus.properties file is provided for your reference.
- In the Parent App's Hybrid.js file, add the following methods:
getArmorTicket() – This method retrieves the armor cookie from the Parent App for the Parent App server.
function getArmorTicket(armorSuccessCallBack) { cookieMaster.getCookieValue(localStorage.getItem("appUrl"),'ArmorTicket', function(cookie) { armorSuccessCallBack.apply(this, [cookie.cookieValue]); }, function(error) { if(error) { console.log('error: '+ error); } }); }
setArmorTicket() – This method sets the retrieved armor cookie to the Child App server.
function setArmorTicket() { var armorTicket = localStorage.getItem("ArmorTicket"); cookieMaster.setCookieValue(localStorage.getItem("appUrl"),'ArmorTicket', armorTicket, function() { console.log('Armor cookie has been set'); }, function(error) { console.log('Error setting cookie: '+ error); }); }
launchChildApp() – This method launches the Child App.
function launchChildApp() { if(!cbx.isEmpty(iportal.workspace.metadata.getCurrentWorkspaceId())) { localStorage.setItem("Parent_WSID", iportal.workspace.metadata.getCurrentWorkspaceId()); var strUrl ="http://172.19.32.28:9080/ctmodelhouse/"; localStorage.setItem("appUrl", strUrl); setArmorTicket(); window.location ="www/CTHome.html"; } }
- In the Child App's Hybrid.js, add the following methods:
getArmorTicket() - This method retrieves the armor cookie from the Child App for the Child App server.
function getArmorTicket(armorSuccessCallBack) { cookieMaster.getCookieValue(localStorage.getItem("appUrl"),'ArmorTicket', function(cookie) { armorSuccessCallBack.apply(this, [cookie.cookieValue]); }, function(error) { if(error) { console.log('error: '+ error); } }); }
setArmorTicket() - This method sets the retrieved armor cookie to the Parent App server.
function setArmorTicket() { var armorTicket = localStorage.getItem("ArmorTicket"); cookieMaster.setCookieValue(localStorage.getItem("appUrl"),'ArmorTicket', armorTicket, function() { console.log('Armor cookie has been set'); }, function(error) { console.log('Error setting cookie: '+ error); }); }
launchParentApp() - This method launches the Parent App.
function launchParentApp() { var strUrl ="http://172.19.32.38:9080/ctmodelhouse/"; localStorage.setItem("appUrl",strUrl); setArmorTicket(); window.location ="../../www/CTHome.html"; }
- In the Parent App's Hybrid.js file, add the following methods:
If the Parent and Child Apps are both built on different versions of Canvas framework and if both the apps use the same context root, for example 'ctmodelhouse', the SQLite database name for both Parent and Child App will be 'CTM' in the CTRIA framework. This will lead to overriding of Parent App metadata with the metadata of the Child Apps and vice versa due to which there will be inconsistency in the data loaded offline. To avoid this provide a different name instead of 'CTM' for the Child App SQLite database.