All Downloads are FREE. Search and download functionalities are using the official Maven repository.

web.userprofile.set-finish-ajaxprocessor.jsp Maven / Gradle / Ivy

The newest version!

<%@ 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.apache.axis2.context.ConfigurationContext"%>
<%@ page import="org.apache.commons.lang.StringUtils"%>
<%@ page import="org.wso2.carbon.CarbonConstants"%>
<%@ page import="org.wso2.carbon.identity.user.profile.stub.types.UserFieldDTO"%>
<%@ page import="org.wso2.carbon.identity.user.profile.stub.types.UserProfileDTO"%>
<%@ page import="org.wso2.carbon.identity.user.profile.ui.client.UserProfileCient"%>
<%@ page import="org.wso2.carbon.ui.CarbonUIMessage"%>
<%@ page import="org.wso2.carbon.ui.CarbonUIUtil"%>
<%@ page import="org.wso2.carbon.user.core.UserCoreConstants"%>
<%@ page import="org.wso2.carbon.user.mgt.ui.Util"%>
<%@ page import="org.wso2.carbon.utils.ServerConstants" %>
<%@ page import="java.text.MessageFormat" %>
<%@ page import="java.util.ResourceBundle" %>
<%@ page import="org.owasp.encoder.Encode" %>
<%@ page import="org.wso2.carbon.identity.user.profile.ui.client.UserProfileUIUtil" %>
<%@ page import="org.wso2.carbon.identity.user.profile.ui.client.UserProfileUIException" %>



<%
    String httpMethod = request.getMethod();
    if (!"post".equalsIgnoreCase(httpMethod)) {
        response.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
        return;
    }

    String BUNDLE = "org.wso2.carbon.identity.user.profile.ui.i18n.Resources";
    ResourceBundle resourceBundle = ResourceBundle.getBundle(BUNDLE, request.getLocale());
    String username = request.getParameter("username");
    String profile = request.getParameter("profile");
    String profileConfiguration = request.getParameter("profileConfiguration");
    String fromUserMgt = request.getParameter("fromUserMgt");
	UserFieldDTO[] fieldDTOs = null;
	UserProfileDTO profileDTO = null;
	String forwardTo = null;
    String encryptedUsername = null;
    if(StringUtils.isBlank(username) || StringUtils.isBlank(profile)){
        String message = MessageFormat.format(resourceBundle.getString("error.while.updating.profile"), null);
        CarbonUIMessage.sendCarbonUIMessage(message, CarbonUIMessage.ERROR, request);
%>
        
<%
        return;
    }

    if (StringUtils.isBlank(fromUserMgt)) {
        fromUserMgt = "false";
    }
	
    try {
        try {
            encryptedUsername = UserProfileUIUtil.getEncryptedAndBase64encodedUsername(username);
        } catch (UserProfileUIException e) {
            String message = MessageFormat.format(resourceBundle.getString("error.while.updating.profile"), null);
            CarbonUIMessage.sendCarbonUIMessage(message, CarbonUIMessage.ERROR, request);
%>
            
<%
        return;
        }

        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);    
        
        try {
        	profileDTO = client.getUserProfile(username,profile);
            if (UserCoreConstants.DEFAULT_PROFILE.equals(profile)||profileDTO!=null && profileDTO.getProfileName()!=null) {
                String message = resourceBundle.getString("user.profile.with.given.name.exists");
                CarbonUIMessage.sendCarbonUIMessage(message, CarbonUIMessage.INFO, request);
                forwardTo ="add.jsp?username="+ Encode.forUriComponent(encryptedUsername);
%>
                
<%			    return;
        	}
        } catch(Exception e) {
        	// ignore exception
        }
        
    	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.added.successfully");
        CarbonUIMessage.sendCarbonUIMessage(message,CarbonUIMessage.INFO, request);
        if ("true".equals(fromUserMgt)) {
        	forwardTo = "index.jsp?username=" + Encode.forUriComponent(encryptedUsername) + "&fromUserMgt=" +
                    Encode.forUriComponent(fromUserMgt);
        }else{
        	forwardTo ="index.jsp?region=region5&item=userprofiles_menu&ordinal=0";        	
        }
    } catch (Exception e) {
        String message = MessageFormat.format(resourceBundle.getString("error.while.updating.profile.user"),
                                          username, e.getMessage());
        CarbonUIMessage.sendCarbonUIMessage(message, CarbonUIMessage.ERROR, request);
        forwardTo =
            "edit.jsp?username=" + Encode.forUriComponent(encryptedUsername) + "&profile=" + Encode.forUriComponent(profile) +
            "&fromUserMgt=" + Encode.forUriComponent(fromUserMgt);
}
%>







© 2015 - 2024 Weber Informatics LLC | Privacy Policy