Ibm mobilefirst 如何在Worklight中的用户标识对象中设置和检索自定义属性?

Ibm mobilefirst 如何在Worklight中的用户标识对象中设置和检索自定义属性?,ibm-mobilefirst,worklight-server,worklight-security,Ibm Mobilefirst,Worklight Server,Worklight Security,我已经在IBM Worklight 6.0中实现了自定义验证器和登录模块。身份验证机制工作正常 我在用户标识对象中设置了自定义属性,如角色、电子邮件等 在登录模块中 public UserIdentity createIdentity(String realm) { Map<String, Object> customAttributes= new HashMap<String, Object>(); customAttributes.put("userName", us

我已经在IBM Worklight 6.0中实现了自定义验证器和登录模块。身份验证机制工作正常

我在用户标识对象中设置了自定义属性,如角色、电子邮件等

在登录模块中

public UserIdentity createIdentity(String realm) {
Map<String, Object> customAttributes= new HashMap<String, Object>();
customAttributes.put("userName", username);
customAttributes.put("mail", customAttrValue); //customAttrValue - this has the email id
UserIdentity uiObj=new UserIdentity("CustomRealm", username, username, null, customAttributes, password);
return uiObj;
}
公共用户标识createIdentity(字符串域){ Map customAttributes=新建HashMap(); customAttributes.put(“用户名”,用户名); customAttributes.put(“mail”,customAttrValue);//customAttrValue-这有电子邮件id UserIdentity uiObj=新用户标识(“CustomRealm”、用户名、用户名、null、customAttributes、密码); 返回uiObj; } 现在我无法使用下面的api调用检索属性值。 WL.Client.getUserInfo(“CustomRealm”、“mail”)

首先,您需要获取领域的“属性”选项。然后拿到你的“邮件” 属性集中的属性。大概是这样的:

var attrs = WL.Client.getUserInfo("CustomRealm", "attributes");
var email = null;;
if (attrs) {
    email = attrs.mail;
}