Skip to Content
0

Handling session Timeout in SAP HANA Cloud Portal

Jan 12, 2017 at 07:02 AM

823

avatar image
Former Member

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?

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Best Answer
Ulrich Block
Jan 16, 2017 at 01:00 PM
0

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);
}
Share
10 |10000 characters needed characters left characters exceeded
Boaz Wimmer
Jan 12, 2017 at 02:39 PM
0

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

Show 1 Share
10 |10000 characters needed characters left characters exceeded
Former Member

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

0