Java Code Examples for org.wso2.carbon.utils.CarbonUtils#getCarbonHome()
The following examples show how to use
org.wso2.carbon.utils.CarbonUtils#getCarbonHome() .
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: EntitlementUtil.java From carbon-identity-framework with Apache License 2.0 | 6 votes |
public static void addSamplePolicies(Registry registry) { File policyFolder = new File(CarbonUtils.getCarbonHome() + File.separator + "repository" + File.separator + "resources" + File.separator + "identity" + File.separator + "policies" + File.separator + "xacml" + File.separator + "default"); File[] fileList; if (policyFolder.exists() && ArrayUtils.isNotEmpty(fileList = policyFolder.listFiles())) { for (File policyFile : fileList) { if (policyFile.isFile()) { PolicyDTO policyDTO = new PolicyDTO(); try { policyDTO.setPolicy(FileUtils.readFileToString(policyFile)); EntitlementUtil.addFilesystemPolicy(policyDTO, registry, false); } catch (Exception e) { // log and ignore log.error("Error while adding sample XACML policies", e); } } } } }
Example 2
Source File: AmqpTopicConnector.java From attic-stratos with Apache License 2.0 | 6 votes |
@Override public void create() { try { String jndiPropFileDir = System.getProperty("jndi.properties.dir"); if(StringUtils.isEmpty(jndiPropFileDir)) { // jndi.properties.dir system property not found, set default jndiPropFileDir = CarbonUtils.getCarbonHome() + File.separator + "repository" + File.separator + "conf"; } Properties environment = MessagingUtil.getProperties(jndiPropFileDir + File.separator + "jndi.properties"); mbUsername = environment.getProperty("java.naming.security.principal"); mbPassword =environment.getProperty("java.naming.security.credentials"); environment.put("org.wso2.carbon.context.RequestBaseContext", "true"); // always returns the base context. initialContext = new InitialContext(environment); // Lookup connection factory String connectionFactoryName = environment.get("connectionfactoryName").toString(); connectionFactory = (TopicConnectionFactory) initialContext.lookup(connectionFactoryName); } catch (Exception e) { String message = "Could not create topic connector"; log.error(message, e); throw new MessagingException(message, e); } }
Example 3
Source File: ZipUtil.java From product-iots with Apache License 2.0 | 5 votes |
/** * Get agent sketch. * * @param archivesPath Path of the zip file to create. * @param templateSketchPath Path of the sketch. * @param contextParams Map of parameters to be included in the zip file. * @param zipFileName Name of the zip file. * @return Created zip archive. * @throws DeviceManagementException * @throws IOException */ public static ZipArchive getSketchArchive(String archivesPath, String templateSketchPath, Map contextParams , String zipFileName) throws DeviceManagementException, IOException { String sketchPath = CarbonUtils.getCarbonHome() + File.separator + templateSketchPath; FileUtils.deleteDirectory(new File(archivesPath)); //clear directory FileUtils.deleteDirectory(new File(archivesPath + ".zip")); //clear zip if (!new File(archivesPath).mkdirs()) { //new dir String message = "Could not create directory at path: " + archivesPath; throw new DeviceManagementException(message); } zipFileName = zipFileName + ".zip"; try { Map<String, List<String>> properties = getProperties(sketchPath + File.separator + "sketch" + ".properties"); List<String> templateFiles = properties.get("templates"); for (String templateFile : templateFiles) { parseTemplate(templateSketchPath + File.separator + templateFile, archivesPath + File.separator + templateFile, contextParams); } templateFiles.add("sketch.properties"); // ommit copying the props file copyFolder(new File(sketchPath), new File(archivesPath), templateFiles); createZipArchive(archivesPath); FileUtils.deleteDirectory(new File(archivesPath)); File zip = new File(archivesPath + ".zip"); return new ZipArchive(zipFileName, zip); } catch (IOException ex) { throw new DeviceManagementException( "Error occurred when trying to read property " + "file sketch.properties", ex); } }
Example 4
Source File: RemoteUserManagerClient.java From carbon-apimgt with Apache License 2.0 | 5 votes |
public RemoteUserManagerClient(String cookie) throws APIManagementException { APIManagerConfiguration config = ServiceReferenceHolder.getInstance() .getAPIManagerConfigurationService() .getAPIManagerConfiguration(); String serviceURL = config.getFirstProperty(APIConstants.AUTH_MANAGER_URL); String username = config.getFirstProperty(APIConstants.AUTH_MANAGER_USERNAME); String password = config.getFirstProperty(APIConstants.AUTH_MANAGER_PASSWORD); if (serviceURL == null || username == null || password == null) { throw new APIManagementException("Required connection details for authentication"); } try { String clientRepo = CarbonUtils.getCarbonHome() + File.separator + "repository" + File.separator + "deployment" + File.separator + "client"; String clientAxisConf = CarbonUtils.getCarbonHome() + File.separator + "repository" + File.separator + "conf" + File.separator + "axis2"+ File.separator +"axis2_client.xml"; ConfigurationContext configContext = ConfigurationContextFactory. createConfigurationContextFromFileSystem(clientRepo,clientAxisConf); userStoreManagerStub = new RemoteUserStoreManagerServiceStub(configContext, serviceURL + "RemoteUserStoreManagerService"); ServiceClient svcClient = userStoreManagerStub._getServiceClient(); CarbonUtils.setBasicAccessSecurityHeaders(username, password, svcClient); Options options = svcClient.getOptions(); options.setTimeOutInMilliSeconds(TIMEOUT_IN_MILLIS); options.setProperty(HTTPConstants.SO_TIMEOUT, TIMEOUT_IN_MILLIS); options.setProperty(HTTPConstants.CONNECTION_TIMEOUT, TIMEOUT_IN_MILLIS); options.setCallTransportCleanup(true); options.setManageSession(true); options.setProperty(HTTPConstants.COOKIE_STRING, cookie); } catch (AxisFault axisFault) { throw new APIManagementException( "Error while initializing the remote user store manager stub", axisFault); } }
Example 5
Source File: EntitlementServiceClient.java From carbon-apimgt with Apache License 2.0 | 5 votes |
/** * This method will initiate entitlement service client which calls PDP * * @throws Exception whenever if failed to initiate client properly. */ public EntitlementServiceClient() throws Exception { ConfigurationContext configContext; try { String repositoryBasePath = CarbonUtils.getCarbonHome() + File.separator + "repository"; String clientRepo = repositoryBasePath + File.separator + "deployment" + File.separator + "client"; String clientAxisConf = repositoryBasePath + File.separator + "conf" + File.separator + "axis2" + File.separator + "axis2_client.xml"; configContext = ConfigurationContextFactory.createConfigurationContextFromFileSystem(clientRepo, clientAxisConf); String serviceEndPoint = EntitlementClientUtils.getServerUrl() + "EntitlementService"; entitlementServiceStub = new EntitlementServiceStub(configContext, serviceEndPoint); ServiceClient client = entitlementServiceStub._getServiceClient(); Options option = client.getOptions(); option.setProperty(HTTPConstants.COOKIE_STRING, null); HttpTransportProperties.Authenticator auth = new HttpTransportProperties.Authenticator(); auth.setUsername(EntitlementClientUtils.getServerUsername()); auth.setPassword(EntitlementClientUtils.getServerPassword()); auth.setPreemptiveAuthentication(true); option.setProperty(HTTPConstants.AUTHENTICATE, auth); option.setManageSession(true); } catch (Exception e) { logger.error("Error while initiating entitlement service client ", e); } }
Example 6
Source File: UsagePublisherUtils.java From carbon-apimgt with Apache License 2.0 | 5 votes |
public static String getUploadedFileDirPath(String tenantDomain, String tempDirName) { //Temporary directory is used for keeping the uploaded files // i.e [APIUsageFileLocation]/api-usage-data/tenantDomain/tvtzC String storageLocation = System.getProperty("APIUsageFileLocation"); return ((storageLocation != null && !storageLocation.isEmpty()) ? storageLocation : CarbonUtils.getCarbonHome()) + File.separator + MicroGatewayAPIUsageConstants.API_USAGE_OUTPUT_DIRECTORY + File.separator + tenantDomain + File.separator + tempDirName; }
Example 7
Source File: APIUsageFileCleanupTask.java From carbon-apimgt with Apache License 2.0 | 5 votes |
@Override public void execute() { String fileRetentionDays = properties.get("fileRetentionDays"); if (fileRetentionDays != null && !fileRetentionDays.isEmpty()) { Date lastKeptDate = getLastKeptDate(Integer.parseInt(fileRetentionDays)); log.info("API Usage data files will be cleaned up to : " + dateFormat.format(lastKeptDate)); //[CARBON_HOME]/api-usage-data/ String usageFileDirectoryPath = CarbonUtils.getCarbonHome() + File.separator + MicroGatewayAPIUsageConstants.API_USAGE_OUTPUT_DIRECTORY; File usageFileDirectory = new File(usageFileDirectoryPath); if (usageFileDirectory.exists()) { File[] listOfFiles = usageFileDirectory.listFiles(); if (listOfFiles != null) { for (File file : listOfFiles) { if (file.getName().endsWith(MicroGatewayAPIUsageConstants.UPLOADED_FILE_SUFFIX) && (new Date(file.lastModified()).before(lastKeptDate))) { boolean deleted = file.delete(); if (!deleted) { log.warn("File : " + file.getName() + " which is older than the retention days" + "[" + fileRetentionDays + " days] could not be deleted by the cleanup task."); } } } } } } else { if (log.isDebugEnabled()) { log.debug("Usage data File cleanup is not enabled."); } } }
Example 8
Source File: APIManagerComponent.java From carbon-apimgt with Apache License 2.0 | 5 votes |
private void addTierPolicies() throws APIManagementException { String apiTierFilePath = CarbonUtils.getCarbonHome() + File.separator + "repository" + File.separator + "resources" + File.separator + "default-tiers" + File.separator + APIConstants.DEFAULT_API_TIER_FILE_NAME; String appTierFilePath = CarbonUtils.getCarbonHome() + File.separator + "repository" + File.separator + "resources" + File.separator + "default-tiers" + File.separator + APIConstants.DEFAULT_APP_TIER_FILE_NAME; String resTierFilePath = CarbonUtils.getCarbonHome() + File.separator + "repository" + File.separator + "resources" + File.separator + "default-tiers" + File.separator + APIConstants.DEFAULT_RES_TIER_FILE_NAME; addTierPolicy(APIConstants.API_TIER_LOCATION, apiTierFilePath); addTierPolicy(APIConstants.APP_TIER_LOCATION, appTierFilePath); addTierPolicy(APIConstants.RES_TIER_LOCATION, resTierFilePath); }
Example 9
Source File: UserManagementServiceImpl.java From carbon-device-mgt with Apache License 2.0 | 5 votes |
private String getEnrollmentTemplateName(String deviceType) { String templateName = deviceType + "-enrollment-invitation"; File template = new File(CarbonUtils.getCarbonHome() + File.separator + "repository" + File.separator + "resources" + File.separator + "email-templates" + File.separator + templateName + ".vm"); if (template.exists()) { return templateName; } else { if (log.isDebugEnabled()) { log.debug("The template that is expected to use is not available. Therefore, using default template."); } } return DeviceManagementConstants.EmailAttributes.DEFAULT_ENROLLMENT_TEMPLATE; }
Example 10
Source File: RegistryConfiguratorTestCase.java From product-es with Apache License 2.0 | 5 votes |
private void copyMimeMappingFile() throws IOException { String fileName = "mime.mappings"; String targetPath = CarbonUtils.getCarbonHome() + File.separator + "repository" + File.separator + "conf" + File.separator + "etc"; String sourcePath = getTestArtifactLocation() + "artifacts" + File.separator + "GREG" + File.separator + "config" + File.separator + "mime.mappings"; FileManager.copyResourceToFileSystem(sourcePath, targetPath, fileName); }
Example 11
Source File: RegistryConfiguratorTestCase.java From product-es with Apache License 2.0 | 5 votes |
public static OMElement getAxis2XmlOmElement() throws FileNotFoundException, XMLStreamException { String axis2XmlPath = CarbonUtils.getCarbonHome() + File.separator + "repository" + File.separator + "conf" + File.separator + "axis2" + File.separator + "axis2_client.xml"; File axis2File = new File(axis2XmlPath); FileInputStream inputStream = new FileInputStream(axis2File); XMLStreamReader parser = XMLInputFactory.newInstance().createXMLStreamReader(inputStream); StAXOMBuilder builder = new StAXOMBuilder(parser); return builder.getDocumentElement(); }
Example 12
Source File: RegistryConfiguratorTestCase.java From product-es with Apache License 2.0 | 5 votes |
public static OMElement getAxis2XmlOmElement() throws FileNotFoundException, XMLStreamException { String axis2XmlPath = CarbonUtils.getCarbonHome() + File.separator + "repository" + File.separator + "conf" + File.separator + "axis2" + File.separator + "axis2_client.xml"; File axis2File = new File(axis2XmlPath); FileInputStream inputStream = new FileInputStream(axis2File); XMLStreamReader parser = XMLInputFactory.newInstance().createXMLStreamReader(inputStream); StAXOMBuilder builder = new StAXOMBuilder(parser); return builder.getDocumentElement(); }
Example 13
Source File: RegistryConfiguratorTestCase.java From product-es with Apache License 2.0 | 5 votes |
private void copyMimeMappingFile() throws IOException { String fileName = "mime.mappings"; String targetPath = CarbonUtils.getCarbonHome() + File.separator + "repository" + File.separator + "conf" + File.separator + "etc"; String sourcePath = getTestArtifactLocation() + "artifacts" + File.separator + "GREG" + File.separator + "config" + File.separator + "mime.mappings"; FileManager.copyResourceToFileSystem(sourcePath, targetPath, fileName); }
Example 14
Source File: RegistryConfiguratorTestCase.java From product-es with Apache License 2.0 | 5 votes |
public static OMElement getRegistryXmlOmElement() throws FileNotFoundException, XMLStreamException { String registryXmlPath = CarbonUtils.getCarbonHome() + File.separator + "repository" + File.separator + "conf" + File.separator + "registry.xml"; File registryFile = new File(registryXmlPath); FileInputStream inputStream = new FileInputStream(registryFile); XMLStreamReader parser = XMLInputFactory.newInstance().createXMLStreamReader(inputStream); StAXOMBuilder builder = new StAXOMBuilder(parser); return builder.getDocumentElement(); }
Example 15
Source File: ZipUtil.java From product-iots with Apache License 2.0 | 4 votes |
public ZipArchive createZipFile(String owner, String tenantDomain, String deviceType, String deviceId, String deviceName, String token, String refreshToken) throws DeviceManagementException { String sketchFolder = "repository" + File.separator + "resources" + File.separator + "sketches"; String archivesPath = CarbonUtils.getCarbonHome() + File.separator + sketchFolder + File.separator + "archives" + File.separator + deviceId; String templateSketchPath = sketchFolder + File.separator + deviceType; String iotServerIP; try { iotServerIP = Utils.getServerUrl(); String httpsServerPort = System.getProperty(HTTPS_PORT_PROPERTY); String httpServerPort = System.getProperty(HTTP_PORT_PROPERTY); String httpsServerEP = HTTPS_PROTOCOL_APPENDER + iotServerIP + ":" + httpsServerPort; String httpServerEP = HTTP_PROTOCOL_APPENDER + iotServerIP + ":" + httpServerPort; String apimEndpoint = httpsServerEP; String mqttEndpoint = MqttConfig.getInstance().getBrokerEndpoint(); if (mqttEndpoint.contains(LOCALHOST)) { mqttEndpoint = mqttEndpoint.replace(LOCALHOST, iotServerIP); } Map<String, String> contextParams = new HashMap<>(); contextParams.put("SERVER_NAME", APIUtil.getTenantDomainOftheUser()); contextParams.put("DEVICE_OWNER", owner); contextParams.put("DEVICE_ID", deviceId); contextParams.put("DEVICE_NAME", deviceName); contextParams.put("HTTPS_EP", httpsServerEP); contextParams.put("HTTP_EP", httpServerEP); contextParams.put("APIM_EP", apimEndpoint); contextParams.put("MQTT_EP", mqttEndpoint); contextParams.put("DEVICE_TOKEN", token); contextParams.put("DEVICE_REFRESH_TOKEN", refreshToken); ZipArchive zipFile; zipFile = Utils.getSketchArchive(archivesPath, templateSketchPath, contextParams, deviceName); return zipFile; } catch (IOException e) { throw new DeviceManagementException("Zip File Creation Failed", e); } }
Example 16
Source File: RegistryConfiguratorTestCase.java From product-es with Apache License 2.0 | 4 votes |
private String getSsoIdpConfigXMLPath() { return CarbonUtils.getCarbonHome() + File.separator + "repository" + File.separator + "conf" + File.separator + "identity" + File.separator + "sso-idp-config.xml"; }
Example 17
Source File: RegistryConfiguratorTestCase.java From product-es with Apache License 2.0 | 4 votes |
private String getRegistryXMLPath() { return CarbonUtils.getCarbonHome() + File.separator + "repository" + File.separator + "conf" + File.separator + "registry.xml"; }
Example 18
Source File: Configurator.java From carbon-apimgt with Apache License 2.0 | 4 votes |
/** * Main method to handle Micro Gateway Configuration * * @param args String[] */ public static void main(String[] args) { carbonHome = CarbonUtils.getCarbonHome(); if (carbonHome == null || carbonHome.isEmpty()) { log.error("Carbon Home has not been set. Startup will be cancelled."); Runtime.getRuntime().exit(1); } if (args.length < 3 || carbonHome == null || carbonHome.isEmpty()) { log.error("Required arguments are not provided. Startup will be cancelled.\n" + "Required:\n" + "\t(1) Email\n" + "\t(2) Password\n" + "\t(3) Organization Key\n"); Runtime.getRuntime().exit(1); } carbonConfigDirPath = CarbonUtils.getCarbonConfigDirPath(); //Read Gateway properties String gatewayConfigPath = carbonConfigDirPath + File.separator + OnPremiseGatewayConstants.CONFIG_FILE_TOML_NAME; try { ConfigDTO gatewayConfigs = getGatewayConfigs(gatewayConfigPath, args); String configToolPropertyFilePath = carbonConfigDirPath + File.separator + ConfigConstants.CONFIG_TOOL_CONFIG_FILE_NAME; //Configure api-manager.xml Properties configToolProperties = readPropertiesFromFile(configToolPropertyFilePath); setAPIMConfigurations(configToolProperties, carbonHome, gatewayConfigs); //Configure registry.xml RegistryXmlConfigurator registryXmlConfigurator = new RegistryXmlConfigurator(); registryXmlConfigurator.configure(carbonConfigDirPath, gatewayConfigs); //Configure log4j.properties Log4JConfigurator log4JConfigurator = new Log4JConfigurator(); log4JConfigurator.configure(carbonConfigDirPath); writeConfiguredLock(carbonHome); initializeOnPremGateway(gatewayConfigs, carbonConfigDirPath, args); } catch (OnPremiseGatewayException | IOException e) { log.error("Error while initializing gateway.", e); Runtime.getRuntime().exit(1); } }
Example 19
Source File: RegistryConfiguratorTestCase.java From product-es with Apache License 2.0 | 4 votes |
private String getSsoIdpConfigXMLPath() { return CarbonUtils.getCarbonHome() + File.separator + "repository" + File.separator + "conf" + File.separator + "identity" + File.separator + "sso-idp-config.xml"; }
Example 20
Source File: SecurityWithServiceDescriptorTest.java From product-ei with Apache License 2.0 | 4 votes |
@Test(groups = { "wso2.bps", "wso2.bps.security" }, description = "BPEL security test scenario - secure BPEL process with service.xml file") public void securityWithServiceDescriptorTest() throws Exception { requestSender.waitForProcessDeployment(backEndUrl + "SWSDPService"); // FrameworkConstants.start(); String securityPolicyPath = FrameworkPathUtil.getSystemResourceLocation() + BPSTestConstants.DIR_ARTIFACTS + File.separator + BPSTestConstants.DIR_POLICY + File.separator + "utpolicy.xml"; String endpointHttpS = "https://localhost:9645/services/SWSDPService"; String trustStore = CarbonUtils.getCarbonHome() + File.separator + "repository" + File.separator + "resources" + File.separator + "security" + File.separator + "wso2carbon.jks"; String clientKey = trustStore; OMElement result; System.setProperty("javax.net.ssl.trustStore", trustStore); System.setProperty("javax.net.ssl.trustStorePassword", "wso2carbon"); if (log.isDebugEnabled()) { log.debug("Carbon Home: " + CarbonUtils.getCarbonHome()); } ConfigurationContext ctx = ConfigurationContextFactory .createConfigurationContextFromFileSystem( CarbonUtils.getCarbonHome() + File.separator + "repository" + File.separator + "deployment" + File.separator + "client", null); ServiceClient sc = new ServiceClient(ctx, null); sc.engageModule("addressing"); sc.engageModule("rampart"); Options opts = new Options(); opts.setTo(new EndpointReference(endpointHttpS)); log.info(endpointHttpS); opts.setAction("urn:swsdp"); log.info("SecurityPolicyPath " + securityPolicyPath); opts.setProperty(RampartMessageData.KEY_RAMPART_POLICY, loadPolicy(securityPolicyPath, clientKey, "admin")); sc.setOptions(opts); result = sc.sendReceive( AXIOMUtil.stringToOM("<p:swsdp xmlns:p=\"http://wso2.org/bpel/sample.wsdl\">\n" + " <TestPart>ww</TestPart>\n" + " </p:swsdp>")); log.info(result.getFirstElement().getText()); Assert.assertFalse("Incorrect Test Result: " + result.toString(), !result.toString().contains("ww World")); }