简体   繁体   English

如何处理来自 Spring Boot 的 LdapAuthenticationProviderConfigurer 的异常

[英]How to handle exceptions from Spring Boot's LdapAuthenticationProviderConfigurer

I have the following web security in a Spring Boot application:我在 Spring 引导应用程序中有以下 web 安全性:

    @Override
    public void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth.ldapAuthentication()
                .contextSource(contextSource)
                .userSearchBase("OU=users,DC=example,DC=com")
                .userSearchFilter("userName={0}")
                .ldapAuthoritiesPopulator(authoritiesPopulator)
                .and()
            // fall back to the admin group if not found
            .ldapAuthentication()
                .contextSource(contextSource)
                .userSearchBase("OU=admins,DC=example,DC=com")
                .userSearchFilter("userName={0}")
                .ldapAuthoritiesPopulator(authoritiesPopulator)
            ;
    }

The idea is pretty straightforward: try searching in the users group and if the user is not found, then try the admin group.这个想法非常简单:尝试在users组中搜索,如果找不到用户,则尝试admin组。 All of this works great until something goes wrong with the first lookup.在第一次查找出现问题之前,所有这些都非常有效。 If the users group suddenly goes away, for example, the first lookup will generate an exception and the second lookup is never attempted.例如,如果users组突然消失,第一次查找将生成异常,并且永远不会尝试第二次查找。 Is there a way to configure LdapAuthenticationProviderConfigurer or perhaps AuthenticationManagerBuilder to not abort the whole process when one of the authentication provider exceptions out?有没有办法配置LdapAuthenticationProviderConfigurerAuthenticationManagerBuilder在身份验证提供程序异常之一出现时不中止整个过程?

following this answer - maybe this (untested code)遵循这个答案- 也许这个(未经测试的代码)


    public void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth.ldapAuthentication()
                .contextSource(contextSource)
                .userSearchBase("DC=example,DC=com")
                //.userSearchFilter("&((userName={0}))")
                .userDnPatterns("userName={0},OU=users", "userName={0},OU=admins")
                .ldapAuthoritiesPopulator(authoritiesPopulator))
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM