Java Spring安全ldap回退

Java Spring安全ldap回退,java,spring,spring-security,Java,Spring,Spring Security,我已配置身份验证,以便inMemoryAuthentication和ldapAuthentication共存。我的问题是,当LDAP服务器不可访问时,我得到了一个到目前为止还不错的ConnectException,它似乎根本没有检查inMemoryAuthentication配置。 我试图找到一种方法,以便在无法访问LDAP服务器时配置回退 以下是我的配置: @Override protected void configure(AuthenticationManagerBuilder auth)

我已配置身份验证,以便inMemoryAuthentication和ldapAuthentication共存。我的问题是,当LDAP服务器不可访问时,我得到了一个到目前为止还不错的ConnectException,它似乎根本没有检查inMemoryAuthentication配置。 我试图找到一种方法,以便在无法访问LDAP服务器时配置回退

以下是我的配置:

@Override
protected void configure(AuthenticationManagerBuilder auth) {
    try {
        LOG.debug("Adding default app user");
        auth.inMemoryAuthentication().withUser("user").password("pass").roles("USER");
    } catch (Exception ex) {
        LOG.error("Error adding default app user", ex);
        throw new AuthenticationServiceException(ex.getLocalizedMessage(), ex);
    }

    ...

    try {
        auth.ldapAuthentication().userDnPatterns(ldapDn).groupSearchBase(ldapGroup).contextSource().url(ldapUrl);
        LOG.debug("Configured");
    } catch (Exception ex) {
        LOG.error("Error during configuration of LDAP auth.", ex);
    }
}
这是在WebSecurityConfigureAdapter的子类中完成的

正如我所说的,当LDAP服务器可以访问时,一切都可以正常工作,但当LDAP服务器不在时,inMemoryAuthentication不起作用

欢迎任何想法


提前谢谢。

嗨,格雷克勒,你解决这个问题了吗?嗨,吕塞克。实际上,我所做的是在SpringSecurity中配置ldap服务器之前添加对其可用性的检查。我的意思是,我将第二个try catch包含在一个可用的ifldapAvailable中,并在这个方法中尝试连接。肮脏但做了我需要的。实现ldapAvailable方法很简单?@Stephane我做这件事已经有一段时间了,所以我不记得是怎么做的,但我记得它很简单。基本上,您可以从检查连接是否存在和是否处于活动状态开始,并最终通过一个简单的查询确认您得到LDAP响应