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);
}
});
}
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());
}
});
}
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();
}
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());
}
});
}
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;
}
Aggregations