Retrieve logged user information from cloud foundry web application

后端 未结 2 688
小鲜肉
小鲜肉 2021-01-14 15:54

We developed a web application using SAP Web-IDE Full Stack; we need to retrieve the details of the user logged into application (as defined in SAP Cloud Platform Identity A

2条回答
  •  忘掉有多难
    2021-01-14 16:30

    I highly suggest using the SAP S/4HANA Cloud SDK for such tasks. It is an SDK developed to make building applications for SAP Cloud Platform easy, by providing easy to use mechanisms for all the Cloud Platform mechanisms.

    Regarding your task at hand, there is a UserAccessor class that you can use like this:

    final Optional user = UserAccessor.getCurrentUser();
    

    This works on Neo as well as on Cloud Foundry, i.e. there is a single interface for both platforms, which allows you to develop your app in a platform agnostic way.

    If this sounds like it could solve your problem, I recommend checking out this blog post series to get started.

    Alternatively, you can also simply add the following dependency to your project to start testing the SDK:

    
        com.sap.cloud.s4hana.cloudplatform
        scp-neo
        2.7.0
    
    

    For Cloud Foundry use scp-cf instead of scp-neo.

    Hope this helps!

    P.S.: To answer your question also on a technical level, Cloud Foundry uses so-called JWTs for authentication and authorization. You can check whether a JWT is present by looking at the Authorization header of the request. The JWT should hold the information you're looking for.

提交回复
热议问题