All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.alachisoft.ncache.security.SecurityConfiguration Maven / Gradle / Ivy

There is a newer version: 5.3.3
Show newest version
package com.alachisoft.ncache.security;


import Alachisoft.NCache.Common.AppUtil;

import java.io.File;

/**
 * Summary description for SecurityConfiguration.
 */
public class SecurityConfiguration {
    /**
     * Configuration file folder name
     */
    private static final String DIRNAME = "config";
    /**
     * Configuration file name
     */
    private static final String FILENAME = "security.conf";

    /**
     * Configuration file name (cache.conf)
     */
    private static final String FILENAMEAPI = "config.ncconf";

//	/** Path of the configuration file.
//	*/
//	private static String s_configFileName = "";
//	/** Path of the configuration folder.
//	*/
//	private static String s_configDir = "";

    public SecurityConfiguration() {
        //
        // TODO: Add constructor logic here
        //
    }

    public static String getConfigurationPath() {
        String filePath = GetFileLocalPath(FILENAME);
        if (filePath != null) {
            return filePath;
        }

        filePath = GetFileGlobalPath(FILENAME, DIRNAME);
        if (filePath != null) {
            return filePath;
        }

        throw new RuntimeException("Missing security config file ");
    }

    public static String getConfigurationPathAPI() {
        String filePath = GetFileLocalPath(FILENAMEAPI);
        if (filePath != null) {
            return filePath;
        }

        filePath = GetFileGlobalPath(FILENAMEAPI, DIRNAME);
        if (filePath != null) {
            return filePath;
        }

        throw new RuntimeException("Missing config file ");
    }

    /**
     * search for the specified file in the executing assembly's working folder
     * if the file is found, then a path string is returned back. otherwise it returns null.
     *
     * @param fileName
     * @return
     */
    private static String GetFileLocalPath(String fileName) {
        String path = System.getProperty("user.dir") + "\\" + fileName;
        if ((new java.io.File(path)).isFile()) {
            return path;
        }
        return null;
    }

    /**
     * search for the specified file in NCache install directory. if the file is found
     * then returns the path string from where the file can be loaded. otherwise it returns
     * null.
     *
     * @param fileName
     * @return
     */
    private static String GetFileGlobalPath(String fileName, String directoryName) {
        String ncacheInstallDirectory = AppUtil.getInstallDir();
        String directoryPath = "";
        String filePath = "";
        if (ncacheInstallDirectory == null) {
            return null;
        }

        File ncacheDir = new File(ncacheInstallDirectory);

        directoryPath = new File(ncacheDir, directoryName).getPath();

        if (!(new java.io.File(directoryPath)).isDirectory()) {
            return null;
        }
        File combineDirPath = new File(directoryPath);
        filePath = new File(combineDirPath, fileName).getPath();
        if (!(new java.io.File(filePath)).isFile()) {
            return null;
        }
        return filePath;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy