Java Code Examples for org.wso2.carbon.utils.CarbonUtils#getCarbonConfigDirPath()

The following examples show how to use org.wso2.carbon.utils.CarbonUtils#getCarbonConfigDirPath() . 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: CloudServiceConfigParser.java    From attic-stratos with Apache License 2.0 6 votes vote down vote up
public static CloudServicesDescConfig loadCloudServicesConfiguration() throws Exception {
    if (cloudServicesDescConfig != null) {
        return cloudServicesDescConfig;
    }

    synchronized (loadlock) {
        if (cloudServicesDescConfig == null) {
            try {
                String configFileName = CarbonUtils.getCarbonConfigDirPath() + File.separator +
                        StratosConstants.MULTITENANCY_CONFIG_FOLDER + File.separator + CONFIG_FILENAME;
                OMElement configElement = CommonUtil.buildOMElement(new FileInputStream(configFileName));
                cloudServicesDescConfig = new CloudServicesDescConfig(configElement);
            } catch (Exception e) {
                String msg = "Error in building the cloud service configuration.";
                log.error(msg, e);
                throw new Exception(msg, e);
            }
        }
    }
    return cloudServicesDescConfig;
}
 
Example 2
Source File: AutoscalerRuleEvaluator.java    From attic-stratos with Apache License 2.0 6 votes vote down vote up
private static KnowledgeBase readKnowledgeBase(String drlFileName) {
    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    String configDir = CarbonUtils.getCarbonConfigDirPath();
    String droolsDir = configDir + File.separator + StratosConstants.DROOLS_DIR_NAME;
    Resource resource = ResourceFactory.newFileResource(droolsDir + File.separator + drlFileName);
    kbuilder.add(resource, ResourceType.DRL);
    KnowledgeBuilderErrors errors = kbuilder.getErrors();
    if (errors.size() > 0) {
        for (KnowledgeBuilderError error : errors) {
            log.error(error.getMessage());
        }
        throw new IllegalArgumentException("Could not parse knowledge");
    }
    KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
    kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
    return kbase;
}
 
Example 3
Source File: ConfigManager.java    From carbon-apimgt with Apache License 2.0 6 votes vote down vote up
/**
 * Method to get initialize micro API gateway configuration
 */
private void init() throws OnPremiseGatewayException {
    if (log.isDebugEnabled()) {
        log.debug("Started reading micro gateway configurations");
    }
    String configPath = CarbonUtils.getCarbonConfigDirPath() + File.separator +
            OnPremiseGatewayConstants.CONFIG_FILE_TOML_NAME;
    try {
        Map<String, Object> tomlResult = TomlParser.parse(configPath);
        ObjectMapper mapper = new ObjectMapper();
        mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        configObject = mapper.convertValue(tomlResult, ConfigDTO.class);
    } catch (ConfigParserException ex) {
        String errorMessage = "Error occurred while reading the config file : "
                + OnPremiseGatewayConstants.CONFIG_FILE_TOML_NAME;
        throw new OnPremiseGatewayException(errorMessage, ex);
    }
}
 
Example 4
Source File: TaskServiceImpl.java    From carbon-commons with Apache License 2.0 6 votes vote down vote up
private TaskServiceXMLConfiguration loadTaskServiceXMLConfig() throws TaskException {
    String path = CarbonUtils.getCarbonConfigDirPath() + File.separator + "etc"
            + File.separator + "tasks-config.xml";
    File file = new File(path);
    if (!file.exists()) {
        return null;
    }
    Document doc = TaskUtils.convertToDocument(file);
    TaskUtils.secureResolveDocument(doc);
    JAXBContext ctx;
    try {
        ctx = JAXBContext.newInstance(TaskServiceXMLConfiguration.class);
        TaskServiceXMLConfiguration taskConfig = (TaskServiceXMLConfiguration) ctx
                .createUnmarshaller().unmarshal(doc);
        return taskConfig;
    } catch (JAXBException e) {
        throw new TaskException(e.getMessage(), Code.CONFIG_ERROR, e);
    }

}
 
Example 5
Source File: LoggingUpdaterUtil.java    From carbon-commons with Apache License 2.0 5 votes vote down vote up
public static FileTime readModifiedTime() throws LoggingUpdaterException {

        String carbonConfigDirPath = CarbonUtils.getCarbonConfigDirPath();
        File log4j2File = new File(carbonConfigDirPath + File.separator + "log4j2.properties");
        try {
            BasicFileAttributes log4j2FileAttributes
                    = Files.getFileAttributeView(log4j2File.toPath(), BasicFileAttributeView.class).readAttributes();
            return log4j2FileAttributes.lastModifiedTime();
        } catch (IOException e) {
            throw new LoggingUpdaterException("Error while reading log4j2.properties", e);
        }
    }
 
Example 6
Source File: CommonUtil.java    From attic-stratos with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the configurations from the stratos configuration file.
 *
 * @return stratos configurations
 */
public static StratosConfiguration loadStratosConfiguration() {
    // gets the configuration file name from the StratosConstants.
    String StratosConfigFileName = CarbonUtils.getCarbonConfigDirPath() + File.separator +
            StratosConstants.MULTITENANCY_CONFIG_FOLDER + File.separator +
            StratosConstants.STRATOS_CONF_FILE;
    return loadStratosConfiguration(StratosConfigFileName);
}
 
Example 7
Source File: CommonUtil.java    From carbon-commons with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the configurations from the stratos configuration file.
 *
 * @return stratos configurations
 */
public static StratosConfiguration loadStratosConfiguration() {
    // gets the configuration file name from the StratosConstants.
    String StratosConfigFileName = CarbonUtils.getCarbonConfigDirPath() + File.separator + 
            StratosConstants.MULTITENANCY_CONFIG_FOLDER + File.separator +
            StratosConstants.STRATOS_CONF_FILE;
    return loadStratosConfiguration(StratosConfigFileName);
}
 
Example 8
Source File: DiscoveryMgtUtils.java    From carbon-commons with Apache License 2.0 5 votes vote down vote up
/**
 * Get the client side security policy for the remote discovery proxy. This method first checks
 * whether a resource named DiscoveryConstants.DISCOVERY_CLIENT_POLICY is available at the
 * root of the configuration registry. If not it attempts to load the policy from a file named
 * DiscoveryConstants.DISCOVERY_CLIENT_POLICY which should reside in the configuration file
 * directory of Carbon.
 *
 * @param registry Configuration registry
 * @return a Policy instance or null
 * @throws RegistryException If the registry cannot be accessed
 * @throws XMLStreamException If the policy XML cannot be parsed
 */
public static Policy getClientSecurityPolicy(Registry registry) throws RegistryException, 
        XMLStreamException {
    //TODO: Improve this logic so that user can put the security policy anywhere in the registry

    InputStream in;
    Resource policyResource = null;
    if (registry.resourceExists(DiscoveryConstants.DISCOVERY_CLIENT_POLICY)) {
        policyResource = registry.get(DiscoveryConstants.DISCOVERY_CLIENT_POLICY);
        in = policyResource.getContentStream();
    } else {
        String file = CarbonUtils.getCarbonConfigDirPath() + File.separator +
            DiscoveryConstants.DISCOVERY_CLIENT_POLICY;
        try {
            in = new FileInputStream(file);
        } catch (FileNotFoundException ignored) {
            return null;
        }
    }

    Policy policy = null;
    if (in != null) {
        StAXOMBuilder builder = new StAXOMBuilder(in);
        policy = PolicyEngine.getPolicy(builder.getDocumentElement());
    }

    if (policyResource != null) {
        policyResource.discard();
    }
    return policy;
}
 
Example 9
Source File: SCIMCommonComponent.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
protected void activate(ComponentContext ctx) {
    try {
        String filePath = CarbonUtils.getCarbonConfigDirPath() + File.separator + "identity" + File.separator +
                          SCIMConfigConstants.PROVISIONING_CONFIG_NAME;

        SCIMConfigProcessor scimConfigProcessor = new SCIMConfigProcessor();
        SCIMConfig scimConfig = scimConfigProcessor.buildConfigFromFile(filePath);
        boolean isDumbMode  = scimConfig.isDumbMode();
        // reading user schema extension
        if (Boolean.parseBoolean(scimConfig.getAdditionalPropertyValue("user-schema-extension-enabled"))) {
            String schemaFilePath =
                    CarbonUtils.getCarbonConfigDirPath() + File.separator +
                    SCIMConfigConstants.SCIM_SCHEMA_EXTENSION_CONFIG;
            SCIMUserSchemaExtensionBuilder.getInstance().buildUserSchemaExtension(schemaFilePath);
        }

        //register UserOperationEventListener implementation
        SCIMUserOperationListener scimUserOperationListener = new SCIMUserOperationListener();
        ctx.getBundleContext().registerService(UserOperationEventListener.class.getName(),
                                               scimUserOperationListener, null);

        SCIMCommonUtils.init();

        if (logger.isDebugEnabled()) {
            logger.debug("SCIM Common component activated successfully.");
        }
    } catch (CharonException e) {
        logger.error("Error in reading information from identity tables at SCIMCommonComponentStartup.", e);
    }
}
 
Example 10
Source File: ServiceReferenceHolder.java    From carbon-apimgt with Apache License 2.0 4 votes vote down vote up
private String getFilePath() {
    return CarbonUtils.getCarbonConfigDirPath() + File.separator + "api-manager.xml";
}
 
Example 11
Source File: IdentityUtil.java    From carbon-identity-framework with Apache License 2.0 4 votes vote down vote up
public static String getIdentityConfigDirPath() {
    return CarbonUtils.getCarbonConfigDirPath() + File.separator + "identity";
}
 
Example 12
Source File: Configurator.java    From carbon-apimgt with Apache License 2.0 4 votes vote down vote up
/**
 * 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 13
Source File: PackageInfoHolder.java    From carbon-commons with Apache License 2.0 4 votes vote down vote up
private List<PackageInfo> deserializePackageDescriptionConfig() throws StratosException {
    String configFilePath = CarbonUtils.getCarbonConfigDirPath() + File.separator +
            StratosConstants.MULTITENANCY_CONFIG_FOLDER + File.separator +
            PACKAGE_DESCRIPTION_CONFIG;
    
    OMElement packageConfigs;
    try {
        packageConfigs = CommonUtil.buildOMElement(new FileInputStream(configFilePath));
    } catch (Exception e) {
        String msg = "Error in deserializing the packageConfigs file: " + configFilePath + ".";
        log.error(msg, e);
        throw new StratosException(msg, e);
    }

    @SuppressWarnings("unchecked")
    Iterator<OMElement> packageConfigsChildsIt = packageConfigs.getChildElements();
    while (packageConfigsChildsIt.hasNext()) {
        OMElement packageConfigEle = packageConfigsChildsIt.next();
        if (!new QName(PACKAGE_DESCRIPTION_CONFIG_NS, "package").equals(
                packageConfigEle.getQName())) {
            continue;
        }
        
        PackageInfo multitenancyPackage = new PackageInfo();
        String packageName = packageConfigEle.getAttributeValue(new QName("name"));
        String subscriptionCharge = getPackageConfigValue("subscriptionCharge", packageConfigEle);
        String usersLimit = getPackageConfigValue("users.limit", packageConfigEle);
        String usersCharge = getPackageConfigValue("users.charge", packageConfigEle);

        String resourceVolumeLimit =
                getPackageConfigValue("resourceVolume.limit", packageConfigEle);
        String resourceVolumeOveruseCharge =
                getPackageConfigValue("resourceVolume.overuseCharge", packageConfigEle);
        String bandwidthLimit = getPackageConfigValue("bandwidth.limit", packageConfigEle);
        String bandwidthOveruseCharge =
                getPackageConfigValue("bandwidth.overuseCharge", packageConfigEle);
        int usersLimitInt = -1;
        if (!usersLimit.equals("unlimited")) {
            usersLimitInt = Integer.parseInt(usersLimit);
        }
        int resourceVolumeLimitInt = -1;
        if (!resourceVolumeLimit.equals("unlimited")) {
            resourceVolumeLimitInt = Integer.parseInt(resourceVolumeLimit);
        }
        int bandwidthLimitInt = -1;
        if (!bandwidthLimit.equals("unlimited")) {
            bandwidthLimitInt = Integer.parseInt(bandwidthLimit);
        }

        multitenancyPackage.setName(packageName);
        //In the PackageInfo class subscriptionCharge, chargeperUser and bandwidthOverUsageCharge
        //are declared as Integers. I think it is better to change them to float. If somebody
        //enters a float value to the conf file it will cause an exception here
        multitenancyPackage.setSubscriptionCharge(Integer.parseInt(subscriptionCharge));
        multitenancyPackage.setUsersLimit(usersLimitInt);
   //   multitenancyPackage.setChargePerUser(Integer.parseInt(usersCharge));
        multitenancyPackage.setResourceVolumeLimit(resourceVolumeLimitInt);
        multitenancyPackage.setBandwidthLimit(bandwidthLimitInt);
      //  multitenancyPackage.setBandwidthOveruseCharge(Integer.parseInt(bandwidthOveruseCharge));

        multitenancyPackages.add(multitenancyPackage);
    }
    return multitenancyPackages;
}
 
Example 14
Source File: IdentityUtil.java    From carbon-identity with Apache License 2.0 4 votes vote down vote up
public static String getIdentityConfigDirPath() {
    return CarbonUtils.getCarbonConfigDirPath() + File.separator + "identity";
}
 
Example 15
Source File: RampartConfigUtil.java    From carbon-identity with Apache License 2.0 4 votes vote down vote up
public static String getCarbonSecurityConfigurationPath() {
    String carbonConfig = CarbonUtils.getCarbonConfigDirPath();

    return carbonConfig + File.separatorChar + "security";
}
 
Example 16
Source File: SecurityConfigAdmin.java    From carbon-identity with Apache License 2.0 4 votes vote down vote up
public void populateRampartConfig(RampartConfig rampartConfig, Properties props,
                                  KerberosConfigData kerberosConfigurations)
        throws SecurityConfigException {

    if (rampartConfig != null) {
        if (kerberosConfigurations != null) {

            Properties kerberosProperties = new Properties();
            kerberosProperties.setProperty(KerberosConfig.SERVICE_PRINCIPLE_NAME,
                    kerberosConfigurations.getServicePrincipleName());
            KerberosConfig kerberosConfig = new KerberosConfig();
            kerberosConfig.setProp(kerberosProperties);
            String carbonSecurityConfigurationPath = CarbonUtils.getCarbonConfigDirPath() + File.separatorChar +
                    IDENTITY_CONFIG_DIR;

            String krbFile = carbonSecurityConfigurationPath + File.separatorChar
                    + KerberosConfigData.KERBEROS_CONFIG_FILE_NAME;

            File krbFileObject = new File(krbFile);

            if (!krbFileObject.exists()) {
                throw new SecurityConfigException("Kerberos configuration file not found at " + krbFile);
            }

            log.info("Setting " + KerberosConfigData.KERBEROS_CONFIG_FILE_SYSTEM_PROPERTY +
                    " to kerberos configuration file " + krbFile);

            System.setProperty(KerberosConfigData.KERBEROS_CONFIG_FILE_SYSTEM_PROPERTY, krbFile);

            rampartConfig.setKerberosConfig(kerberosConfig);

        } else {
            if (!props.isEmpty()) {
                // Encryption crypto config
                {
                    CryptoConfig encrCryptoConfig = new CryptoConfig();
                    encrCryptoConfig.setProvider(ServerCrypto.class.getName());
                    encrCryptoConfig.setProp(props);
                    encrCryptoConfig.setCacheEnabled(true);
                    encrCryptoConfig.setCryptoKey(ServerCrypto.PROP_ID_PRIVATE_STORE);
                    rampartConfig.setEncrCryptoConfig(encrCryptoConfig);
                }
                {
                    CryptoConfig signatureCryptoConfig = new CryptoConfig();
                    signatureCryptoConfig.setProvider(ServerCrypto.class.getName());
                    signatureCryptoConfig.setProp(props);
                    signatureCryptoConfig.setCacheEnabled(true);
                    signatureCryptoConfig.setCryptoKey(ServerCrypto.PROP_ID_PRIVATE_STORE);
                    rampartConfig.setSigCryptoConfig(signatureCryptoConfig);
                }
            }

            rampartConfig.setEncryptionUser(WSHandlerConstants.USE_REQ_SIG_CERT);
            rampartConfig.setUser(props.getProperty(SecurityConstants.USER));

            // Get ttl and timeskew params from axis2 xml
            int ttl = RampartConfig.DEFAULT_TIMESTAMP_TTL;
            int timeSkew = RampartConfig.DEFAULT_TIMESTAMP_MAX_SKEW;

            rampartConfig.setTimestampTTL(Integer.toString(ttl));
            rampartConfig.setTimestampMaxSkew(Integer.toString(timeSkew));

            //this will check for TokenStoreClassName property under Security in carbon.xml
            //if it is not found, default token store class will be set
            String tokenStoreClassName = ServerConfiguration.getInstance().
                    getFirstProperty("Security.TokenStoreClassName");
            if (tokenStoreClassName == null) {
                rampartConfig.setTokenStoreClass(SecurityTokenStore.class.getName());
            } else {
                rampartConfig.setTokenStoreClass(tokenStoreClassName);
            }
        }
    }
}
 
Example 17
Source File: PackageInfoHolder.java    From attic-stratos with Apache License 2.0 4 votes vote down vote up
private List<PackageInfo> deserializePackageDescriptionConfig() throws ApacheStratosException {
    String configFilePath = CarbonUtils.getCarbonConfigDirPath() + File.separator +
            StratosConstants.MULTITENANCY_CONFIG_FOLDER + File.separator +
            PACKAGE_DESCRIPTION_CONFIG;

    OMElement packageConfigs;
    try {
        packageConfigs = CommonUtil.buildOMElement(new FileInputStream(configFilePath));
    } catch (Exception e) {
        String msg = "Error in deserializing the packageConfigs file: " + configFilePath + ".";
        log.error(msg, e);
        throw new ApacheStratosException(msg, e);
    }

    @SuppressWarnings("unchecked")
    Iterator<OMElement> packageConfigsChildsIt = packageConfigs.getChildElements();
    while (packageConfigsChildsIt.hasNext()) {
        OMElement packageConfigEle = packageConfigsChildsIt.next();
        if (!new QName(PACKAGE_DESCRIPTION_CONFIG_NS, "package").equals(
                packageConfigEle.getQName())) {
            continue;
        }

        PackageInfo multitenancyPackage = new PackageInfo();
        String packageName = packageConfigEle.getAttributeValue(new QName("name"));
        String subscriptionCharge = getPackageConfigValue("subscriptionCharge", packageConfigEle);
        String usersLimit = getPackageConfigValue("users.limit", packageConfigEle);
        String usersCharge = getPackageConfigValue("users.charge", packageConfigEle);

        String resourceVolumeLimit =
                getPackageConfigValue("resourceVolume.limit", packageConfigEle);
        String resourceVolumeOveruseCharge =
                getPackageConfigValue("resourceVolume.overuseCharge", packageConfigEle);
        String bandwidthLimit = getPackageConfigValue("bandwidth.limit", packageConfigEle);
        String bandwidthOveruseCharge =
                getPackageConfigValue("bandwidth.overuseCharge", packageConfigEle);
        int usersLimitInt = -1;
        if (!usersLimit.equals("unlimited")) {
            usersLimitInt = Integer.parseInt(usersLimit);
        }
        int resourceVolumeLimitInt = -1;
        if (!resourceVolumeLimit.equals("unlimited")) {
            resourceVolumeLimitInt = Integer.parseInt(resourceVolumeLimit);
        }
        int bandwidthLimitInt = -1;
        if (!bandwidthLimit.equals("unlimited")) {
            bandwidthLimitInt = Integer.parseInt(bandwidthLimit);
        }

        multitenancyPackage.setName(packageName);
        //In the PackageInfo class subscriptionCharge, chargeperUser and bandwidthOverUsageCharge
        //are declared as Integers. I think it is better to change them to float. If somebody
        //enters a float value to the conf file it will cause an exception here
        multitenancyPackage.setSubscriptionCharge(Integer.parseInt(subscriptionCharge));
        multitenancyPackage.setUsersLimit(usersLimitInt);
        //   multitenancyPackage.setChargePerUser(Integer.parseInt(usersCharge));
        multitenancyPackage.setResourceVolumeLimit(resourceVolumeLimitInt);
        multitenancyPackage.setBandwidthLimit(bandwidthLimitInt);
        //  multitenancyPackage.setBandwidthOveruseCharge(Integer.parseInt(bandwidthOveruseCharge));

        multitenancyPackages.add(multitenancyPackage);
    }
    return multitenancyPackages;
}
 
Example 18
Source File: BPMNAnalyticsCoreServer.java    From product-ei with Apache License 2.0 4 votes vote down vote up
/**
 * @return BPS Analytics configuration path.
 */
private String getBPSAnalyticsConfigurationFilePath() {
    return CarbonUtils.getCarbonConfigDirPath() + File.separator +
           BPMNAnalyticsCoreConstants.BPS_ANALYTICS_CONFIGURATION_FILE_NAME;
}
 
Example 19
Source File: CommonUtil.java    From attic-stratos with Apache License 2.0 3 votes vote down vote up
/**
 * Loading the EULA.
 * ultimately we shall be loading the eula from the web page itself.
 * But loading from file should be there to customize the EULA based on the private deployments,
 * etc.
 *
 * @return eula
 */
public static String loadTermsOfUsage() {
    // currently loads from the file; gets the eula file name from the StratosConstants.
    String StratosEULAFileName = CarbonUtils.getCarbonConfigDirPath() + File.separator +
            StratosConstants.MULTITENANCY_CONFIG_FOLDER + File.separator +
            StratosConstants.STRATOS_EULA;
    return loadTermsOfUsage(StratosEULAFileName);
}
 
Example 20
Source File: APIHandlerServiceComponent.java    From carbon-apimgt with Apache License 2.0 2 votes vote down vote up
protected String getFilePath() {

        return CarbonUtils.getCarbonConfigDirPath() + File.separator + "api-manager.xml";
    }