Search in sources :

Example 41 with FessConfig

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

the class LdapManager method insert.

public void insert(final Role role) {
    final FessConfig fessConfig = ComponentUtil.getFessConfig();
    if (!fessConfig.isLdapAdminEnabled()) {
        return;
    }
    final Supplier<Hashtable<String, String>> adminEnv = () -> createAdminEnv();
    search(fessConfig.getLdapAdminRoleBaseDn(), fessConfig.getLdapAdminRoleFilter(role.getName()), null, adminEnv, result -> {
        if (!result.isEmpty()) {
            logger.info("{} exists in LDAP server.", role.getName());
        } else {
            final String entryDN = fessConfig.getLdapAdminRoleSecurityPrincipal(role.getName());
            final BasicAttributes entry = new BasicAttributes();
            addRoleAttributes(entry, role, fessConfig);
            final Attribute oc = fessConfig.getLdapAdminRoleObjectClassAttribute();
            entry.put(oc);
            insert(entryDN, entry, adminEnv);
        }
    });
}
Also used : BasicAttributes(javax.naming.directory.BasicAttributes) BasicAttribute(javax.naming.directory.BasicAttribute) Attribute(javax.naming.directory.Attribute) Hashtable(java.util.Hashtable) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig)

Example 42 with FessConfig

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

the class LdapManager method delete.

public void delete(final User user) {
    final FessConfig fessConfig = ComponentUtil.getFessConfig();
    if (!fessConfig.isLdapAdminEnabled(user.getName())) {
        return;
    }
    final Supplier<Hashtable<String, String>> adminEnv = () -> createAdminEnv();
    final String userDN = fessConfig.getLdapAdminUserSecurityPrincipal(user.getName());
    stream(user.getGroupNames()).of(stream -> stream.forEach(name -> {
        search(fessConfig.getLdapAdminGroupBaseDn(), fessConfig.getLdapAdminGroupFilter(name), null, adminEnv, subResult -> {
            if (!!subResult.isEmpty()) {
                final Group group = new Group();
                group.setName(name);
                insert(group);
            }
            final List<ModificationItem> modifyList = new ArrayList<>();
            modifyDeleteEntry(modifyList, "member", userDN);
            modify(fessConfig.getLdapAdminGroupSecurityPrincipal(name), modifyList, adminEnv);
        });
    }));
    stream(user.getRoleNames()).of(stream -> stream.forEach(name -> {
        search(fessConfig.getLdapAdminRoleBaseDn(), fessConfig.getLdapAdminRoleFilter(name), null, adminEnv, subResult -> {
            if (!!subResult.isEmpty()) {
                final Role role = new Role();
                role.setName(name);
                insert(role);
            }
            final List<ModificationItem> modifyList = new ArrayList<>();
            modifyDeleteEntry(modifyList, "member", userDN);
            modify(fessConfig.getLdapAdminRoleSecurityPrincipal(name), modifyList, adminEnv);
        });
    }));
    search(fessConfig.getLdapAdminUserBaseDn(), fessConfig.getLdapAdminUserFilter(user.getName()), null, adminEnv, result -> {
        if (!result.isEmpty()) {
            delete(userDN, adminEnv);
        } else {
            logger.info("{} does not exist in LDAP server.", user.getName());
        }
    });
}
Also used : ModificationItem(javax.naming.directory.ModificationItem) Constants(org.codelibs.fess.Constants) LoggerFactory(org.slf4j.LoggerFactory) NamingException(javax.naming.NamingException) User(org.codelibs.fess.es.user.exentity.User) Supplier(java.util.function.Supplier) SearchControls(javax.naming.directory.SearchControls) ArrayList(java.util.ArrayList) InitialDirContext(javax.naming.directory.InitialDirContext) BasicAttribute(javax.naming.directory.BasicAttribute) Attribute(javax.naming.directory.Attribute) Role(org.codelibs.fess.es.user.exentity.Role) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) Locale(java.util.Locale) BiConsumer(java.util.function.BiConsumer) FessUser(org.codelibs.fess.entity.FessUser) Context(javax.naming.Context) Hashtable(java.util.Hashtable) StreamUtil.stream(org.codelibs.core.stream.StreamUtil.stream) Logger(org.slf4j.Logger) OptionalUtil(org.codelibs.fess.util.OptionalUtil) OptionalEntity(org.dbflute.optional.OptionalEntity) LdapOperationException(org.codelibs.fess.exception.LdapOperationException) DirContext(javax.naming.directory.DirContext) StringUtil(org.codelibs.core.lang.StringUtil) BasicAttributes(javax.naming.directory.BasicAttributes) Collectors(java.util.stream.Collectors) Consumer(java.util.function.Consumer) Base64(java.util.Base64) List(java.util.List) ComponentUtil(org.codelibs.fess.util.ComponentUtil) DfTypeUtil(org.dbflute.util.DfTypeUtil) Attributes(javax.naming.directory.Attributes) SystemHelper(org.codelibs.fess.helper.SystemHelper) Collections(java.util.Collections) SearchResult(javax.naming.directory.SearchResult) Group(org.codelibs.fess.es.user.exentity.Group) Role(org.codelibs.fess.es.user.exentity.Role) Group(org.codelibs.fess.es.user.exentity.Group) Hashtable(java.util.Hashtable) ArrayList(java.util.ArrayList) List(java.util.List) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig)

Example 43 with FessConfig

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

the class PingEsJob method execute.

public String execute() {
    final FessEsClient fessEsClient = ComponentUtil.getFessEsClient();
    final FessConfig fessConfig = ComponentUtil.getFessConfig();
    final SystemHelper systemHelper = ComponentUtil.getSystemHelper();
    final StringBuilder resultBuf = new StringBuilder();
    final String notificationTo = fessConfig.getNotificationTo();
    final PingResponse ping = fessEsClient.ping();
    final int status = ping.getStatus();
    if (systemHelper.isChangedClusterState(status)) {
        if (StringUtil.isNotBlank(notificationTo)) {
            final Postbox postbox = ComponentUtil.getComponent(Postbox.class);
            try {
                EsStatusPostcard.droppedInto(postbox, postcard -> {
                    postcard.setFrom(fessConfig.getMailFromAddress(), fessConfig.getMailFromName());
                    postcard.addReplyTo(fessConfig.getMailReturnPath());
                    postcard.addTo(notificationTo);
                    postcard.setHostname(systemHelper.getHostname());
                    postcard.setClustername(ping.getClusterName());
                    postcard.setClusterstatus(ping.getClusterStatus());
                });
            } catch (final Exception e) {
                logger.warn("Failed to send a test mail.", e);
            }
        }
        resultBuf.append("Status of ").append(ping.getClusterName()).append(" is changed to ").append(ping.getClusterStatus()).append('.');
    } else {
        if (status == 0) {
            resultBuf.append(ping.getClusterName()).append(" is alive.");
        } else {
            resultBuf.append(ping.getClusterName()).append(" is not available.");
        }
    }
    return resultBuf.toString();
}
Also used : SystemHelper(org.codelibs.fess.helper.SystemHelper) FessEsClient(org.codelibs.fess.es.client.FessEsClient) PingResponse(org.codelibs.fess.entity.PingResponse) Postbox(org.lastaflute.core.mail.Postbox) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig)

Example 44 with FessConfig

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

the class LdapManager method delete.

public void delete(final Role role) {
    final FessConfig fessConfig = ComponentUtil.getFessConfig();
    if (!fessConfig.isLdapAdminEnabled()) {
        return;
    }
    final Supplier<Hashtable<String, String>> adminEnv = () -> createAdminEnv();
    search(fessConfig.getLdapAdminRoleBaseDn(), fessConfig.getLdapAdminRoleFilter(role.getName()), null, adminEnv, result -> {
        if (!result.isEmpty()) {
            final String entryDN = fessConfig.getLdapAdminRoleSecurityPrincipal(role.getName());
            delete(entryDN, adminEnv);
        } else {
            logger.info("{} does not exist in LDAP server.", role.getName());
        }
    });
}
Also used : Hashtable(java.util.Hashtable) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig)

Example 45 with FessConfig

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

the class ViewHelper method getSitePath.

public Object getSitePath(final Map<String, Object> docMap) {
    final FessConfig fessConfig = ComponentUtil.getFessConfig();
    final Object urlLink = docMap.get(fessConfig.getResponseFieldUrlLink());
    if (urlLink != null) {
        final String returnUrl;
        final String url = urlLink.toString();
        if (LOCAL_PATH_PATTERN.matcher(url).find() || SHARED_FOLDER_PATTERN.matcher(url).find()) {
            returnUrl = url.replaceFirst("^file:/+", "");
        } else if (url.startsWith("file:")) {
            returnUrl = url.replaceFirst("^file:/+", "/");
        } else {
            returnUrl = url.replaceFirst("^[a-zA-Z0-9]*:/+", "");
        }
        return StringUtils.abbreviate(returnUrl, sitePathLength);
    }
    return null;
}
Also used : FessConfig(org.codelibs.fess.mylasta.direction.FessConfig)

Aggregations

FessConfig (org.codelibs.fess.mylasta.direction.FessConfig)108 ArrayList (java.util.ArrayList)41 Map (java.util.Map)33 HashMap (java.util.HashMap)32 List (java.util.List)27 ComponentUtil (org.codelibs.fess.util.ComponentUtil)27 Logger (org.slf4j.Logger)26 LoggerFactory (org.slf4j.LoggerFactory)26 StringUtil (org.codelibs.core.lang.StringUtil)24 Constants (org.codelibs.fess.Constants)22 StreamUtil.stream (org.codelibs.core.stream.StreamUtil.stream)21 IOException (java.io.IOException)15 SystemHelper (org.codelibs.fess.helper.SystemHelper)15 PostConstruct (javax.annotation.PostConstruct)14 FessSystemException (org.codelibs.fess.exception.FessSystemException)14 File (java.io.File)11 Date (java.util.Date)11 QueryBuilder (org.elasticsearch.index.query.QueryBuilder)11 Hashtable (java.util.Hashtable)10 FessEsClient (org.codelibs.fess.es.client.FessEsClient)9