org.wso2.carbon.ui.CarbonUIUtil Java Examples
The following examples show how to use
org.wso2.carbon.ui.CarbonUIUtil.
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 |
/** * {@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: STSUtil.java From carbon-identity with Apache License 2.0 | 6 votes |
/** * Initializes STSUtil * * @param cookie Cookie string * @throws Exception */ public STSUtil(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 #3
Source File: CarbonSTSClient.java From carbon-identity with Apache License 2.0 | 6 votes |
/** * 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: reportUploadExecutor.java From carbon-commons with Apache License 2.0 | 6 votes |
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 #5
Source File: CompositeReportProcessor.java From carbon-commons with Apache License 2.0 | 6 votes |
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 #6
Source File: RegistryAdminServiceClient.java From attic-stratos with Apache License 2.0 | 6 votes |
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 #7
Source File: Util.java From carbon-commons with Apache License 2.0 | 6 votes |
public static String getRelativeUrl() { BundleContext context = CarbonUIUtil.getBundleContext(); ServiceReference reference = context.getServiceReference(RegistryService.class.getName()); RegistryService registryService = (RegistryService) context.getService(reference); String url = null; try { Registry systemRegistry = registryService.getConfigSystemRegistry(); Resource resource = systemRegistry.get(RegistryResources.CONNECTION_PROPS); String servicePath = resource.getProperty("service-path"); String contextRoot = resource.getProperty("context-root"); contextRoot = contextRoot.equals("/") ? "" : contextRoot; url = contextRoot + servicePath + "/WSDL2CodeService"; } catch (Exception e) { log.error(e); } return url; }
Example #8
Source File: Util.java From carbon-commons with Apache License 2.0 | 6 votes |
public static String getRelativeUrl() { BundleContext context = CarbonUIUtil.getBundleContext(); ServiceReference reference = context.getServiceReference(RegistryService.class.getName()); RegistryService registryService = (RegistryService) context.getService(reference); String url = null; try { Registry systemRegistry = registryService.getConfigSystemRegistry(); Resource resource = systemRegistry.get(RegistryResources.CONNECTION_PROPS); String servicePath = resource.getProperty("service-path"); String contextRoot = resource.getProperty("context-root"); contextRoot = contextRoot.equals("/") ? "" : contextRoot; url = contextRoot + servicePath + "/WSDL2CodeService"; } catch (Exception e) { log.error(e); } return url; }
Example #9
Source File: Util.java From carbon-commons with Apache License 2.0 | 6 votes |
public static String getRelativeUrl() { BundleContext context = CarbonUIUtil.getBundleContext(); ServiceReference reference = context.getServiceReference(RegistryService.class .getName()); RegistryService registryService = (RegistryService) context.getService(reference); String url = null; try { Registry systemRegistry = registryService.getConfigSystemRegistry(); Resource resource = systemRegistry.get("/carbon/connection/props"); String servicePath = resource.getProperty("service-path"); String contextRoot = resource.getProperty("context-root"); contextRoot = contextRoot.equals("/") ? "" : contextRoot; url = contextRoot + servicePath + "/Java2WSDLService"; } catch (Exception e) { log.error(e); } return url; }
Example #10
Source File: IWAUIAuthenticator.java From carbon-identity with Apache License 2.0 | 6 votes |
/** * @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 #11
Source File: EmailVerificationServiceClient.java From carbon-commons with Apache License 2.0 | 6 votes |
public EmailVerificationServiceClient(ServletConfig config, HttpSession session) throws RegistryException { 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); epr = backendServerURL + "EmailVerificationService"; try { stub = new EmailVerificationServiceStub(configContext, epr); ServiceClient client = stub._getServiceClient(); Options option = client.getOptions(); option.setManageSession(true); option.setProperty(org.apache.axis2.transport.http.HTTPConstants.COOKIE_STRING, cookie); } catch (AxisFault axisFault) { String msg = "Failed to initiate Add Services service client. " + axisFault.getMessage(); log.error(msg, axisFault); throw new RegistryException(msg, axisFault); } }
Example #12
Source File: ReportResourceSupplierClient.java From carbon-commons with Apache License 2.0 | 5 votes |
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 #13
Source File: ReportResourceSupplierClient.java From carbon-commons with Apache License 2.0 | 5 votes |
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 #14
Source File: ReportGenerator.java From carbon-commons with Apache License 2.0 | 5 votes |
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 #15
Source File: UIUtils.java From carbon-commons with Apache License 2.0 | 5 votes |
/** * 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 #16
Source File: Report.java From attic-stratos with Apache License 2.0 | 5 votes |
public int doStartTag() throws JspException { //check permission. HttpServletRequest req = (HttpServletRequest) pageContext.getRequest(); if(!CarbonUIUtil.isUserAuthorized(req, "/permission/admin/manage/report")){ return EVAL_PAGE; } JspWriter writer = pageContext.getOut(); String context = "<div style='float:right;padding-bottom:5px;padding-right:15px;'>"; if(pdfReport){ context = context+ "<a target='_blank' class='icon-link' style='background-image:url(../admin/images/pdficon.gif);' href=\"../report" + "?" +"reportDataSession="+ reportDataSession + "&component=" + component + "&template=" + template + "&type=pdf" + "\">Generate Pdf Report</a>"; } if(htmlReport){ context = context+ "<a target='_blank' class='icon-link' style='background-image:url(../admin/images/htmlicon.gif);' href=\"../report" + "?" + "reportDataSession="+ reportDataSession + "&component=" + component + "&template=" + template + "&type=html" + "\">Generate Html Report</a>"; } if(excelReport){ context = context+ "<a target='_blank' class='icon-link' style='background-image:url(../admin/images/excelicon.gif);' href=\"../report" + "?" + "reportDataSession="+ reportDataSession + "&component=" + component + "&template=" + template + "&type=excel" +"\">Generate Excel Report</a>"; } context = context + "</div><div style='clear:both;'></div>"; try { writer.write(context); } catch (IOException e) { String msg = "Cannot write reporting tag content"; throw new JspException(msg, e); } return EVAL_PAGE; }
Example #17
Source File: JSi18n.java From attic-stratos with Apache License 2.0 | 5 votes |
public static Locale getLocaleFromPageContext(PageContext pageContext) { if (pageContext.getSession().getAttribute(CarbonUIUtil.SESSION_PARAM_LOCALE) != null) { return CarbonUIUtil.toLocale(pageContext.getSession().getAttribute(CarbonUIUtil.SESSION_PARAM_LOCALE).toString()); }else{ return pageContext.getRequest().getLocale(); } }
Example #18
Source File: FileUploadExecutorManager.java From attic-stratos with Apache License 2.0 | 5 votes |
/** * When a FileUpload request is received, this method will be called. * * @param request The HTTP Request * @param response The HTTP Response * @return true - if the file uploading was successful, false - otherwise * @throws IOException If an unrecoverable error occurs during file upload */ public boolean execute(HttpServletRequest request, HttpServletResponse response) throws IOException { HttpSession session = request.getSession(); String cookie = (String) session.getAttribute(ServerConstants.ADMIN_SERVICE_COOKIE); request.setAttribute(CarbonConstants.ADMIN_SERVICE_COOKIE, cookie); request.setAttribute(CarbonConstants.WEB_CONTEXT, webContext); request.setAttribute(CarbonConstants.SERVER_URL, CarbonUIUtil.getServerURL(request.getSession().getServletContext(), request.getSession())); String requestURI = request.getRequestURI(); //TODO - fileupload is hardcoded int indexToSplit = requestURI.indexOf("fileupload/") + "fileupload/".length(); String actionString = requestURI.substring(indexToSplit); // Register execution handlers FileUploadExecutionHandlerManager execHandlerManager = new FileUploadExecutionHandlerManager(); CarbonXmlFileUploadExecHandler carbonXmlExecHandler = new CarbonXmlFileUploadExecHandler(request, response, actionString); execHandlerManager.addExecHandler(carbonXmlExecHandler); OSGiFileUploadExecHandler osgiExecHandler = new OSGiFileUploadExecHandler(request, response); execHandlerManager.addExecHandler(osgiExecHandler); AnyFileUploadExecHandler anyFileExecHandler = new AnyFileUploadExecHandler(request, response); execHandlerManager.addExecHandler(anyFileExecHandler); execHandlerManager.startExec(); return true; }
Example #19
Source File: OpenIDUtil.java From carbon-identity with Apache License 2.0 | 5 votes |
/** * 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 #20
Source File: JrxmlFileUploaderClient.java From carbon-commons with Apache License 2.0 | 5 votes |
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 #21
Source File: SSOAssertionConsumerService.java From carbon-identity with Apache License 2.0 | 5 votes |
/** * Get the admin console url from the request. * * @param request httpServletReq that hits the ACS Servlet * @return Admin Console URL https://10.100.1.221:8443/acs/carbon/ */ private String getAdminConsoleURL(HttpServletRequest request) { String url = CarbonUIUtil.getAdminConsoleURL(request); if (!url.endsWith("/")) { url = url + "/"; } if (url.indexOf("/acs") != -1) { url = url.replace("/acs", ""); } return url; }
Example #22
Source File: NDataSourceAdminServiceClient.java From carbon-commons with Apache License 2.0 | 5 votes |
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 #23
Source File: OIDCAssertionConsumerService.java From carbon-apimgt with Apache License 2.0 | 5 votes |
/** * Get the admin console url from the request. * * @param request httpServletReq that hits the ACS Servlet * @return Admin Console URL https://10.100.1.221:9443/oidcacs/carbon/ */ private String getAdminConsoleURL(HttpServletRequest request) { String url = CarbonUIUtil.getAdminConsoleURL(request); if (!url.endsWith("/")) { url = url + "/"; } if (url.contains("/oidcacs")) { url = url.replace("/oidcacs", ""); } return url; }
Example #24
Source File: OIDCUIAuthenticator.java From carbon-apimgt with Apache License 2.0 | 5 votes |
@Override public void unauthenticate(Object o) throws Exception { HttpServletRequest request = (HttpServletRequest) o; HttpSession session = request.getSession(); String username = (String) session.getAttribute(CarbonConstants.LOGGED_USER); ServletContext servletContext = session.getServletContext(); ConfigurationContext configContext = (ConfigurationContext) servletContext .getAttribute(CarbonConstants.CONFIGURATION_CONTEXT); String backendServerURL = CarbonUIUtil.getServerURL(servletContext, session); try { String cookie = (String) session.getAttribute(ServerConstants. ADMIN_SERVICE_AUTH_TOKEN); OIDCAuthenticationClient authClient = new OIDCAuthenticationClient(configContext, backendServerURL, cookie, session); authClient.logout(session); log.info(username + "@" + PrivilegedCarbonContext.getThreadLocalCarbonContext(). getTenantDomain() +" successfully logged out"); } catch (Exception ignored) { String msg = "OIDC logout failed"; log.error(msg, ignored); throw new Exception(msg, ignored); } String logoutUrl = Util.getIdentityProviderURI() + "logout"; request.setAttribute(OIDCConstants.HTTP_ATTR_IS_LOGOUT_REQ, true); request.setAttribute(OIDCConstants.EXTERNAL_LOGOUT_PAGE, logoutUrl); }
Example #25
Source File: DBReportingServiceClient.java From carbon-commons with Apache License 2.0 | 5 votes |
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 #26
Source File: SSOAssertionConsumerService.java From carbon-identity with Apache License 2.0 | 5 votes |
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 #27
Source File: AuthenticationRequestBuilder.java From carbon-identity with Apache License 2.0 | 5 votes |
/** * Generate an authentication request with passive support. * * @return AuthnRequest Object * @throws Exception */ public AuthnRequest buildAuthenticationRequest(String subjectName, String nameIdPolicyFormat, boolean isPassive) throws Exception { if (log.isDebugEnabled()) { log.debug("Building Authentication Request"); } Util.doBootstrap(); AuthnRequest authnRequest = (AuthnRequest) Util .buildXMLObject(AuthnRequest.DEFAULT_ELEMENT_NAME); authnRequest.setID(Util.createID()); authnRequest.setVersion(SAMLVersion.VERSION_20); authnRequest.setIssueInstant(new DateTime()); authnRequest.setIssuer(buildIssuer()); authnRequest.setNameIDPolicy(buildNameIDPolicy(nameIdPolicyFormat)); authnRequest.setIsPassive(isPassive); authnRequest.setDestination(Util.getIdentityProviderSSOServiceURL()); String acs = Util.getAssertionConsumerServiceURL(); if (acs != null && acs.trim().length() > 0) { authnRequest.setAssertionConsumerServiceURL(acs); } else { authnRequest.setAssertionConsumerServiceURL(CarbonUIUtil.getAdminConsoleURL("").replace("carbon/", "acs")); } if (subjectName != null) { Subject subject = new SubjectBuilder().buildObject(); NameID nameId = new NameIDBuilder().buildObject(); nameId.setValue(subjectName); nameId.setFormat(NameIdentifier.EMAIL); subject.setNameID(nameId); authnRequest.setSubject(subject); } Util.setSignature(authnRequest, XMLSignature.ALGO_ID_SIGNATURE_RSA, new SignKeyDataHolder()); return authnRequest; }
Example #28
Source File: OIDCUIAuthenticator.java From carbon-apimgt with Apache License 2.0 | 4 votes |
@Override public void authenticate(HttpServletRequest request) throws AuthenticationException { String username = ""; HttpSession session = request.getSession(); String responseCode = request.getParameter(OIDCConstants.PARAM_CODE); String sessionNonce = (String) request.getSession().getAttribute( OIDCConstants.PARAM_NONCE); ServletContext servletContext = request.getSession().getServletContext(); ConfigurationContext configContext = (ConfigurationContext) servletContext.getAttribute( CarbonConstants.CONFIGURATION_CONTEXT); String backEndServerURL = request.getParameter("backendURL"); if (backEndServerURL == null) { backEndServerURL = CarbonUIUtil.getServerURL(servletContext, session); } session.setAttribute(CarbonConstants.SERVER_URL, backEndServerURL); String cookie = (String) session.getAttribute(ServerConstants. ADMIN_SERVICE_AUTH_TOKEN); // authorize the user with the back-end OIDCAuthenticationClient authenticationClient; try { if (log.isDebugEnabled()) { log.debug("Invoking the OIDC Authenticator BE for the Response Code : " + responseCode); } authenticationClient = new OIDCAuthenticationClient( configContext, backEndServerURL, cookie, session); username = authenticationClient.login(responseCode, sessionNonce); // add an entry to CarbonSSOSessionManager : IdpSessionIndex --> localSessionId if (username != null && !username.equals("")) { CarbonSSOSessionManager oidcSessionManager = OIDCAuthFEDataHolder. getInstance().getCarbonSSOSessionManager(); if (responseCode != null) { // Session id is provided only when Single Logout enabled at the IdP. oidcSessionManager.addSessionMapping(responseCode, session.getId()); request.getSession().setAttribute(OIDCConstants.IDP_SESSION_INDEX, responseCode); } onSuccessAdminLogin(request, username); } else { log.error("Authentication failed due to empty user name"); throw new AuthenticationException("Authentication failed due to empty user name"); } } catch (Exception e) { log.error("Error when login to OIDC server", e); throw new AuthenticationException("Error when login to OIDC server.", e); } if (username == null || username.equals("")) { throw new AuthenticationException("Authentication failure " + username); } }
Example #29
Source File: UIAnnouncementDeployer.java From attic-stratos with Apache License 2.0 | 4 votes |
public static void deployNotificationSources() { BundleContext bundleContext = CarbonUIUtil.getBundleContext(); uiAnnouncementTracker = new ServiceTracker(bundleContext, UIAnnouncement.class.getName(), null); uiAnnouncementTracker.open(); }
Example #30
Source File: PassiveSTS.java From carbon-identity with Apache License 2.0 | 4 votes |
private void process(HttpServletRequest request, HttpServletResponse response, SessionDTO sessionDTO, AuthenticationResult authnResult) throws ServletException, IOException { HttpSession session = request.getSession(); session.removeAttribute(PassiveRequestorConstants.PASSIVE_REQ_ATTR_MAP); RequestToken reqToken = new RequestToken(); Map<ClaimMapping, String> attrMap = authnResult.getSubject().getUserAttributes(); StringBuilder buffer = null; if (MapUtils.isNotEmpty(attrMap)) { buffer = new StringBuilder(); for (Iterator<Entry<ClaimMapping, String>> iterator = attrMap.entrySet().iterator(); iterator .hasNext(); ) { Entry<ClaimMapping, String> entry = iterator.next(); buffer.append("{" + entry.getKey().getRemoteClaim().getClaimUri() + "|" + entry.getValue() + "}#CODE#"); } } reqToken.setAction(sessionDTO.getAction()); if (buffer != null) { reqToken.setAttributes(buffer.toString()); } else { reqToken.setAttributes(sessionDTO.getAttributes()); } reqToken.setContext(sessionDTO.getContext()); reqToken.setReplyTo(sessionDTO.getReplyTo()); reqToken.setPseudo(sessionDTO.getPseudo()); reqToken.setRealm(sessionDTO.getRealm()); reqToken.setRequest(sessionDTO.getRequest()); reqToken.setRequestPointer(sessionDTO.getRequestPointer()); reqToken.setPolicy(sessionDTO.getPolicy()); reqToken.setPseudo(session.getId()); reqToken.setUserName(authnResult.getSubject().getAuthenticatedSubjectIdentifier()); reqToken.setTenantDomain(sessionDTO.getTenantDomain()); String serverURL = CarbonUIUtil.getServerURL(session.getServletContext(), session); ConfigurationContext configContext = (ConfigurationContext) session.getServletContext().getAttribute(CarbonConstants.CONFIGURATION_CONTEXT); IdentityPassiveSTSClient passiveSTSClient = null; passiveSTSClient = new IdentityPassiveSTSClient(serverURL, configContext); ResponseToken respToken = passiveSTSClient.getResponse(reqToken); if (respToken != null && respToken.getResults() != null) { persistRealms(reqToken, request.getSession()); sendData(response, respToken, reqToken.getAction(), authnResult.getAuthenticatedIdPs()); } }