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

web.roles-mgt.add-server-role.jsp Maven / Gradle / Ivy


<%@page import="org.apache.axis2.context.ConfigurationContext" %>
<%@page import="org.wso2.carbon.CarbonConstants" %>
<%@page import="org.wso2.carbon.roles.mgt.ui.ServerRoleManagerClient" %>
<%@page import="org.wso2.carbon.ui.CarbonUIMessage" %>
<%@page import="org.wso2.carbon.ui.CarbonUIUtil" %>
<%@page import="org.wso2.carbon.ui.util.CharacterEncoder" %>
<%@ page import="org.wso2.carbon.utils.ServerConstants" %>
<%@page import="java.text.MessageFormat" %>
<%@ page import="java.util.ResourceBundle" %>

<%

    String httpMethod = request.getMethod().toLowerCase();

    if (!"post".equals(httpMethod)) {
        response.sendError(405);
        return;
    }

    String forwardTo;
    String BUNDLE = "org.wso2.carbon.roles.mgt.ui.i18n.Resources";
    ResourceBundle resourceBundle = ResourceBundle.getBundle(BUNDLE, request.getLocale());
    ServerRoleManagerClient client;
    String serverRoleName = CharacterEncoder.getSafeText(request.getParameter("serverRoleName"));
    String serverRoleType = CharacterEncoder.getSafeText(request.getParameter("serverRoleType"));

    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);

        client = new ServerRoleManagerClient(configContext, backendServerURL, cookie);
        client.addServerRoles(new String[]{serverRoleName}, serverRoleType);

        forwardTo = "server-roles-mgt.jsp";
    } catch (Exception e) {
        String message = MessageFormat.format(resourceBundle.getString("server-role.cannot.add"),
                serverRoleName, e.getMessage());
        CarbonUIMessage.sendCarbonUIMessage(message, CarbonUIMessage.ERROR, request);
        forwardTo = "server-roles-mgt.jsp";
    }
%>






© 2015 - 2024 Weber Informatics LLC | Privacy Policy