What method replaces the deprecated method refreshMetadata of sap.ui.model.odata.v2.ODataModel?
OpenUI5 version: 1.60.1
Browser/version (+device/version): 71.0.3578.98 (Official Build) (64-bit)
Any other tested browsers/devices(OK/FAIL): N/A
URL (minimal example if possible): https://openui5.hana.ondemand.com/#/api/sap.ui.model.odata.v2.ODataModel/methods/refreshMetadata
Steps to reproduce the problem: In the current documentation the method refreshMetadata of sap.ui.model.odata.v2.ODataModel is marked as deprecated since 1.42. I use this method to refreshMetadata after I've handled the attachMetadataFailed by another request to the backend (HANA XS Classic) which reads the group assignments of the user and adds a new role to the user. After this request was executed successful I call refreshMetadata and the app can continue loading.
What is the expected result? Have a replacement for the method refreshMetadata.
What happens instead? It might be removed in future releases of UI5.
Hello @gregorwolf !
I cannot really comment on this issue because I am only involved with OData V4. But out of curiosity: why does the metadata (have to) change when you add a new role to the user? I understand that roles are important for authorization, but I would expect that to happen on a data level, not on a metadata level.
Best regards, Thomas
Hi @ThomasChadzelek ,
we have the following Architecture:
SAPUI5 App deployed as HTML5 App on SAP CP Neo | Destination with Authentication set to AppToAppSSO | HANA instance trusting the Sub-Account SAML configuration and Dynamic User Creation
The HTML5 App is also protected by an Authorization that is assigned to a SAP CP Role, with is assigned to a Group. This Group is mapped to a user by using a SAML assertion received from our corporate Identity Provider.
So when a user accesses the HTML5 App the authentication will happen at the corporate IdP providing the assertion. If the user has the needed Group access to the HTML5 App will be granted and a request for the OData Metadata from the HANA backend will be triggered. As this is the first request, it will trigger the Dynamic User Creation. Due to security reasons we can't assign the role for this application to the default role which is assigned to the user during creation. We need to check if the user got a specific group assigned in SAP CP. As I don't know how I could hook into the $metadata creation in HANA my solution was the following:
I've adjusted the coding which is called for attachMetadataFailed in the way that it will not show the user the usual error MessageBox, but instead call a xsjs endpoint from the HANA System that will read the content of the $.session Object. When the user was authenticated to HANA via the AppToAppSSO Destination the content will look like that:
{
"language":"",
"samlAttribute":{
"com.sap.core.jpaas.security.um.groups":[
{
"type":"xs:string",
"value":"Group1;Group2"
}
],
"name":[
{
"type":"xs:string",
"value":"gregor"
}
]
},
"samlUserInfo":{
}
}
So I have a trusted, server side information that this user is assigned to two Groups in SAP CP. By using that information I can assign the needed HANA role on the fly. After that request was completed I call refreshMetadata to repeat the request to retrieve the metadata. That is now possible as the needed HANA role is assigned.
Hope that makes it clear.
CU Gregor
Hello Gregor!
Sorry, I have to confess that I only understand half of it. At most. But that is my fault. Could you please explain how $metadata differs from one user to the other? I still have the assumption that $metadata calls should not fail dynamically. Only data calls should.
Best regards, Thomas
Hi Thomas,
it's good to have that questions that clarify the case hopefully.
The first $metadata request will fail due to the missing role assignment in the HANA backend. So I invoke the following code:
this._oModel.attachMetadataFailed(function (oEvent) {
var oParams = oEvent.getParameters();
if (oParams.statusCode === 403) {
this._assignHanaRoleFromSamlAttribute(oParams);
} else {
this._showServiceError(oParams.response);
}
}, this);
this will trigger:
_assignHanaRoleFromSamlAttribute : function (oParams) {
var oReq = new XMLHttpRequest();
oReq.addEventListener("load", this._handleAssignmentResponse.bind(this));
oReq.open("GET", "/SCP_HANA/myapp/roleassignment/assignment.xsjs");
oReq.send();
},
where the user get's the correct HANA role assigned. The handler for the response is:
_handleAssignmentResponse : function (oEvent) {
var oStatus = JSON.parse(oEvent.target.responseText);
Log.info("Result of the assignment: " + oStatus.assignment);
if(oStatus.assignment){
this._oModel.refreshMetadata();
} else {
this._showServiceError("Assignment of HANA role failed");
}
},
which will trigger the refreshMetadata() in the case that the role assignment was OK.
Best regards Gregor
Hello Gregor!
I think I got that part now. But could you please provide a (simplified) example of what the resulting $metadata looks like in the end? Is it something that is not known in the beginning or is it just a secret or...?
Best regards, Thomas
Hi Thomas,
due to the missing authorisations the HANA backend will respond with the HTTP Status Code: 403 and the following HTML content:
<html>
<head>
<title>Error 403 - Forbidden</title>
<style>
...
I haven't checked yet, but is there a way in OpenUI5 to issue a request to the backend before the request for metadata is done?
Best regards Gregor
Could you please provide a (simplified) example of what the resulting $metadata looks like in the end? I mean, the one that you get once you are allowed to get it.
It's just normal OData V2 as you i.e. get it from the Service behind SITreg Participant List. You get the $metadata here.
I am not a cloud expert, but maybe $metadata should not be protected in the same way as data ("Destination with Authentication set to AppToAppSSO"). But I guess you cannot have an exception for $metadata alone, or a different destination. Sounds tricky. The reason why I am asking all these questions is because my team is doing the V4 model and we have no such thing as refreshMetadata(). Up to now, I could not see a valid use case for it and I still think it's a pity that an app has to write such code just to load $metadata. It just does not feel right. But I cannot answer your original V2 question.
Hello Gregor, refreshMetadata is deprecated due to several problems:
- only $metadata gets refetched
- annotation loading will not be retriggered
- even if we could manage to retrigger the annotation loading, 'later' added annotations via addAnnotationUrl must also be tracked an reloaded.
- If all the above stuff was done successfully, we must retrigger potential consumers of this data: templating, types, formatter, other metadata/annotation related stuff, ...
Retriggering all the above stuff is more or less like a restart of the application.
Maybe it is sufficient to recreate the model instead using refreshMetadata in your scenario? Not aware of a programmatic way to restart the application.
Best regards, Jan