use of org.codelibs.fess.mylasta.direction.FessConfig in project fess by codelibs.
the class UserInfoHelper method getUserCodeFromRequest.
protected String getUserCodeFromRequest(final HttpServletRequest request) {
final FessConfig fessConfig = ComponentUtil.getFessConfig();
final String userCode = request.getParameter(fessConfig.getUserCodeRequestParameter());
if (StringUtil.isBlank(userCode)) {
return null;
}
final int length = userCode.length();
if (fessConfig.getUserCodeMinLengthAsInteger().intValue() > length || fessConfig.getUserCodeMaxLengthAsInteger().intValue() < length) {
return null;
}
if (fessConfig.isValidUserCode(userCode)) {
request.setAttribute(Constants.USER_CODE, userCode);
return userCode;
}
return null;
}
use of org.codelibs.fess.mylasta.direction.FessConfig in project fess by codelibs.
the class UserInfoHelper method storeQueryId.
public void storeQueryId(final String queryId, final List<Map<String, Object>> documentItems) {
final HttpSession session = LaRequestUtil.getRequest().getSession(false);
if (session != null) {
final FessConfig fessConfig = ComponentUtil.getFessConfig();
final List<String> docIdList = new ArrayList<>();
for (final Map<String, Object> map : documentItems) {
final Object docId = map.get(fessConfig.getIndexFieldDocId());
if (docId != null && docId.toString().length() > 0) {
docIdList.add(docId.toString());
}
}
if (!docIdList.isEmpty()) {
final Map<String, String[]> resultDocIdsCache = getResultDocIdsCache(session);
resultDocIdsCache.put(queryId, docIdList.toArray(new String[docIdList.size()]));
}
}
}
use of org.codelibs.fess.mylasta.direction.FessConfig in project fess by codelibs.
the class LdapManager method insert.
public void insert(final Group group) {
final FessConfig fessConfig = ComponentUtil.getFessConfig();
if (!fessConfig.isLdapAdminEnabled()) {
return;
}
final Supplier<Hashtable<String, String>> adminEnv = () -> createAdminEnv();
final String entryDN = fessConfig.getLdapAdminGroupSecurityPrincipal(group.getName());
search(fessConfig.getLdapAdminGroupBaseDn(), fessConfig.getLdapAdminGroupFilter(group.getName()), null, adminEnv, result -> {
if (!result.isEmpty()) {
logger.info("{} exists in LDAP server.", group.getName());
modifyGroupAttributes(group, adminEnv, entryDN, result, fessConfig);
} else {
final BasicAttributes entry = new BasicAttributes();
addGroupAttributes(entry, group, fessConfig);
final Attribute oc = fessConfig.getLdapAdminGroupObjectClassAttribute();
entry.put(oc);
insert(entryDN, entry, adminEnv);
}
});
}
use of org.codelibs.fess.mylasta.direction.FessConfig in project fess by codelibs.
the class LdapManager method insert.
public void insert(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());
// attributes
search(fessConfig.getLdapAdminUserBaseDn(), fessConfig.getLdapAdminUserFilter(user.getName()), null, adminEnv, result -> {
if (!result.isEmpty()) {
modifyUserAttributes(user, adminEnv, userDN, result, fessConfig);
} else {
final BasicAttributes entry = new BasicAttributes();
addUserAttributes(entry, user, fessConfig);
final Attribute oc = fessConfig.getLdapAdminUserObjectClassAttribute();
entry.put(oc);
insert(userDN, entry, adminEnv);
}
});
// groups and roles
search(fessConfig.getLdapAdminUserBaseDn(), fessConfig.getLdapAdminUserFilter(user.getName()), new String[] { fessConfig.getLdapMemberofAttribute() }, adminEnv, result -> {
if (!result.isEmpty()) {
final List<String> oldGroupList = new ArrayList<>();
final List<String> oldRoleList = new ArrayList<>();
final String lowerGroupDn = fessConfig.getLdapAdminGroupBaseDn().toLowerCase(Locale.ROOT);
final String lowerRoleDn = fessConfig.getLdapAdminRoleBaseDn().toLowerCase(Locale.ROOT);
processSearchRoles(result, (entryDn, name) -> {
final String lowerEntryDn = entryDn.toLowerCase(Locale.ROOT);
if (lowerEntryDn.indexOf(lowerGroupDn) != -1) {
oldGroupList.add(name);
} else if (lowerEntryDn.indexOf(lowerRoleDn) != -1) {
oldRoleList.add(name);
}
});
final List<String> newGroupList = stream(user.getGroupNames()).get(stream -> stream.collect(Collectors.toList()));
stream(user.getGroupNames()).of(stream -> stream.forEach(name -> {
if (oldGroupList.contains(name)) {
oldGroupList.remove(name);
newGroupList.remove(name);
}
}));
oldGroupList.stream().forEach(name -> {
search(fessConfig.getLdapAdminGroupBaseDn(), fessConfig.getLdapAdminGroupFilter(name), null, adminEnv, subResult -> {
if (!subResult.isEmpty()) {
final List<ModificationItem> modifyList = new ArrayList<>();
modifyDeleteEntry(modifyList, "member", userDN);
modify(fessConfig.getLdapAdminGroupSecurityPrincipal(name), modifyList, adminEnv);
}
});
});
newGroupList.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<>();
modifyAddEntry(modifyList, "member", userDN);
modify(fessConfig.getLdapAdminGroupSecurityPrincipal(name), modifyList, adminEnv);
});
});
final List<String> newRoleList = stream(user.getRoleNames()).get(stream -> stream.collect(Collectors.toList()));
stream(user.getRoleNames()).of(stream -> stream.forEach(name -> {
if (oldRoleList.contains(name)) {
oldRoleList.remove(name);
newRoleList.remove(name);
}
}));
oldRoleList.stream().forEach(name -> {
search(fessConfig.getLdapAdminRoleBaseDn(), fessConfig.getLdapAdminRoleFilter(name), null, adminEnv, subResult -> {
if (!subResult.isEmpty()) {
final List<ModificationItem> modifyList = new ArrayList<>();
modifyDeleteEntry(modifyList, "member", userDN);
modify(fessConfig.getLdapAdminRoleSecurityPrincipal(name), modifyList, adminEnv);
}
});
});
newRoleList.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<>();
modifyAddEntry(modifyList, "member", userDN);
modify(fessConfig.getLdapAdminRoleSecurityPrincipal(name), modifyList, adminEnv);
});
});
} else {
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<>();
modifyAddEntry(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<>();
modifyAddEntry(modifyList, "member", userDN);
modify(fessConfig.getLdapAdminRoleSecurityPrincipal(name), modifyList, adminEnv);
});
}));
}
});
}
use of org.codelibs.fess.mylasta.direction.FessConfig in project fess by codelibs.
the class LdapManager method delete.
public void delete(final Group group) {
final FessConfig fessConfig = ComponentUtil.getFessConfig();
if (!fessConfig.isLdapAdminEnabled()) {
return;
}
final Supplier<Hashtable<String, String>> adminEnv = () -> createAdminEnv();
search(fessConfig.getLdapAdminGroupBaseDn(), fessConfig.getLdapAdminGroupFilter(group.getName()), null, adminEnv, result -> {
if (!result.isEmpty()) {
final String entryDN = fessConfig.getLdapAdminGroupSecurityPrincipal(group.getName());
delete(entryDN, adminEnv);
} else {
logger.info("{} does not exist in LDAP server.", group.getName());
}
});
}
Aggregations