【问题标题】:Get user claim value programmatically以编程方式获取用户声明价值
【发布时间】:2012-07-21 19:06:07
【问题描述】:

我正在尝试以编程方式为特定用户获取 wso2 身份服务器声明值。但是,当我每次遇到异常时都尝试访问它时,我设法以编程方式添加了声明

org.apache.axis2.databinding.ADBException: Unexpected subelement {http://api.user.carbon.wso2.org/xsd}claimUri

我使用的代码是:

 UserRealm realm = WSRealmBuilder.createWSRealm(
                        Constants.SERVER_URL, getCookie(),
                        Constants.CONFIG_CONTEXT);
                STORE_MANAGER = realm.getUserStoreManager();
    STORE_MANAGER.getUserClaimValues(username, "default");

什么会导致这个异常,我该如何解决?

【问题讨论】:

  • 您的 WSO2 身份服务器的版本是什么,您使用的 API 的版本是什么?
  • 我正在使用 WSO2 IS 3.2.3 和 3.2.0、org.wso2.carbon.user.mgt.stub-3.2.0.jar、org.wso2.carbon.user.core- 3.2.2.jar,org.wso2.carbon.user.api-3.2.2.jar。

标签: exception wso2 axis2 wso2is claims


【解决方案1】:

更新: 我自己也遇到过这个问题。我在https://wso2.org/jira/browse/CARBON-13809 找到了答案。看来这是一个应该在 IS 4.0 版本中修复的错误

原始答案如下:

以下代码来自 org.wso2.carbon.identity.user.profile.ui\3.2.0\src\main\resources\web\userprofile 和来自 wso2 Identity Server 3.2 的文件 edit-finish.jsp

<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib uri="http://wso2.org/projects/carbon/taglibs/carbontags.jar"
prefix="carbon"%>
<%@page import="org.wso2.carbon.utils.ServerConstants"%>
<%@page import="org.wso2.carbon.ui.CarbonUIUtil"%>
<%@page import="org.apache.axis2.context.ConfigurationContext"%>
<%@page import="org.wso2.carbon.CarbonConstants"%>
<%@page import="org.wso2.carbon.identity.user.profile.ui.client.UserProfileCient"%>
<%@page import="java.util.Map"%>
<%@page import="java.util.Iterator"%>
<%@page import="java.lang.Exception"%>
<%@page import="java.util.ResourceBundle"%>
<%@page import="org.wso2.carbon.ui.util.CharacterEncoder"%><script type="text/   javascript" src="extensions/js/vui.js"></script>
<script type="text/javascript" src="../extensions/core/js/vui.js"></script>
<script type="text/javascript" src="../admin/js/main.js"></script>

<jsp:include page="../dialog/display_messages.jsp" />
<%@ page import="org.wso2.carbon.ui.CarbonUIMessage"%>
<%@ page import="org.wso2.carbon.identity.user.profile.stub.types.UserFieldDTO" %>
<%@ page import="org.wso2.carbon.identity.user.profile.stub.types.UserProfileDTO" %>
<%@ page import="java.text.MessageFormat" %>

<%
String profile = CharacterEncoder.getSafeText(request.getParameter("profile"));
String username = CharacterEncoder.getSafeText(request.getParameter("username"));
String profileConfiguration = request.getParameter("profileConfiguration");
UserFieldDTO[] fieldDTOs = null;
String forwardTo = null;
String BUNDLE = "org.wso2.carbon.identity.user.profile.ui.i18n.Resources";
ResourceBundle resourceBundle = ResourceBundle.getBundle(BUNDLE, request.getLocale());
String fromUserMgt = (String) request.getParameter("fromUserMgt");

try {
    String cookie = (String) session.getAttribute(ServerConstants.ADMIN_SERVICE_COOKIE);
    String backendServerURL = CarbonUIUtil.getServerURL(config.getServletContext(), session);
    ConfigurationContext configContext =
            (ConfigurationContext) config.getServletContext().getAttribute(CarbonConstants.CONFIGURATION_CONTEXT);
    UserProfileCient client = new UserProfileCient(cookie, backendServerURL, configContext);        

    fieldDTOs = client.getProfileFieldsForInternalStore().getFieldValues();

    if (fieldDTOs!=null)
    {
      for (UserFieldDTO field : fieldDTOs) {
        String value = request.getParameter(field.getClaimUri());
        field.setFieldValue(value);   
      }
    }

    UserProfileDTO userprofile= new UserProfileDTO();
    userprofile.setProfileName(profile);
    userprofile.setFieldValues(fieldDTOs);      
    userprofile.setProfileConifuration(profileConfiguration);
    client.setUserProfile(username, userprofile);
    String message = resourceBundle.getString("user.profile.updated.successfully");
    CarbonUIMessage.sendCarbonUIMessage(message,CarbonUIMessage.INFO, request);
    if ("true".equals(fromUserMgt)) {
        forwardTo ="index.jsp?username="+username+"&fromUserMgt=true";
    }else{
        forwardTo ="index.jsp?region=region5&item=userprofiles_menu&ordinal=0";         
    }

} catch (Exception e) {
    String message = MessageFormat.format(resourceBundle.getString(
            "error.while.updating.user.profile"), username, e.getMessage());
    CarbonUIMessage.sendCarbonUIMessage(message, CarbonUIMessage.ERROR, request);
    forwardTo = "edit.jsp?username=" + username + "&profile=" + profile + "&fromUserMgt=true";
}
%>

<script type="text/javascript">
    function forward() {
    location.href ="<%=forwardTo%>";
    }
</script>

<script type="text/javascript">
    forward();
</script>

注意这段代码

    if (fieldDTOs!=null)
    {
      for (UserFieldDTO field : fieldDTOs) {
        String value = request.getParameter(field.getClaimUri());
        field.setFieldValue(value);   
      }
    }

希望你能用它来帮助你。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-11-12
    • 1970-01-01
    • 2018-12-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-19
    相关资源
    最近更新 更多