Java Code Examples for org.wso2.carbon.ui.CarbonUIUtil#getServerURL()

The following examples show how to use org.wso2.carbon.ui.CarbonUIUtil#getServerURL() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IWAUIAuthenticator.java    From carbon-identity with Apache License 2.0 7 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void authenticate(HttpServletRequest request) throws AuthenticationException {

    String userName = request.getRemoteUser();
    userName = userName.substring(userName.indexOf("\\") + 1);

    if (log.isDebugEnabled()) {
        log.debug("Authenticate request received : Authtype - " + request.getAuthType() +
                ", User - " + userName);
    }

    ServletContext servletContext = request.getSession().getServletContext();
    HttpSession session = request.getSession();
    String backendServerURL = request.getParameter("backendURL");
    if (backendServerURL == null) {
        backendServerURL = CarbonUIUtil.getServerURL(servletContext, request.getSession());
    }

    session.setAttribute(CarbonConstants.SERVER_URL, backendServerURL);
    String rememberMe = request.getParameter("rememberMe");

    handleSecurity(userName, (rememberMe != null), request);
    request.setAttribute("username", userName);
}
 
Example 2
Source File: CompositeReportProcessor.java    From carbon-commons with Apache License 2.0 6 votes vote down vote up
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws
        Exception {
    String webContext = (String) request.getAttribute(CarbonConstants.WEB_CONTEXT);
    HttpSession session = request.getSession();
    String serverURL = CarbonUIUtil.getServerURL(getServletContext(), session);
    ConfigurationContext configContext =
            (ConfigurationContext) getServletContext().getAttribute(CarbonConstants.CONFIGURATION_CONTEXT);
    String cookie = (String) session.getAttribute(ServerConstants.ADMIN_SERVICE_COOKIE);

    ReportTemplateClient client;
    String errorString = "";

    client = new ReportTemplateClient(configContext, serverURL, cookie);
    String reportname = request.getParameter("reportName");
    String[] reports = getSubReportsName(request);

    if (reports != null) {
        client.addNewCompositeReport(reports, reportname);
        response.sendRedirect("../reporting_custom/list-reports.jsp?region=region5&item=reporting_list");
    } else {
        errorString = "No reports was sleected to form the composite report";
        request.setAttribute("errorString", errorString);
        response.sendRedirect("../reporting-template/add-composite-report.jsp");
    }
}
 
Example 3
Source File: CarbonSTSClient.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
/**
 * Initializes STSUtil
 *
 * @param cookie Cookie string
 * @throws Exception
 */
public CarbonSTSClient(ServletConfig config, HttpSession session, String cookie)
        throws Exception {
    ServiceClient client = null;
    Options option = null;
    String serverUrl = null;

    // Obtaining the client-side ConfigurationContext instance.
    configContext = (ConfigurationContext) config.getServletContext().getAttribute(
            CarbonConstants.CONFIGURATION_CONTEXT);

    // Server URL which is defined in the server.xml
    serverUrl = CarbonUIUtil.getServerURL(config.getServletContext(), session);

    this.serviceEndPoint = serverUrl + "STSAdminService";
    try {
        this.stub = new STSAdminServiceStub(configContext, serviceEndPoint);
    } catch (AxisFault e) {
        log.error("Error while creating STSAdminServiceStub", e);
        throw new Exception(e);
    }
    client = stub._getServiceClient();
    option = client.getOptions();
    option.setManageSession(true);
    option.setProperty(org.apache.axis2.transport.http.HTTPConstants.COOKIE_STRING, cookie);
}
 
Example 4
Source File: RegistryAdminServiceClient.java    From attic-stratos with Apache License 2.0 6 votes vote down vote up
public RegistryAdminServiceClient(String cookie, ServletConfig config, HttpSession session)
        throws AxisFault {
    String serverURL = CarbonUIUtil.getServerURL(config.getServletContext(),
                session);
    ConfigurationContext ctx = (ConfigurationContext) config.
                getServletContext().getAttribute(CarbonConstants.CONFIGURATION_CONTEXT);
    this.session = session;
    String serviceEPR = serverURL + "RegistryAdminService";
    stub = new RegistryAdminServiceStub(ctx, serviceEPR);
    ServiceClient client = stub._getServiceClient();
    Options options = client.getOptions();
    options.setManageSession(true);
    if (cookie != null) {
        options.setProperty(HTTPConstants.COOKIE_STRING, cookie);
    }
}
 
Example 5
Source File: IWAUIAuthenticator.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
/**
 * @param request
 * @return
 * @throws AxisFault
 */
private IWAAuthenticatorStub getIWAClient(HttpServletRequest request)
        throws AxisFault, IdentityException {

    HttpSession session = request.getSession();
    ServletContext servletContext = session.getServletContext();
    String backendServerURL = request.getParameter("backendURL");
    if (backendServerURL == null) {
        backendServerURL = CarbonUIUtil.getServerURL(servletContext, request.getSession());
    }

    ConfigurationContext configContext = (ConfigurationContext) servletContext
            .getAttribute(CarbonConstants.CONFIGURATION_CONTEXT);

    String serviceEPR = backendServerURL + "IWAAuthenticator";
    IWAAuthenticatorStub stub = new IWAAuthenticatorStub(configContext, serviceEPR);
    ServiceClient client = stub._getServiceClient();
    client.engageModule("rampart");
    Policy rampartConfig = IdentityBaseUtil.getDefaultRampartConfig();
    Policy signOnly = IdentityBaseUtil.getSignOnlyPolicy();
    Policy mergedPolicy = signOnly.merge(rampartConfig);
    Options options = client.getOptions();
    options.setProperty(RampartMessageData.KEY_RAMPART_POLICY, mergedPolicy);
    options.setManageSession(true);
    return stub;
}
 
Example 6
Source File: reportUploadExecutor.java    From carbon-commons with Apache License 2.0 6 votes vote down vote up
private void init(HttpServletRequest request) throws Exception {
    HttpSession session = request.getSession();
    String serverURL = CarbonUIUtil.getServerURL(session.getServletContext(), session);
    ConfigurationContext configContext =
            (ConfigurationContext) session.getServletContext().getAttribute(CarbonConstants.CONFIGURATION_CONTEXT);
    String cookie = (String) session.getAttribute(ServerConstants.ADMIN_SERVICE_COOKIE);

    client = new ReportTemplateClient(configContext, serverURL, cookie);
    Map<String, ArrayList<FileItemData>> fileItemsMap = getFileItemsMap();
    formFieldsMap = getFormFieldsMap();

    images = fileItemsMap.get("logo");

    String type = null;
    if(formFieldsMap.get("reportType") != null){
       type = formFieldsMap.get("reportType").get(0);
    }

    if(type == null){
      tableReport= (TableReportDTO)session.getAttribute("table-report");
    }
    else {
      chartReport = (ChartReportDTO)session.getAttribute("chart-report");
    }
}
 
Example 7
Source File: OpenIDUtil.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
/**
 * Returns an instance of <code>OpenIDAdminClient</code>.
 * Only one instance of this will be created for a session.
 * This method is used to reuse the same client within a session.
 *
 * @param session
 * @return {@link OpenIDAdminClient}
 * @throws AxisFault
 */
public static OpenIDAdminClient getOpenIDAdminClient(HttpSession session) throws AxisFault {
    OpenIDAdminClient client =
            (OpenIDAdminClient) session.getAttribute(OpenIDConstants.SessionAttribute.OPENID_ADMIN_CLIENT);
    if (client == null) { // a session timeout or the fist request
        String serverURL = CarbonUIUtil.getServerURL(session.getServletContext(), session);
        ConfigurationContext configContext = (ConfigurationContext) session.getServletContext().getAttribute(
                CarbonConstants.CONFIGURATION_CONTEXT);
        String cookie = (String) session.getAttribute(ServerConstants.ADMIN_SERVICE_COOKIE);
        client = new OpenIDAdminClient(configContext, serverURL, cookie);
        session.setAttribute(OpenIDConstants.SessionAttribute.OPENID_ADMIN_CLIENT, client);
    }
    return client;
}
 
Example 8
Source File: ReportResourceSupplierClient.java    From carbon-commons with Apache License 2.0 5 votes vote down vote up
public static  ReportResourceSupplierClient getInstance(ServletConfig config, HttpSession session)
        throws AxisFault {
      String backendServerURL = CarbonUIUtil.getServerURL(config.getServletContext(), session);
    ConfigurationContext configContext =
            (ConfigurationContext) config.getServletContext().getAttribute(
                    CarbonConstants.CONFIGURATION_CONTEXT);

    String cookie = (String) session.getAttribute(ServerConstants.ADMIN_SERVICE_COOKIE);
    return new ReportResourceSupplierClient(cookie, backendServerURL, configContext);

}
 
Example 9
Source File: ReportResourceSupplierClient.java    From carbon-commons with Apache License 2.0 5 votes vote down vote up
public static  ReportResourceSupplierClient getInstance(ServletConfig config, HttpSession session)
        throws AxisFault {
      String backendServerURL = CarbonUIUtil.getServerURL(config.getServletContext(), session);
    ConfigurationContext configContext =
            (ConfigurationContext) config.getServletContext().getAttribute(
                    CarbonConstants.CONFIGURATION_CONTEXT);

    String cookie = (String) session.getAttribute(ServerConstants.ADMIN_SERVICE_COOKIE);
    return new ReportResourceSupplierClient(cookie, backendServerURL, configContext);

}
 
Example 10
Source File: DBReportingServiceClient.java    From carbon-commons with Apache License 2.0 5 votes vote down vote up
public static DBReportingServiceClient getInstance(ServletConfig config, HttpSession session)
        throws AxisFault {
     String backendServerURL = CarbonUIUtil.getServerURL(config.getServletContext(), session);
    ConfigurationContext configContext =
            (ConfigurationContext) config.getServletContext().getAttribute(
                    CarbonConstants.CONFIGURATION_CONTEXT);

    String cookie = (String) session.getAttribute(ServerConstants.ADMIN_SERVICE_COOKIE);
    return new DBReportingServiceClient(cookie,backendServerURL,configContext);
}
 
Example 11
Source File: JrxmlFileUploaderClient.java    From carbon-commons with Apache License 2.0 5 votes vote down vote up
public static JrxmlFileUploaderClient getInstance(ServletConfig config, HttpSession session) throws AxisFault {
    String backendServerURL = CarbonUIUtil.getServerURL(config.getServletContext(), session);
    ConfigurationContext configContext =
            (ConfigurationContext) config.getServletContext().getAttribute(
                    CarbonConstants.CONFIGURATION_CONTEXT);

    String cookie = (String) session.getAttribute(ServerConstants.ADMIN_SERVICE_COOKIE);
    return new JrxmlFileUploaderClient(cookie,backendServerURL,configContext);
}
 
Example 12
Source File: NDataSourceAdminServiceClient.java    From carbon-commons with Apache License 2.0 5 votes vote down vote up
public static NDataSourceAdminServiceClient getInstance(ServletConfig config,
		HttpSession session) throws AxisFault {
	String backendServerURL = CarbonUIUtil.getServerURL(config.getServletContext(), session);
	ConfigurationContext configContext = (ConfigurationContext) config.getServletContext()
			.getAttribute(CarbonConstants.CONFIGURATION_CONTEXT);

	String cookie = (String) session.getAttribute(ServerConstants.ADMIN_SERVICE_COOKIE);
	return new NDataSourceAdminServiceClient(cookie, backendServerURL, configContext);

}
 
Example 13
Source File: UIUtils.java    From carbon-commons with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the broker client for EventBrokerService
 * Suppressing warning of unused declaration as it used by the UI (JSP pages)
 *
 * @param config the servlet configuration
 * @param session the http session
 * @param request the http servlet request
 * @return the broker client
 */
@SuppressWarnings("UnusedDeclaration")
public static BrokerClient getBrokerClient(ServletConfig config, HttpSession session,
                                           HttpServletRequest request) {
    String backendServerURL = CarbonUIUtil.getServerURL(config.getServletContext(), session);
    ConfigurationContext configContext = (ConfigurationContext) config.getServletContext()
            .getAttribute(CarbonConstants.CONFIGURATION_CONTEXT);

    backendServerURL = backendServerURL + "EventBrokerService";

    String cookie = (String) session.getAttribute(ServerConstants.ADMIN_SERVICE_COOKIE);
    return new BrokerClient(configContext, backendServerURL, cookie);
}
 
Example 14
Source File: SSOAssertionConsumerService.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
private void handleFederatedSAMLRequest(HttpServletRequest req, HttpServletResponse resp,
                                        String ssoTokenID, String samlRequest,
                                        String relayState, String authMode, Subject subject,
                                        String rpSessionId)
        throws IOException, ServletException, SAML2SSOUIAuthenticatorException {
    // Instantiate the service client.
    HttpSession session = req.getSession();
    String serverURL = CarbonUIUtil.getServerURL(session.getServletContext(), session);
    ConfigurationContext configContext =
            (ConfigurationContext) session.getServletContext()
                    .getAttribute(CarbonConstants.CONFIGURATION_CONTEXT);
    SAMLSSOServiceClient ssoServiceClient = new SAMLSSOServiceClient(serverURL, configContext);

    String method = req.getMethod();
    boolean isPost = false;

    if ("post".equalsIgnoreCase(method)) {
        isPost = true;
    }

    SAMLSSOReqValidationResponseDTO signInRespDTO =
            ssoServiceClient.validate(samlRequest,
                    null, ssoTokenID,
                    rpSessionId,
                    authMode, isPost);
    if (signInRespDTO.getValid()) {
        handleRequestFromLoginPage(req, resp, ssoTokenID,
                signInRespDTO.getAssertionConsumerURL(),
                signInRespDTO.getId(), signInRespDTO.getIssuer(),
                subject.getNameID().getValue(), subject.getNameID()
                        .getValue(),
                signInRespDTO.getRpSessionId(),
                signInRespDTO.getRequestMessageString(), relayState);
    }
}
 
Example 15
Source File: ReportGenerator.java    From carbon-commons with Apache License 2.0 5 votes vote down vote up
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws
        Exception {
    HttpSession session = request.getSession();
    String serverURL = CarbonUIUtil.getServerURL(getServletContext(), session);
    ConfigurationContext configContext =
            (ConfigurationContext) getServletContext().getAttribute(CarbonConstants.CONFIGURATION_CONTEXT);
    String cookie = (String) session.getAttribute(ServerConstants.ADMIN_SERVICE_COOKIE);

    ReportTemplateClient client;
    String errorString = "";
    client = new ReportTemplateClient(configContext, serverURL, cookie);

    String reportName = request.getParameter("reportName");
    String reportType = request.getParameter("reportType");

    String downloadFileName = null;

    if (reportType.equals("pdf")) {
        response.setContentType("application/pdf");
        downloadFileName = reportName + ".pdf";
    } else if (reportType.equals("xls")) {
        response.setContentType("application/vnd.ms-excel");
        downloadFileName = reportName + ".xls";
    } else if (reportType.equals("html")) {
        response.setContentType("text/html");
    }

    if (downloadFileName != null) {
        response.setHeader("Content-Disposition", "attachment; filename=\"" + downloadFileName + "\"");
    }
    DataHandler dataHandler = null;

    if (client != null) {
        dataHandler = client.generateReport(reportName, reportType);
    }
    ServletOutputStream outputStream = response.getOutputStream();
    if (dataHandler != null) {
        dataHandler.writeTo(outputStream);
    }
}
 
Example 16
Source File: ChartDataProcessor.java    From carbon-commons with Apache License 2.0 4 votes vote down vote up
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws Exception {
    String webContext = (String) request.getAttribute(CarbonConstants.WEB_CONTEXT);
    HttpSession session = request.getSession();
    String serverURL = CarbonUIUtil.getServerURL(getServletContext(), session);
    ConfigurationContext configContext =
            (ConfigurationContext) getServletContext().getAttribute(CarbonConstants.CONFIGURATION_CONTEXT);
    String cookie = (String) session.getAttribute(ServerConstants.ADMIN_SERVICE_COOKIE);

    ReportTemplateClient client;
    String errorString = "";
    client = new ReportTemplateClient(configContext, serverURL, cookie);

    String reportType = request.getParameter("reportType");
    String dsName = request.getParameter("datasource");
    String tableName = request.getParameter("tableName");
    String reportname = request.getParameter("reportName");

    SeriesDTO[] series = getSeries(request);
    String msg = "";
    if (reportType.contains("xy")) {
        msg = client.isValidNumberAxis(reportType, dsName, tableName, getXAxisFields(series));
       if(!msg.isEmpty()) msg = "X-Axis Fields are not compatible for the chart type : \n"+msg;
    }
    if (msg.isEmpty()) {
        msg = client.isValidNumberAxis(reportType, dsName, tableName, getYAxisFields(series));
        if(!msg.isEmpty())msg = "Y-Axis Fields are not compatible for the chart type : \n"+msg;
    }
    if (msg.equals("")) {
        ChartReportDTO chartReport = new ChartReportDTO();
        chartReport.setReportType(reportType);
        chartReport.setReportName(reportname);
        chartReport.setDsName(dsName);
        chartReport = addSeries(series, chartReport);
        session.setAttribute("chart-report", chartReport);
        response.sendRedirect("../reporting-template/chart-report-format.jsp?reportType=" + reportType);
    } else {
        request.setAttribute("errorString", msg);
        response.sendRedirect("../reporting-template/add-chart-report.jsp?reportType=" +
                reportType + "&success=false&errorString="+msg+"&datasource="+dsName+"&tableName"+tableName+"&reportName");
    }

}
 
Example 17
Source File: IWAUIAuthenticator.java    From carbon-identity with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public String doAuthentication(Object credentials, boolean isRememberMe, ServiceClient client,
                               HttpServletRequest request) throws AuthenticationException {

    try {

        String user = (String) credentials;

        if (user == null) {
            throw new AuthenticationException("Invalid Credentials.");
        }

        ServletContext servletContext = request.getSession().getServletContext();
        ConfigurationContext configContext = (ConfigurationContext) servletContext
                .getAttribute(CarbonConstants.CONFIGURATION_CONTEXT);

        if (configContext == null) {
            log.error("Configuration context is null.");
        }

        HttpSession session = request.getSession();
        String backendServerURL = request.getParameter("backendURL");
        if (backendServerURL == null) {
            backendServerURL = CarbonUIUtil.getServerURL(servletContext, request.getSession());
        }

        // Back-end server URL is stored in the session, even if it is an incorrect one. This
        // value will be displayed in the server URL text box. Usability improvement.
        session.setAttribute(CarbonConstants.SERVER_URL, backendServerURL);

        if (getIWAClient(request).login(user, request.getRemoteAddr())) {
            setAdminCookie(session, client, null);
        }

        return user;

    } catch (Exception e) {
        throw new AuthenticationException(
                "System error occured while trying to authenticate the user", e);
    }
}
 
Example 18
Source File: SSOAssertionConsumerService.java    From carbon-identity with Apache License 2.0 4 votes vote down vote up
private void handleRequestFromLoginPage(HttpServletRequest req, HttpServletResponse resp,
                                        String ssoTokenID, String assertionConsumerUrl, String id, String issuer, String userName, String subject,
                                        String rpSession, String requestMsgString, String relayState)
        throws IOException, ServletException, SAML2SSOUIAuthenticatorException {
    HttpSession session = req.getSession();

    // instantiate the service client
    String serverURL = CarbonUIUtil.getServerURL(session.getServletContext(), session);
    ConfigurationContext configContext = (ConfigurationContext) session.getServletContext()
            .getAttribute(CarbonConstants.CONFIGURATION_CONTEXT);
    SAMLSSOServiceClient ssoServiceClient = new SAMLSSOServiceClient(serverURL, configContext);

    // Create SAMLSSOAuthnReqDTO using the request Parameters
    SAMLSSOAuthnReqDTO authnReqDTO = new SAMLSSOAuthnReqDTO();

    authnReqDTO.setAssertionConsumerURL(assertionConsumerUrl);
    authnReqDTO.setId(id);
    authnReqDTO.setIssuer(issuer);
    //TODO FIX NEED TO BE DONE
    authnReqDTO.setUser(null);
    authnReqDTO.setPassword("federated_idp_login");
    authnReqDTO.setSubject(subject);
    authnReqDTO.setRpSessionId(rpSession);
    authnReqDTO.setRequestMessageString(requestMsgString);

    // authenticate the user
    SAMLSSORespDTO authRespDTO = ssoServiceClient.authenticate(authnReqDTO, ssoTokenID);

    if (authRespDTO.getSessionEstablished()) { // authentication is SUCCESSFUL
        // Store the cookie
        storeSSOTokenCookie(ssoTokenID, req, resp);
        // add relay state, assertion string and ACS URL as request parameters.
        req.setAttribute(SAMLConstants.RELAY_STATE, relayState);
        req.setAttribute(SAMLConstants.ASSERTION_STR, authRespDTO.getRespString());
        req.setAttribute(SAMLConstants.ASSRTN_CONSUMER_URL, authRespDTO.getAssertionConsumerURL());
        req.setAttribute(SAMLConstants.SUBJECT, authRespDTO.getSubject());
        RequestDispatcher reqDispatcher = req.getRequestDispatcher("/carbon/sso-acs/federation_ajaxprocessor.jsp");
        reqDispatcher.forward(req, resp);
        return;
    }
}
 
Example 19
Source File: BeanCollectionReportServlet.java    From carbon-commons with Apache License 2.0 4 votes vote down vote up
/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
 *
 * @param request  servlet request
 * @param response servlet response
 * @throws ReportingException if failed to handle report request
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws
        ReportingException {

    String component = request.getParameter("component");
    String template = request.getParameter("template");
    String type = request.getParameter("type");
    String reportData = request.getParameter("reportDataSession");
    String downloadFileName = null;

    if (component == null || template == null || type == null || reportData == null) {
        throw new ReportingException("required one or more parameters missing (component ,template , reportType, reportData)");
    }

    if (type.equals("pdf")) {
        response.setContentType("application/pdf");
        downloadFileName = template + ".pdf";
    } else if (type.equals("excel")) {
        response.setContentType("application/vnd.ms-excel");
        downloadFileName = template + ".xls";
    } else if (type.equals("html")) {
        response.setContentType("text/html");

    } else {
        throw new ReportingException("requested report type can not be support");
    }
    if (downloadFileName != null) {
        response.setHeader("Content-Disposition", "attachment; filename=\"" + downloadFileName + "\"");
    }
    Object reportDataObject = request.getSession().getAttribute(reportData);
    if (reportDataObject == null) {
        throw new ReportingException("can't generate report , data unavailable in session ");
    }

    try {
        String serverURL = CarbonUIUtil.getServerURL(request.getSession().getServletContext(), request.getSession());
        ConfigurationContext configurationContext = (ConfigurationContext) request.getSession().getServletContext().
                getAttribute(CarbonConstants.CONFIGURATION_CONTEXT);
        String cookie = (String) request.getSession().getAttribute(ServerConstants.ADMIN_SERVICE_COOKIE);

        ReportResourceSupplierClient resourceSupplierClient = new ReportResourceSupplierClient(cookie,
                serverURL, configurationContext);

        String reportResource = resourceSupplierClient.getReportResources(component, template);
        JRDataSource jrDataSource = new BeanCollectionReportData().getReportDataSource(reportDataObject);
        JasperPrintProvider jasperPrintProvider = new JasperPrintProvider();
        JasperPrint jasperPrint = jasperPrintProvider.createJasperPrint(jrDataSource ,reportResource, new ReportParamMap[0]);
        request.getSession().setAttribute(ImageServlet.DEFAULT_JASPER_PRINT_SESSION_ATTRIBUTE,jasperPrint);
        ReportStream reportStream = new ReportStream();
        ByteArrayOutputStream outputStream =  reportStream.getReportStream(jasperPrint,type);
        ServletOutputStream servletOutputStream = response.getOutputStream();
        try{
        outputStream.writeTo(servletOutputStream);
        outputStream.flush();
        }finally {
            outputStream.close();
            servletOutputStream.close();
        }

    } catch (Exception e) {
        String msg = "Error occurred handling " + template + "report request from " + component;
        log(msg);
        throw new ReportingException(msg, e);
    }
}
 
Example 20
Source File: Util.java    From carbon-identity-framework with Apache License 2.0 4 votes vote down vote up
public static boolean isUserOnBoardingEnabled(ServletContext context, HttpSession session) {

        if (!isAskPasswordAdminUIEnabled) {
            return false;
        }

        String backendServerURL = CarbonUIUtil.getServerURL(context, session);
        String cookie = (String) session.getAttribute(ServerConstants.ADMIN_SERVICE_COOKIE);
        ConfigurationContext configContext =
                (ConfigurationContext) context.getAttribute(CarbonConstants.CONFIGURATION_CONTEXT);
        Map<String, Map<String, List<ConnectorConfig>>> connectorList;
        try {
            IdentityGovernanceAdminClient client =
                    new IdentityGovernanceAdminClient(cookie, backendServerURL, configContext);
            connectorList = client.getConnectorList();
        } catch (Exception e) {
            log.error("Error while getting connector list from governance service, at URL :" +
                    backendServerURL, e);
            return false;
        }

        if (connectorList != null) {
            for (Map.Entry<String, Map<String, List<ConnectorConfig>>> entry : connectorList.entrySet()) {
                Map<String, List<ConnectorConfig>> subCatList = entry.getValue();
                for (String subCatKey : subCatList.keySet()) {
                    List<ConnectorConfig> connectorConfigs = subCatList.get(subCatKey);
                    for (ConnectorConfig connectorConfig : connectorConfigs) {
                        Property[] properties = connectorConfig.getProperties();
                        for (Property property : properties) {
                            if (property != null) {
                                if (EMAIL_VERIFICATION_ENABLE_PROP_NAME.equals(property.getName())) {
                                    String propValue = property.getValue();
                                    boolean isEmailVerificationEnabled = false;

                                    if (!StringUtils.isEmpty(propValue)) {
                                        isEmailVerificationEnabled = Boolean.parseBoolean(propValue);
                                    }
                                    return isEmailVerificationEnabled;
                                }
                            }
                        }
                    }
                }
            }
        }
        return false;
    }