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

时间:2012-07-23 14:16:05

标签: exception wso2 axis2 wso2is claims

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

什么可能导致此异常以及如何解决?

1 个答案:

答案 0 :(得分:0)

更新: 我自己遇到了这个问题。我在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 < / p>

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

希望你可以用它来帮助你。