使用UserAccessor访问用户属性 [英] Accessing user attributes using UserAccessor

查看:95
本文介绍了使用UserAccessor访问用户属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

com.sap.cloud.sdk.cloudplatform.security.user.UserAccessor类允许我检索当前用户及其属性.

The class com.sap.cloud.sdk.cloudplatform.security.user.UserAccessor allows to me to retrieve the current user and it's attributes.

例如:

    Optional<UserAttribute> optionalfirstName = user.getAttribute("firstname"); 
    UserAttribute ua = optionalfirstName.get(); 

一旦检索到UserAttribute,它将具有两个属性名称"和值".但是,没有可用的方法来获取该值.我如何获得价值?

Once I have retrieved the UserAttribute, it has two properites "Name" and "Value". However there is no method available to get the Value. How can I access the value?

推荐答案

取决于所使用的SAP CP环境,UserAttribute是以下内容的实例:

Depending on the SAP CP environment you are using, the UserAttribute is an instance of:

  • SimpleUserAttribute<String> on Neo
  • CollectionUserAttribute<String>在Cloud Foundry上
  • SimpleUserAttribute<String> on Neo
  • CollectionUserAttribute<String> on Cloud Foundry

您可以通过将类型强制转换为所需实例来访问相应的值:

You can access the respective values by type-casting to the required instance:

if( ua instanceof SimpleUserAttribute ) {
    String value = (String) ((SimpleUserAttribute<?>)ua).getValue();
}
else if ( ua instanceof CollectionUserAttribute ) {
    Collection<?> values = ((CollectionUserAttribute<?>)ua).getValues();
}

注意:我们计划在以后的SDK版本中对此进行简化,以便返回StringUserAttributeStringCollectionUserAttribute实例以便更方便地使用.

Note: We plan to simplify this in future releases of the SDK so that StringUserAttribute and StringCollectionUserAttribute instances are returned for more convenient consumption.

这篇关于使用UserAccessor访问用户属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆