fix #742 check bind dn when updating config
This commit is contained in:
parent
2a19e3ad2c
commit
be6c61ba13
3 changed files with 28 additions and 0 deletions
|
@ -156,6 +156,7 @@ public class AdminGeneralAction extends FessAdminAction {
|
|||
fessConfig.setNotificationSearchTop(form.notificationSearchTop);
|
||||
|
||||
fessConfig.storeSystemProperties();
|
||||
ComponentUtil.getLdapManager().updateConfig();
|
||||
saveInfo(messages -> messages.addSuccessUpdateCrawlerParams(GLOBAL));
|
||||
return redirect(getClass());
|
||||
}
|
||||
|
|
|
@ -301,6 +301,7 @@ public class SystemHelper {
|
|||
ComponentUtil.getSuggestHelper().init();
|
||||
ComponentUtil.getPopularWordHelper().init();
|
||||
ComponentUtil.getJobManager().reboot();
|
||||
ComponentUtil.getLdapManager().updateConfig();
|
||||
}
|
||||
|
||||
public String generateAccessToken() {
|
||||
|
|
|
@ -61,6 +61,8 @@ public class LdapManager {
|
|||
|
||||
protected ThreadLocal<DirContextHolder> contextLocal = new ThreadLocal<>();
|
||||
|
||||
protected volatile boolean isBind = false;
|
||||
|
||||
protected Hashtable<String, String> createEnvironment(final String initialContextFactory, final String securityAuthentication,
|
||||
final String providerUrl, final String principal, final String credntials) {
|
||||
final Hashtable<String, String> env = new Hashtable<>();
|
||||
|
@ -99,6 +101,26 @@ public class LdapManager {
|
|||
fessConfig.getLdapAdminSecurityCredentials());
|
||||
}
|
||||
|
||||
public void updateConfig() {
|
||||
isBind = false;
|
||||
}
|
||||
|
||||
protected boolean validate() {
|
||||
if (!isBind) {
|
||||
final Hashtable<String, String> env = createAdminEnv();
|
||||
try (DirContextHolder holder = getDirContext(() -> env)) {
|
||||
final DirContext context = holder.get();
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Logged in as Bind DN.", context);
|
||||
}
|
||||
isBind = true;
|
||||
} catch (final Exception e) {
|
||||
logger.warn("LDAP configuration is wrong.", e);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public OptionalEntity<FessUser> login(final String username, final String password) {
|
||||
final FessConfig fessConfig = ComponentUtil.getFessConfig();
|
||||
|
||||
|
@ -106,6 +128,10 @@ public class LdapManager {
|
|||
return OptionalEntity.empty();
|
||||
}
|
||||
|
||||
if (!validate()) {
|
||||
return OptionalEntity.empty();
|
||||
}
|
||||
|
||||
final Hashtable<String, String> env = createSearchEnv(username, password);
|
||||
try (DirContextHolder holder = getDirContext(() -> env)) {
|
||||
final DirContext context = holder.get();
|
||||
|
|
Loading…
Add table
Reference in a new issue