org.wso2.carbon.utils.ServerConstants Java Examples
The following examples show how to use
org.wso2.carbon.utils.ServerConstants.
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: FileBasedConfigurationBuilder.java From carbon-identity with Apache License 2.0 | 6 votes |
private String replaceSystemProperty(String text) { int indexOfStartingChars = -1; int indexOfClosingBrace; String tmpText = null; // The following condition deals with properties. // Properties are specified as ${system.property}, // and are assumed to be System properties while (indexOfStartingChars < text.indexOf("${") && (indexOfStartingChars = text.indexOf("${")) != -1 && (indexOfClosingBrace = text.indexOf("}")) != -1) { // Is a property used? String sysProp = text.substring(indexOfStartingChars + 2, indexOfClosingBrace); String propValue = System.getProperty(sysProp); if (propValue != null) { tmpText = text.substring(0, indexOfStartingChars) + propValue + text.substring(indexOfClosingBrace + 1); } if ((ServerConstants.CARBON_HOME).equals(sysProp) && (".").equals(System.getProperty(ServerConstants.CARBON_HOME))) { tmpText = new File(".").getAbsolutePath() + File.separator + text; } } return tmpText; }
Example #2
Source File: ServerConfigurationManager.java From micro-integrator with Apache License 2.0 | 6 votes |
/** * backup the current server configuration file * * @param fileName file name * @throws IOException */ private void backupConfiguration(String fileName) throws IOException { //restore backup configuration String carbonHome = System.getProperty(ServerConstants.CARBON_HOME); String confDir = Paths.get(carbonHome, "conf").toString(); String axis2Xml = "axis2"; if (fileName.contains(axis2Xml)) { confDir = Paths.get(confDir, "axis2").toString(); } originalConfig = Paths.get(confDir, fileName).toFile(); backUpConfig = Paths.get(confDir, fileName + ".backup").toFile(); Files.move(originalConfig.toPath(), backUpConfig.toPath(), StandardCopyOption.REPLACE_EXISTING); if (originalConfig.exists()) { throw new IOException( "Failed to rename file from " + originalConfig.getName() + "to" + backUpConfig.getName()); } configData.add(new ConfigData(backUpConfig, originalConfig)); }
Example #3
Source File: STSAdminServiceImpl.java From carbon-identity with Apache License 2.0 | 6 votes |
@Override public void setProofKeyType(String keyType) throws SecurityConfigException { try { AxisService service = getAxisConfig().getService(ServerConstants.STS_NAME); Parameter origParam = service.getParameter(SAMLTokenIssuerConfig.SAML_ISSUER_CONFIG .getLocalPart()); if (origParam != null) { OMElement samlConfigElem = origParam.getParameterElement().getFirstChildWithName( SAMLTokenIssuerConfig.SAML_ISSUER_CONFIG); SAMLTokenIssuerConfig samlConfig = new SAMLTokenIssuerConfig(samlConfigElem); samlConfig.setProofKeyType(keyType); setSTSParameter(samlConfig); } else { throw new AxisFault("missing parameter : " + SAMLTokenIssuerConfig.SAML_ISSUER_CONFIG.getLocalPart()); } } catch (Exception e) { log.error("Error setting proof key type", e); throw new SecurityConfigException(e.getMessage(), e); } }
Example #4
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 #5
Source File: SampleAxis2Server.java From product-ei with Apache License 2.0 | 6 votes |
public SampleAxis2Server(String axis2xmlFile) { repositoryPath = System.getProperty(ServerConstants.CARBON_HOME) + File.separator + "samples" + File.separator + "axis2Server" + File.separator + "repository"; File repository = new File(repositoryPath); log.info("Using the Axis2 repository path: " + repository.getAbsolutePath()); try { File axis2xml = copyResourceToFileSystem(axis2xmlFile, "axis2.xml"); if (axis2xml == null) { log.error("Error while copying the test axis2.xml to the file system"); return; } log.info("Loading axis2.xml from: " + axis2xml.getAbsolutePath()); cfgCtx = ConfigurationContextFactory.createConfigurationContextFromFileSystem( repository.getAbsolutePath(), axis2xml.getAbsolutePath()); } catch (Exception e) { log.error("Error while initializing the configuration context", e); } }
Example #6
Source File: STSAdminServiceImpl.java From carbon-identity with Apache License 2.0 | 6 votes |
public void removeTrustedService(String serviceAddress) throws SecurityConfigException { try { AxisService stsService = getAxisConfig().getService(ServerConstants.STS_NAME); Parameter origParam = stsService.getParameter(SAMLTokenIssuerConfig.SAML_ISSUER_CONFIG .getLocalPart()); if (origParam != null) { OMElement samlConfigElem = origParam.getParameterElement().getFirstChildWithName( SAMLTokenIssuerConfig.SAML_ISSUER_CONFIG); SAMLTokenIssuerConfig samlConfig = new SAMLTokenIssuerConfig(samlConfigElem); samlConfig.getTrustedServices().remove(serviceAddress); setSTSParameter(samlConfig); removeTrustedService(ServerConstants.STS_NAME, ServerConstants.STS_NAME, serviceAddress); } else { throw new AxisFault("missing parameter : " + SAMLTokenIssuerConfig.SAML_ISSUER_CONFIG.getLocalPart()); } } catch (Exception e) { log.error("Error while removing a trusted service", e); throw new SecurityConfigException(e.getMessage(), e); } }
Example #7
Source File: IdentityTenantUtil.java From carbon-identity with Apache License 2.0 | 6 votes |
public static Registry getRegistry(String domainName, String username) throws IdentityException { HttpSession httpSess = getHttpSession(); if (httpSess != null) { if (httpSess.getAttribute(ServerConstants.USER_LOGGED_IN) != null) { try { return AdminServicesUtil.getSystemRegistry(); } catch (CarbonException e) { log.error("Error obtaining a registry instance", e); throw IdentityException.error( "Error obtaining a registry instance", e); } } } return getRegistryForAnonymousSession(domainName, username); }
Example #8
Source File: AbstractCarbonUIAuthenticator.java From attic-stratos with Apache License 2.0 | 6 votes |
/** * * @param session * @param serviceClient * @param rememberMeCookie * @throws AxisFault */ protected void setAdminCookie(HttpSession session, ServiceClient serviceClient, String rememberMeCookie) throws AxisFault { String cookie = (String) serviceClient.getServiceContext().getProperty( HTTPConstants.COOKIE_STRING); if (cookie == null) { // For local transport - the cookie will be null. // This generated cookie cannot be used for any form authentication with the backend. // This is done to be backward compatible. cookie = UUIDGenerator.generateUUID(); } if (rememberMeCookie != null) { cookie = cookie + "; " + rememberMeCookie; } if (session != null) { session.setAttribute(ServerConstants.ADMIN_SERVICE_AUTH_TOKEN, cookie); } }
Example #9
Source File: ThriftAuthenticationConfigParser.java From carbon-identity with Apache License 2.0 | 6 votes |
private String replaceSystemProperty(String text) { int indexOfStartingChars = -1; int indexOfClosingBrace; // The following condition deals with properties. // Properties are specified as ${system.property}, // and are assumed to be System properties while (indexOfStartingChars < text.indexOf("${") && (indexOfStartingChars = text.indexOf("${")) != -1 && (indexOfClosingBrace = text.indexOf("}")) != -1) { // Is a property used? String sysProp = text.substring(indexOfStartingChars + 2, indexOfClosingBrace); String propValue = System.getProperty(sysProp); if (propValue != null) { text = text.substring(0, indexOfStartingChars) + propValue + text.substring(indexOfClosingBrace + 1); } if (sysProp.equals(ServerConstants.CARBON_HOME) && ".".equals(System.getProperty(ServerConstants.CARBON_HOME)) ) { text = new File(".").getAbsolutePath() + File.separator + text; } } return text; }
Example #10
Source File: MediationLibraryServiceTestCase.java From micro-integrator with Apache License 2.0 | 6 votes |
/** * Wait until the zip file is copied to the synapse-libs directory or the default wait time is exceeded * * @param connectorZip */ private void waitUntilLibAvailable(String connectorZip) { String connectorZipPath = ServerConstants.CARBON_HOME + File.separator + "repository" + File.separator + "deployment" + File.separator + "server" + File.separator + "synapse-libs" + File.separator + connectorZip; File zipFile = new File(connectorZipPath); long startTime = System.currentTimeMillis(); while (((System.currentTimeMillis() - startTime) < 20000) && !zipFile.exists()) { try { Thread.sleep(500); } catch (InterruptedException e) { log.warn("Error while sleep the thread for 0.5 sec"); } } }
Example #11
Source File: MSMPCronForwarderCase.java From product-ei with Apache License 2.0 | 6 votes |
@BeforeClass(alwaysRun = true) protected void init() throws Exception { // START THE ESB super.init(); // START THE SERVER tomcatServerManager = new TomcatServerManager(CustomerConfig.class.getName(), TomcatServerType.jaxrs.name(), 8080); tomcatServerManager.startServer(); // staring tomcat server instance Awaitility.await().pollInterval(50, TimeUnit.MILLISECONDS).atMost(60, TimeUnit.SECONDS) .until(isServerStarted()); logAdmin = new LoggingAdminClient(contextUrls.getBackEndUrl(), getSessionCookie()); serverConfigurationManager = new ServerConfigurationManager(new AutomationContext("ESB", TestUserMode.SUPER_TENANT_ADMIN)); String carbonHome = System.getProperty(ServerConstants.CARBON_HOME); File log4jProperties = new File(carbonHome + File.separator + "conf" + File.separator + "log4j2.properties"); applyProperty(log4jProperties, "logger.org-apache-synapse.level", "DEBUG"); serverConfigurationManager.restartGracefully(); super.init(); }
Example #12
Source File: ESBJAVA4931PreserveContentTypeHeaderCharSetTestCase.java From micro-integrator with Apache License 2.0 | 6 votes |
@BeforeTest(alwaysRun = true) public void init() throws Exception { super.init(); wireMonitorServer = new WireMonitorServer(6780); wireMonitorServer.start(); File sourceFile = new File( getESBResourceLocation() + File.separator + "passthru" + File.separator + "transport" + File.separator + "ESBJAVA4931" + File.separator + "sample_proxy_3.wsdl"); File targetFile = new File( System.getProperty(ServerConstants.CARBON_HOME) + File.separator + "samples" + File.separator + "service-bus" + File.separator + "resources" + File.separator + "proxy" + File.separator + "sample_proxy_3.wsdl"); FileUtils.copyFile(sourceFile, targetFile); verifyProxyServiceExistence("PreserveContentTypeHeaderCharSetTestProxy"); }
Example #13
Source File: MediationLibraryServiceTestCase.java From product-ei with Apache License 2.0 | 6 votes |
/** * Wait until the zip file is copied to the synapse-libs directory or the default wait time is exceeded * * @param connectorZip */ private void waitUntilLibAvailable(String connectorZip) { String connectorZipPath = ServerConstants.CARBON_HOME + File.separator + "repository" + File.separator + "deployment" + File.separator + "server" + File.separator + "synapse-libs" + File.separator + connectorZip; File zipFile = new File(connectorZipPath); long startTime = System.currentTimeMillis(); while (((System.currentTimeMillis() - startTime) < 20000) && !zipFile.exists()) { try { Thread.sleep(500); } catch (InterruptedException e) { log.warn("Error while sleep the thread for 0.5 sec"); } } }
Example #14
Source File: HttpAccessLogTestCase.java From product-ei with Apache License 2.0 | 6 votes |
@BeforeClass(alwaysRun = true) public void init() throws Exception { super.init(); serverConfigurationManager = new ServerConfigurationManager(new AutomationContext("ESB", TestUserMode.SUPER_TENANT_ADMIN)); String nhttpFile = FrameworkPathUtil.getSystemResourceLocation() + "artifacts" + separator + "ESB" + separator + "passthru" + separator + "transport" + separator + "httpaccesslogs" + separator + "access-log.properties"; File srcFile = new File(nhttpFile); String carbonHome = System.getProperty(ServerConstants.CARBON_HOME); httpLogDir = carbonHome + File.separator + "repository" + File.separator + "logs" + File.separator + "httpLogs"; File log4jProperties = new File(carbonHome + File.separator + "conf" + File.separator + "log4j2.properties"); String propertyName = "nhttp.log.directory"; createNewDir(httpLogDir); applyProperty(srcFile, propertyName, httpLogDir); applyProperty(log4jProperties, "logger.synapse-transport-http-access.level", "DEBUG"); serverConfigurationManager.restartGracefully(); super.init(); verifyProxyServiceExistence("HttpAccessLogsTestProxy"); }
Example #15
Source File: Axis2ServerManager.java From micro-integrator with Apache License 2.0 | 6 votes |
public Axis2ServerManager(String axis2xmlFile) { repositoryPath = System.getProperty(ServerConstants.CARBON_HOME) + File.separator + "samples" + File.separator + "axis2Server" + File.separator + "repository"; File repository = new File(repositoryPath); log.info("Using the Axis2 repository path: " + repository.getAbsolutePath()); try { File axis2xml = copyResourceToFileSystem(axis2xmlFile, "axis2.xml"); if (!axis2xml.exists()) { log.error("Error while copying the test axis2.xml to the file system"); return; } log.info("Loading axis2.xml from: " + axis2xml.getAbsolutePath()); cfgCtx = ConfigurationContextFactory .createConfigurationContextFromFileSystem(repository.getAbsolutePath(), axis2xml.getAbsolutePath()); } catch (Exception e) { log.error("Error while initializing the configuration context", e); } }
Example #16
Source File: FileBasedConfigurationBuilder.java From carbon-identity-framework with Apache License 2.0 | 6 votes |
private String replaceSystemProperty(String text) { int indexOfStartingChars = -1; int indexOfClosingBrace; String tmpText = null; // The following condition deals with properties. // Properties are specified as ${system.property}, // and are assumed to be System properties while (indexOfStartingChars < text.indexOf("${") && (indexOfStartingChars = text.indexOf("${")) != -1 && (indexOfClosingBrace = text.indexOf("}")) != -1) { // Is a property used? String sysProp = text.substring(indexOfStartingChars + 2, indexOfClosingBrace); String propValue = System.getProperty(sysProp); if (propValue != null) { tmpText = text.substring(0, indexOfStartingChars) + propValue + text.substring(indexOfClosingBrace + 1); } if ((ServerConstants.CARBON_HOME).equals(sysProp) && (".").equals(System.getProperty(ServerConstants.CARBON_HOME))) { tmpText = new File(".").getAbsolutePath() + File.separator + text; } } return tmpText; }
Example #17
Source File: ThriftAuthenticationConfigParser.java From carbon-identity-framework with Apache License 2.0 | 6 votes |
private String replaceSystemProperty(String text) { int indexOfStartingChars = -1; int indexOfClosingBrace; // The following condition deals with properties. // Properties are specified as ${system.property}, // and are assumed to be System properties while (indexOfStartingChars < text.indexOf("${") && (indexOfStartingChars = text.indexOf("${")) != -1 && (indexOfClosingBrace = text.indexOf("}")) != -1) { // Is a property used? String sysProp = text.substring(indexOfStartingChars + 2, indexOfClosingBrace); String propValue = System.getProperty(sysProp); if (propValue != null) { text = text.substring(0, indexOfStartingChars) + propValue + text.substring(indexOfClosingBrace + 1); } if (sysProp.equals(ServerConstants.CARBON_HOME) && ".".equals(System.getProperty(ServerConstants.CARBON_HOME)) ) { text = new File(".").getAbsolutePath() + File.separator + text; } } return text; }
Example #18
Source File: IdentityConfigParser.java From carbon-identity-framework with Apache License 2.0 | 6 votes |
private String replaceSystemProperty(String text) { int indexOfStartingChars = -1; int indexOfClosingBrace; // The following condition deals with properties. // Properties are specified as ${system.property}, // and are assumed to be System properties while (indexOfStartingChars < text.indexOf("${") && (indexOfStartingChars = text.indexOf("${")) != -1 && (indexOfClosingBrace = text.indexOf("}")) != -1) { // Is a property used? String sysProp = text.substring(indexOfStartingChars + 2, indexOfClosingBrace); String propValue = System.getProperty(sysProp); if (propValue != null) { text = text.substring(0, indexOfStartingChars) + propValue + text.substring(indexOfClosingBrace + 1); } if (sysProp.equals(ServerConstants.CARBON_HOME)) { if (System.getProperty(ServerConstants.CARBON_HOME).equals(".")) { text = new File(".").getAbsolutePath() + File.separator + text; } } } return text; }
Example #19
Source File: AuthenticationAdminClient.java From carbon-commons with Apache License 2.0 | 6 votes |
public boolean login(HttpServletRequest request, String username, String password) throws java.lang.Exception { log.info("Logging into " + backendServerURL); Login loginRequest = new Login(); loginRequest.setUsername(username); loginRequest.setPassword(password); loginRequest.setRemoteAddress(request.getRemoteAddr()); Options option = stub._getServiceClient().getOptions(); option.setManageSession(true); boolean isLoggedIn = false; try { isLoggedIn = stub.login(username, password, request.getRemoteAddr()); if (isLoggedIn) { String cookie = (String) stub._getServiceClient().getServiceContext(). getProperty(HTTPConstants.COOKIE_STRING); HttpSession session = request.getSession(); session.setAttribute(ServerConstants.ADMIN_SERVICE_COOKIE, cookie); } } catch (java.lang.Exception e) { String msg = MessageFormat.format(bundle.getString("cannot.login.to.server"), backendServerURL); handleException(msg, e); } return isLoggedIn; }
Example #20
Source File: IdentityTenantUtil.java From carbon-identity-framework with Apache License 2.0 | 6 votes |
public static Registry getRegistry(String domainName, String username) throws IdentityException { HttpSession httpSess = getHttpSession(); if (httpSess != null) { if (httpSess.getAttribute(ServerConstants.USER_LOGGED_IN) != null) { try { return AdminServicesUtil.getSystemRegistry(); } catch (CarbonException e) { log.error("Error obtaining a registry instance", e); throw IdentityException.error( "Error obtaining a registry instance", e); } } } return getRegistryForAnonymousSession(domainName, username); }
Example #21
Source File: AxisOperationClient.java From product-ei with Apache License 2.0 | 6 votes |
public AxisOperationClient() { String repositoryPath = System.getProperty(ServerConstants.CARBON_HOME) + File.separator + "samples" + File.separator + "axis2Server" + File.separator + "repository"; File repository = new File(repositoryPath); log.info("Using the Axis2 repository path: " + repository.getAbsolutePath()); try { cfgCtx = ConfigurationContextFactory.createConfigurationContextFromFileSystem(repository.getCanonicalPath(), null); serviceClient = new ServiceClient(cfgCtx, null); log.info("Sample clients initialized successfully..."); } catch (Exception e) { log.error("Error while initializing the Operational Client", e); } }
Example #22
Source File: Axis2ServerManager.java From product-ei with Apache License 2.0 | 6 votes |
public Axis2ServerManager(String axis2xmlFile) { repositoryPath = System.getProperty(ServerConstants.CARBON_HOME) + File.separator + "samples" + File.separator + "axis2Server" + File.separator + "repository"; File repository = new File(repositoryPath); log.info("Using the Axis2 repository path: " + repository.getAbsolutePath()); try { File axis2xml = copyResourceToFileSystem(axis2xmlFile, "axis2.xml"); if (!axis2xml.exists()) { log.error("Error while copying the test axis2.xml to the file system"); return; } log.info("Loading axis2.xml from: " + axis2xml.getAbsolutePath()); cfgCtx = ConfigurationContextFactory.createConfigurationContextFromFileSystem( repository.getAbsolutePath(), axis2xml.getAbsolutePath()); } catch (Exception e) { log.error("Error while initializing the configuration context", e); } }
Example #23
Source File: XMPPConfigurationService.java From carbon-identity with Apache License 2.0 | 6 votes |
/** * @param username * @param operation * @throws IdentityProviderException */ private void checkUserAuthorization(String username, String operation) throws IdentityProviderException { MessageContext msgContext = MessageContext.getCurrentMessageContext(); HttpServletRequest request = (HttpServletRequest) msgContext.getProperty(HTTPConstants.MC_HTTP_SERVLETREQUEST); HttpSession httpSession = request.getSession(false); if (httpSession != null) { String userName = (String) httpSession.getAttribute(ServerConstants.USER_LOGGED_IN); if (!username.equals(userName)) { throw new IdentityProviderException("Unauthorised action by user " + username + " to access " + operation); } return; } throw new IdentityProviderException("Unauthorised action by user " + username + " to access " + operation); }
Example #24
Source File: IdentityProviderService.java From carbon-identity with Apache License 2.0 | 6 votes |
/** * @param username * @param operation * @throws IdentityProviderException */ private void checkUserAuthorization(String username, String operation) throws IdentityProviderException { MessageContext msgContext = MessageContext.getCurrentMessageContext(); HttpServletRequest request = (HttpServletRequest) msgContext.getProperty(HTTPConstants.MC_HTTP_SERVLETREQUEST); HttpSession httpSession = request.getSession(false); String tenantFreeUsername = MultitenantUtils.getTenantAwareUsername(username); if (httpSession != null) { String loggedInUsername = (String) httpSession.getAttribute(ServerConstants.USER_LOGGED_IN); if (!tenantFreeUsername.equals(loggedInUsername)) { throw new IdentityProviderException("Unauthorised action by user " + username + " to access " + operation); } } else { throw new IdentityProviderException("Unauthorised action by user " + tenantFreeUsername + " to access " + operation); } }
Example #25
Source File: AxisOperationClient.java From micro-integrator with Apache License 2.0 | 6 votes |
public AxisOperationClient() { String repositoryPath = System.getProperty(ServerConstants.CARBON_HOME) + File.separator + "samples" + File.separator + "axis2Server" + File.separator + "repository"; File repository = new File(repositoryPath); log.info("Using the Axis2 repository path: " + repository.getAbsolutePath()); try { cfgCtx = ConfigurationContextFactory .createConfigurationContextFromFileSystem(repository.getCanonicalPath(), null); serviceClient = new ServiceClient(cfgCtx, null); log.info("Sample clients initialized successfully..."); } catch (Exception e) { log.error("Error while initializing the Operational Client", e); } }
Example #26
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 #27
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 #28
Source File: MultipleCredentialsUserProxy.java From carbon-identity with Apache License 2.0 | 5 votes |
/** * Gets logged in user of the server * * @return user name */ private String getLoggedInUser() { MessageContext context = MessageContext.getCurrentMessageContext(); if (context != null) { HttpServletRequest request = (HttpServletRequest) context.getProperty(HTTPConstants.MC_HTTP_SERVLETREQUEST); if (request != null) { HttpSession httpSession = request.getSession(false); return (String) httpSession.getAttribute(ServerConstants.USER_LOGGED_IN); } } return null; }
Example #29
Source File: OauthAuthenticator.java From carbon-device-mgt with Apache License 2.0 | 5 votes |
/** * Authenticates the user using the provided OAuth token and returns the status as a boolean. * Sets the tenant domain and tenant friendly username to the session as attributes. * * @param messageContext containing the request need to be authenticated. * @return boolean indicating the authentication status. */ public boolean isAuthenticated(MessageContext messageContext) { HttpServletRequest httpServletRequest = getHttpRequest(messageContext); String headerValue = httpServletRequest.getHeader(HTTPConstants.HEADER_AUTHORIZATION); String[] headerPart = headerValue.trim().split(OauthAuthenticatorConstants.SPLITING_CHARACTOR); String accessToken = headerPart[ACCESS_TOKEN_INDEX]; OAuthValidationResponse response = null; try { response = tokenValidator.validateToken(accessToken); } catch (RemoteException e) { log.error("Failed to validate the OAuth token provided.", e); } if (response != null && response.isValid()) { HttpSession session; if ((session = httpServletRequest.getSession(false)) != null) { session.setAttribute(MultitenantConstants.TENANT_DOMAIN, response.getTenantDomain()); session.setAttribute(ServerConstants.USER_LOGGED_IN, response.getUserName()); if (log.isDebugEnabled()) { log.debug("Authentication successful for " + session.getAttribute(ServerConstants.USER_LOGGED_IN)); } } return true; } if (log.isDebugEnabled()) { log.debug("Authentication failed.Illegal attempt from session " + httpServletRequest.getSession().getId()); } return false; }
Example #30
Source File: ESServerExtension.java From product-es with Apache License 2.0 | 5 votes |
public void onExecutionStart() { try { if (executionEnvironment.equalsIgnoreCase(ExecutionEnvironment.STANDALONE.name())) { String carbonHome = serverManager.startServer(); System.setProperty(ServerConstants.CARBON_HOME, carbonHome); // log.info("#### Delaying test startup for 20s in order to allow assets to be indexed #### "); // Thread.sleep(20000); } } catch (Exception e) { handleException("Fail to start carbon server ", e); } }