Exception 以编程方式获取用户声明值

Exception 以编程方式获取用户声明值,exception,wso2,axis2,wso2is,claims,Exception,Wso2,Axis2,Wso2is,Claims,我试图以编程方式为特定用户获取wso2 identity server声明值。然而,当我每次遇到异常时都试图访问声明时,我设法以编程方式添加了声明 org.apache.axis2.databinding.ADBException: Unexpected subelement {http://api.user.carbon.wso2.org/xsd}claimUri 我使用的代码是: UserRealm realm = WSRealmBuilder.createWSRealm(

我试图以编程方式为特定用户获取wso2 identity server声明值。然而,当我每次遇到异常时都试图访问声明时,我设法以编程方式添加了声明

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");
什么会导致此异常?我如何修复它?

更新: 我自己也遇到了这个问题。我终于找到了答案。这似乎是一个应该在is 4.0版本中修复的bug

原始答复如下:

以下代码来自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>
希望您能用它来帮助您。

更新: 我自己也遇到了这个问题。我终于找到了答案。这似乎是一个应该在is 4.0版本中修复的bug

原始答复如下:

以下代码来自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>

希望您能用它来帮助您。

您的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.您的wso2身份服务器版本是什么?您使用的api版本是什么?我使用的wso2是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。