Accessing user attributes using UserAccessor

本小妞迷上赌 提交于 2019-12-25 03:19:09

问题


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

For example:

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

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?


回答1:


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

  • 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();
}

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



来源:https://stackoverflow.com/questions/53858644/accessing-user-attributes-using-useraccessor

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!