Search code examples
sap-cloud-sdk

How to get user info and authorities in SAP Cloud SDK 3.0 and above


I want to get user info and authorities but could not find any interface. But there is an interface called AuthTokenAccessor in package com.sap.cloud.sdk.cloudplatform.security. I could get JWT token but could not parse it due to lack of information e.g. sign key.

String token = AuthTokenAccessor.getCurrentToken().getJwt().getToken();

In SAP Cloud SDK version 2.0, there is an interface UserAccessor which can meet the requirements but seems it is gone in version 3.X.

Could you suggest how to do it in version 3.0 and above?

Update

PrincipalAccessor interface is the answer. But authorizations returned are empty. I am using App router to access backend restful APIs.

 Set<Authorization> authorizations = principal.getAuthorizations();
 log.info("Authentication set is empty:" + authorizations.isEmpty());

SDK version is 3.15.1.

Remote debugging. Attributes and authorizations are both empty. enter image description here


Solution

  • Please use PrincipalAccessor instead. UserAccessor has been merged into the more generic PrincipalAccessor.

    Also, while migrating from v2 to v3 of the Cloud SDK, please refer to this migration guide. You can also find release notes of the SDK here.