2012-07-23 46 views
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"); 

,是什麼原因例外,哪能修理它?

+0

WSO2 Identity Server的版本是什麼?您使用的API版本是什麼? – 2012-07-26 08:29:41

+0

我使用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。 – 2012-07-27 13:56:31

回答

0

更新: 我自己遇到了這個問題。我在https://wso2.org/jira/browse/CARBON-13809找到了答案。現在看來,這是一個應該被固定在

原回答以下爲4.0版本中的錯誤:

下面的代碼是從org.wso2.carbon.identity.user.profile.ui \ 3.2。 0的\ src \主\資源\網絡\用戶配置文件,並從WSO2 Identity Server的文件編輯finish.jsp 3.2

<%@ 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); 
     } 
    } 

希望你可以用它來幫助你。