cancel
Showing results for 
Search instead for 
Did you mean: 

Handling session Timeout in SAP HANA Cloud Portal

sahud
Participant
0 Kudos

Hi Experts,

I am working with HCP Portal SAPUI5 apps. I need to check the session before every data call is made to the backend so I can redirect the user back to the logon page.

In the HANA Cloud documentation, the below code is provided:

jQuery(document).ajaxComplete(function(e, jqXHR) {
  if (jqXHR.getResponseHeader("com.sap.cloud.security.login")) {
    alert("Session is expired, page shall be reloaded.");
    jQuery.sap.delayedCall(0, this, function() {
      location.reload(true);
    });
  }
});

Does the above code only works for both Ajax and oData calls. We want to redirect the user in every case to the logon page after session expiry.

Is there a direct method to achieve it both for oData calls and Ajax calls?

Accepted Solutions (1)

Accepted Solutions (1)

0 Kudos

Hi Deepak,

check the JSDoc of sap.ui.model.odata.ODataModel or sap.ui.model.odata.v2.ODataModel or newer if you are already using it.

In any case you will see a list of events you could add an event handler to. One try could be the requestFailed, which could be added like:

var oModel = new sap.ui.model.odata.ODataModel(...);
oModel.attachRequestFailed(this.handleRequestFailed, this);

Define the handler like:

handleRequestFailed: function(oEvent) {
    console.log(oEvent);
}

Answers (1)

Answers (1)

boaz_wimmer
Explorer
0 Kudos

Hi Deepak,

Indeed, the code you mentioned, which is detailed under https://help.hana.ondemand.com/help/frameset.htm?de16793b391a4bcfae6096f34433de76.html, is relevant to Ajax calls. However, it doesn't handle oData calls, which you can handle separately for every such call in order to redirect back to the logon page. I'm not aware of any direct method to achieve both calls.

Best Regards,
Boaz

sahud
Participant
0 Kudos

Thanks Boaz,

Can you help me with how to acheive the same for oData calls. I tried using below code, but the code never hits oMetadata Failed even after I have invalidated the session.

jQuery.sap.intervalCall(5000, this, function() {
				var serviceURL = this.getManifestEntry("/sap.app/dataSources/domainPath/uri");
				var sessionCheckURL = serviceURL + "/BRS/HAA/services/AppConfig.xsodata";
				var oSessionChckModel = new sap.ui.model.odata.ODataModel(sessionCheckURL);
				oSessionChckModel.attachMetadataFailed(function(oEvent){
					alert("session expired");	
				}, this);
				oSessionChckModel.attachMetadataLoaded(function(oEvent){
					alert("session Alive");
				});
			});

It never goes into the attachMetadataFailed Event and inside the MetadataLoaded Event, I cannot find the parameter "com.sap.cloud.security.login" in the headers.

The way I test the session timeout is as follows:

  1. Run the SAPUI5 App.
  2. Logout of HANA Cloud Platform Cockpit so it invalidates the session at IDP level (i.e. each single application).
  3. make oData calls to a sample service every 5 seconds to check if session is valid.

Should I be using a different approach?

Best Regards,

Deepak