Search in sources :

Example 66 with FessConfig

use of org.codelibs.fess.mylasta.direction.FessConfig in project fess by codelibs.

the class SamlCredential method getDefaultRolesAsArray.

protected String[] getDefaultRolesAsArray() {
    final List<String> list = new ArrayList<>();
    final FessConfig fessConfig = ComponentUtil.getFessConfig();
    final String key = fessConfig.getSystemProperty("saml.attribute.role.name");
    if (StringUtil.isNotBlank(key)) {
        final List<String> nameList = attributes.get(key);
        if (nameList != null) {
            list.addAll(nameList);
        }
    }
    final String value = fessConfig.getSystemProperty("saml.default.roles");
    if (StringUtil.isNotBlank(value)) {
        split(value, ",").of(stream -> stream.forEach(list::add));
    }
    return list.stream().filter(StringUtil::isNotBlank).map(String::trim).toArray(n -> new String[n]);
}
Also used : ArrayList(java.util.ArrayList) StringUtil(org.codelibs.core.lang.StringUtil) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig)

Example 67 with FessConfig

use of org.codelibs.fess.mylasta.direction.FessConfig in project fess by codelibs.

the class SpnegoAuthenticator method getAuthenticator.

protected synchronized org.codelibs.spnego.SpnegoAuthenticator getAuthenticator() {
    final FessConfig fessConfig = ComponentUtil.getFessConfig();
    if (authenticator != null && fessConfig.getSystemPropertyAsBoolean(SPNEGO_INITIALIZED, false)) {
        return authenticator;
    }
    try {
        // set some System properties
        final SpnegoFilterConfig config = SpnegoFilterConfig.getInstance(new SpengoConfig());
        // pre-authenticate
        authenticator = new org.codelibs.spnego.SpnegoAuthenticator(config);
        fessConfig.setSystemPropertyAsBoolean(SPNEGO_INITIALIZED, true);
        fessConfig.storeSystemProperties();
        return authenticator;
    } catch (final Exception e) {
        throw new SsoLoginException("Failed to initialize SPNEGO.", e);
    }
}
Also used : SpnegoFilterConfig(org.codelibs.spnego.SpnegoFilterConfig) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) SsoLoginException(org.codelibs.fess.exception.SsoLoginException) SsoLoginException(org.codelibs.fess.exception.SsoLoginException)

Example 68 with FessConfig

use of org.codelibs.fess.mylasta.direction.FessConfig in project fess by codelibs.

the class ThumbnailManager method getImageFilename.

protected String getImageFilename(final Map<String, Object> docMap) {
    final FessConfig fessConfig = ComponentUtil.getFessConfig();
    final String docid = DocumentUtil.getValue(docMap, fessConfig.getIndexFieldDocId(), String.class);
    return getImageFilename(docid);
}
Also used : FessConfig(org.codelibs.fess.mylasta.direction.FessConfig)

Example 69 with FessConfig

use of org.codelibs.fess.mylasta.direction.FessConfig in project fess by codelibs.

the class SuggestJob method executeSuggestCreator.

protected void executeSuggestCreator() {
    final List<String> cmdList = new ArrayList<>();
    final String cpSeparator = SystemUtils.IS_OS_WINDOWS ? ";" : ":";
    final ServletContext servletContext = ComponentUtil.getComponent(ServletContext.class);
    final ProcessHelper processHelper = ComponentUtil.getProcessHelper();
    final FessConfig fessConfig = ComponentUtil.getFessConfig();
    cmdList.add(fessConfig.getJavaCommandPath());
    // -cp
    cmdList.add("-cp");
    final StringBuilder buf = new StringBuilder(100);
    ResourceUtil.getOverrideConfPath().ifPresent(p -> {
        buf.append(p);
        buf.append(cpSeparator);
    });
    final String confPath = System.getProperty(Constants.FESS_CONF_PATH);
    if (StringUtil.isNotBlank(confPath)) {
        buf.append(confPath);
        buf.append(cpSeparator);
    }
    // WEB-INF/env/suggest/resources
    buf.append("WEB-INF");
    buf.append(File.separator);
    buf.append("env");
    buf.append(File.separator);
    buf.append(getExecuteType());
    buf.append(File.separator);
    buf.append("resources");
    buf.append(cpSeparator);
    // WEB-INF/classes
    buf.append("WEB-INF");
    buf.append(File.separator);
    buf.append("classes");
    // target/classes
    final String userDir = System.getProperty("user.dir");
    final File targetDir = new File(userDir, "target");
    final File targetClassesDir = new File(targetDir, "classes");
    if (targetClassesDir.isDirectory()) {
        buf.append(cpSeparator);
        buf.append(targetClassesDir.getAbsolutePath());
    }
    // WEB-INF/lib
    appendJarFile(cpSeparator, buf, new File(servletContext.getRealPath("/WEB-INF/lib")), "WEB-INF" + File.separator + "lib" + File.separator);
    // WEB-INF/env/suggest/lib
    appendJarFile(cpSeparator, buf, new File(servletContext.getRealPath("/WEB-INF/env/" + getExecuteType() + "/lib")), "WEB-INF" + File.separator + "env" + File.separator + getExecuteType() + File.separator + "lib" + File.separator);
    // WEB-INF/plugin
    appendJarFile(cpSeparator, buf, new File(servletContext.getRealPath("/WEB-INF/plugin")), "WEB-INF" + File.separator + "plugin" + File.separator);
    final File targetLibDir = new File(targetDir, "fess" + File.separator + "WEB-INF" + File.separator + "lib");
    if (targetLibDir.isDirectory()) {
        appendJarFile(cpSeparator, buf, targetLibDir, targetLibDir.getAbsolutePath() + File.separator);
    }
    cmdList.add(buf.toString());
    if (useLocalFesen) {
        final String httpAddress = System.getProperty(Constants.FESS_ES_HTTP_ADDRESS);
        if (StringUtil.isNotBlank(httpAddress)) {
            cmdList.add("-D" + Constants.FESS_ES_HTTP_ADDRESS + "=" + httpAddress);
        }
    }
    final String systemLastaEnv = System.getProperty("lasta.env");
    if (StringUtil.isNotBlank(systemLastaEnv)) {
        if ("web".equals(systemLastaEnv)) {
            cmdList.add("-Dlasta.env=" + getExecuteType());
        } else {
            cmdList.add("-Dlasta.env=" + systemLastaEnv);
        }
    } else if (StringUtil.isNotBlank(lastaEnv)) {
        cmdList.add("-Dlasta.env=" + lastaEnv);
    } else {
        cmdList.add("-Dlasta.env=" + getExecuteType());
    }
    addFessConfigProperties(cmdList);
    addFessSystemProperties(cmdList);
    addSystemProperty(cmdList, Constants.FESS_CONF_PATH, null, null);
    cmdList.add("-Dfess." + getExecuteType() + ".process=true");
    if (logFilePath == null) {
        final String value = System.getProperty("fess.log.path");
        logFilePath = value != null ? value : new File(targetDir, "logs").getAbsolutePath();
    }
    cmdList.add("-Dfess.log.path=" + logFilePath);
    addSystemProperty(cmdList, "fess.log.name", "fess-" + getExecuteType(), "-" + getExecuteType());
    if (logLevel == null) {
        addSystemProperty(cmdList, "fess.log.level", null, null);
    } else {
        cmdList.add("-Dfess.log.level=" + logLevel);
    }
    stream(fessConfig.getJvmSuggestOptionsAsArray()).of(stream -> stream.filter(StringUtil::isNotBlank).forEach(value -> cmdList.add(value)));
    File ownTmpDir = null;
    final String tmpDir = System.getProperty("java.io.tmpdir");
    if (fessConfig.isUseOwnTmpDir() && StringUtil.isNotBlank(tmpDir)) {
        ownTmpDir = new File(tmpDir, "fessTmpDir_" + sessionId);
        if (ownTmpDir.mkdirs()) {
            cmdList.add("-Djava.io.tmpdir=" + ownTmpDir.getAbsolutePath());
        } else {
            ownTmpDir = null;
        }
    }
    if (!jvmOptions.isEmpty()) {
        jvmOptions.stream().filter(StringUtil::isNotBlank).forEach(cmdList::add);
    }
    cmdList.add(SuggestCreator.class.getCanonicalName());
    cmdList.add("--sessionId");
    cmdList.add(sessionId);
    final File propFile = ComponentUtil.getSystemHelper().createTempFile(getExecuteType() + "_", ".properties");
    try {
        cmdList.add("-p");
        cmdList.add(propFile.getAbsolutePath());
        createSystemProperties(cmdList, propFile);
        final File baseDir = new File(servletContext.getRealPath("/WEB-INF")).getParentFile();
        if (logger.isInfoEnabled()) {
            logger.info("SuggestCreator: \nDirectory={}\nOptions={}", baseDir, cmdList);
        }
        final JobProcess jobProcess = processHelper.startProcess(sessionId, cmdList, pb -> {
            pb.directory(baseDir);
            pb.redirectErrorStream(true);
        });
        final InputStreamThread it = jobProcess.getInputStreamThread();
        it.start();
        final Process currentProcess = jobProcess.getProcess();
        currentProcess.waitFor();
        it.join(5000);
        final int exitValue = currentProcess.exitValue();
        if (logger.isInfoEnabled()) {
            logger.info("SuggestCreator: Exit Code={} - Process Output:\n{}", exitValue, it.getOutput());
        }
        if (exitValue != 0) {
            final StringBuilder out = new StringBuilder();
            if (processTimeout) {
                out.append("Process is terminated due to ").append(timeout).append(" second exceeded.\n");
            }
            out.append("Exit Code: ").append(exitValue).append("\nOutput:\n").append(it.getOutput());
            throw new JobProcessingException(out.toString());
        }
        ComponentUtil.getPopularWordHelper().clearCache();
    } catch (final JobProcessingException e) {
        throw e;
    } catch (final Exception e) {
        throw new JobProcessingException("SuggestCreator Process terminated.", e);
    } finally {
        try {
            processHelper.destroyProcess(sessionId);
        } finally {
            if (propFile != null && !propFile.delete()) {
                logger.warn("Failed to delete {}.", propFile.getAbsolutePath());
            }
            deleteTempDir(ownTmpDir);
        }
    }
}
Also used : Constants(org.codelibs.fess.Constants) StreamUtil.stream(org.codelibs.core.stream.StreamUtil.stream) ProcessHelper(org.codelibs.fess.helper.ProcessHelper) SystemUtils(org.apache.commons.lang3.SystemUtils) InputStreamThread(org.codelibs.fess.util.InputStreamThread) StringUtil(org.codelibs.core.lang.StringUtil) SuggestCreator(org.codelibs.fess.exec.SuggestCreator) File(java.io.File) ArrayList(java.util.ArrayList) ResourceUtil(org.codelibs.fess.util.ResourceUtil) List(java.util.List) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) Logger(org.apache.logging.log4j.Logger) ComponentUtil(org.codelibs.fess.util.ComponentUtil) ServletContext(javax.servlet.ServletContext) RandomStringUtils(org.apache.commons.lang3.RandomStringUtils) JobProcessingException(org.codelibs.fess.exception.JobProcessingException) TimeoutTask(org.codelibs.core.timer.TimeoutTask) LogManager(org.apache.logging.log4j.LogManager) JobProcess(org.codelibs.fess.util.JobProcess) SuggestCreator(org.codelibs.fess.exec.SuggestCreator) ArrayList(java.util.ArrayList) JobProcess(org.codelibs.fess.util.JobProcess) ProcessHelper(org.codelibs.fess.helper.ProcessHelper) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) JobProcess(org.codelibs.fess.util.JobProcess) JobProcessingException(org.codelibs.fess.exception.JobProcessingException) JobProcessingException(org.codelibs.fess.exception.JobProcessingException) InputStreamThread(org.codelibs.fess.util.InputStreamThread) ServletContext(javax.servlet.ServletContext) StringUtil(org.codelibs.core.lang.StringUtil) File(java.io.File)

Example 70 with FessConfig

use of org.codelibs.fess.mylasta.direction.FessConfig in project fess by codelibs.

the class FessUserLocaleProcessProvider method findBusinessLocale.

@Override
public OptionalThing<Locale> findBusinessLocale(final ActionRuntime runtimeMeta, final RequestManager requestManager) {
    final FessConfig fessConfig = ComponentUtil.getFessConfig();
    final String name = fessConfig.getQueryBrowserLangParameterName();
    if (StringUtil.isNotBlank(name)) {
        try {
            return requestManager.getParameter(name).filter(StringUtil::isNotBlank).map(LocaleUtils::toLocale);
        } catch (final Exception e) {
            logger.debug("Failed to parse a value of {}.", name, e);
        }
    }
    return OptionalObject.empty();
}
Also used : LocaleUtils(org.apache.commons.lang3.LocaleUtils) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig)

Aggregations

FessConfig (org.codelibs.fess.mylasta.direction.FessConfig)176 ArrayList (java.util.ArrayList)60 Map (java.util.Map)54 HashMap (java.util.HashMap)48 StringUtil (org.codelibs.core.lang.StringUtil)42 ComponentUtil (org.codelibs.fess.util.ComponentUtil)42 List (java.util.List)37 Constants (org.codelibs.fess.Constants)36 LogManager (org.apache.logging.log4j.LogManager)30 Logger (org.apache.logging.log4j.Logger)30 StreamUtil.stream (org.codelibs.core.stream.StreamUtil.stream)28 PostConstruct (javax.annotation.PostConstruct)27 IOException (java.io.IOException)24 SystemHelper (org.codelibs.fess.helper.SystemHelper)19 File (java.io.File)18 Collectors (java.util.stream.Collectors)18 SearchEngineClient (org.codelibs.fess.es.client.SearchEngineClient)18 FessSystemException (org.codelibs.fess.exception.FessSystemException)17 Collections (java.util.Collections)15 DocumentUtil (org.codelibs.fess.util.DocumentUtil)15