Search in sources :

Example 61 with FessConfig

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

the class PermissionHelper method getFtpRoleTypeList.

public List<String> getFtpRoleTypeList(final ResponseData responseData) {
    final List<String> roleTypeList = new ArrayList<>();
    final FessConfig fessConfig = ComponentUtil.getFessConfig();
    if (fessConfig.isFtpRoleFromFile() && responseData.getUrl().startsWith("ftp:")) {
        final String owner = (String) responseData.getMetaDataMap().get(FtpClient.FTP_FILE_USER);
        if (owner != null) {
            roleTypeList.add(systemHelper.getSearchRoleByUser(owner));
        }
        final String group = (String) responseData.getMetaDataMap().get(FtpClient.FTP_FILE_GROUP);
        if (group != null) {
            roleTypeList.add(systemHelper.getSearchRoleByGroup(group));
        }
        if (logger.isDebugEnabled()) {
            logger.debug("ftpUrl:{} roleType:{}", responseData.getUrl(), roleTypeList);
        }
    }
    return roleTypeList;
}
Also used : ArrayList(java.util.ArrayList) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig)

Example 62 with FessConfig

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

the class PermissionHelper method getFileRoleTypeList.

public List<String> getFileRoleTypeList(final ResponseData responseData) {
    final List<String> roleTypeList = new ArrayList<>();
    final FessConfig fessConfig = ComponentUtil.getFessConfig();
    if (fessConfig.isFileRoleFromFile() && responseData.getUrl().startsWith("file:")) {
        final String owner = (String) responseData.getMetaDataMap().get(FileSystemClient.FS_FILE_USER);
        if (owner != null) {
            roleTypeList.add(systemHelper.getSearchRoleByUser(owner));
        }
        final String[] groups = (String[]) responseData.getMetaDataMap().get(FileSystemClient.FS_FILE_GROUPS);
        roleTypeList.addAll(stream(groups).get(stream -> stream.map(systemHelper::getSearchRoleByGroup).collect(Collectors.toList())));
        if (logger.isDebugEnabled()) {
            logger.debug("fileUrl:{} roleType:{}", responseData.getUrl(), roleTypeList);
        }
    }
    return roleTypeList;
}
Also used : StreamUtil.stream(org.codelibs.core.stream.StreamUtil.stream) Resource(javax.annotation.Resource) StringUtil(org.codelibs.core.lang.StringUtil) FileSystemClient(org.codelibs.fess.crawler.client.fs.FileSystemClient) FtpClient(org.codelibs.fess.crawler.client.ftp.FtpClient) SID(jcifs.SID) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) List(java.util.List) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) Logger(org.apache.logging.log4j.Logger) ComponentUtil(org.codelibs.fess.util.ComponentUtil) Locale(java.util.Locale) Map(java.util.Map) SmbClient(org.codelibs.fess.crawler.client.smb.SmbClient) LogManager(org.apache.logging.log4j.LogManager) ResponseData(org.codelibs.fess.crawler.entity.ResponseData) ArrayList(java.util.ArrayList) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig)

Example 63 with FessConfig

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

the class CurlHelper method init.

@PostConstruct
public void init() {
    final FessConfig fessConfig = ComponentUtil.getFessConfig();
    final String authorities = fessConfig.getElasticsearchHttpSslCertificateAuthorities();
    if (StringUtil.isNotBlank(authorities)) {
        if (logger.isDebugEnabled()) {
            logger.debug("Loading certificate_authorities: {}", authorities);
        }
        try (final InputStream in = new FileInputStream(authorities)) {
            final Certificate certificate = CertificateFactory.getInstance("X.509").generateCertificate(in);
            final KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
            keyStore.load(null, null);
            keyStore.setCertificateEntry("server", certificate);
            final TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
            trustManagerFactory.init(keyStore);
            final SSLContext sslContext = SSLContext.getInstance("TLS");
            sslContext.init(null, trustManagerFactory.getTrustManagers(), null);
            sslSocketFactory = sslContext.getSocketFactory();
        } catch (final Exception e) {
            logger.warn("Failed to load {}", authorities, e);
        }
    }
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) TrustManagerFactory(javax.net.ssl.TrustManagerFactory) SSLContext(javax.net.ssl.SSLContext) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) KeyStore(java.security.KeyStore) FileInputStream(java.io.FileInputStream) Certificate(java.security.cert.Certificate) PostConstruct(javax.annotation.PostConstruct)

Example 64 with FessConfig

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

the class KeyMatchHelper method getBoostedDocumentList.

public List<Map<String, Object>> getBoostedDocumentList(final KeyMatch keyMatch) {
    final SearchEngineClient searchEngineClient = ComponentUtil.getSearchEngineClient();
    String virtualHost = keyMatch.getVirtualHost();
    if (StringUtil.isBlank(virtualHost)) {
        virtualHost = StringUtil.EMPTY;
    }
    final List<Tuple3<String, QueryBuilder, ScoreFunctionBuilder<?>>> boostList = getQueryMap(virtualHost).get(toLowerCase(keyMatch.getTerm()));
    if (boostList == null) {
        return Collections.emptyList();
    }
    for (final Tuple3<String, QueryBuilder, ScoreFunctionBuilder<?>> pair : boostList) {
        if (!keyMatch.getId().equals(pair.getValue1())) {
            continue;
        }
        final FessConfig fessConfig = ComponentUtil.getFessConfig();
        return searchEngineClient.getDocumentList(fessConfig.getIndexDocumentSearchIndex(), searchRequestBuilder -> {
            searchRequestBuilder.setPreference(Constants.SEARCH_PREFERENCE_LOCAL).setQuery(pair.getValue2()).setSize(keyMatch.getMaxSize());
            return true;
        });
    }
    return Collections.emptyList();
}
Also used : ScoreFunctionBuilder(org.opensearch.index.query.functionscore.ScoreFunctionBuilder) Tuple3(org.codelibs.core.misc.Tuple3) SearchEngineClient(org.codelibs.fess.es.client.SearchEngineClient) QueryBuilder(org.opensearch.index.query.QueryBuilder) BoolQueryBuilder(org.opensearch.index.query.BoolQueryBuilder) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig)

Example 65 with FessConfig

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

the class User method getPermissions.

@Override
public String[] getPermissions() {
    final FessConfig fessConfig = ComponentUtil.getFessConfig();
    final List<String> list = new ArrayList<>();
    list.add(fessConfig.getRoleSearchUserPrefix() + getName());
    stream(getRoles()).of(stream -> stream.forEach(s -> list.add(fessConfig.getRoleSearchRolePrefix() + decode(s))));
    stream(getGroups()).of(stream -> stream.forEach(s -> list.add(fessConfig.getRoleSearchGroupPrefix() + decode(s))));
    return list.toArray(new String[list.size()]);
}
Also used : Arrays(java.util.Arrays) Base64(java.util.Base64) List(java.util.List) Constants(org.codelibs.fess.Constants) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) StreamUtil.stream(org.codelibs.core.stream.StreamUtil.stream) BsUser(org.codelibs.fess.es.user.bsentity.BsUser) ComponentUtil(org.codelibs.fess.util.ComponentUtil) Map(java.util.Map) HashMap(java.util.HashMap) FessUser(org.codelibs.fess.entity.FessUser) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) 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