2

我正在尝试以编程方式为特定用户获取 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");

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

4

1 回答 1

0

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

下面的原始答案:

以下代码来自 wso2 Identity Server 3.2 中的 org.wso2.carbon.identity.user.profile.ui\3.2.0\src\main\resources\web\userprofile 和文件 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);   
      }
    }

希望您可以使用它来帮助您。

于 2012-09-04T18:03:00.590 回答