相关疑难解决方法(0)

使用Spring Security和JavaConfig进行身份验证时出现PartialResultException

我目前正在使用Spring Boot创建一个新的Web应用程序,并开始集成Spring Security进行身份验证.在成功遵循基于Spring Boot的LDAP教程之后,我想将基于JavaConfig的配置指向我的Active Directory实例.

我的应用程序现在按预期处理错误的凭据,但现在导致有效的凭据

javax.naming.PartialResultException: Unprocessed Continuation Reference(s); remaining name ''
Run Code Online (Sandbox Code Playgroud)

这是一个常见的问题-有一个数量 地方在那里已经遇到了这个问题.解决方案似乎是将Context.REFERRAL设置为"follow",但我找不到任何指示如何使用JavaConfig设置该选项的文档.这是我唯一可以恢复基于XML的配置吗?看起来Spring正在将开发人员推向JavaConfig,所以如果可能的话,我想避免混合这两种方法.

以下是我的安全配置:

@Configuration
@EnableWebMvcSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests().antMatchers("/css/**").permitAll().anyRequest()
                .fullyAuthenticated().and().formLogin();
    }

    @Configuration
    protected static class AuthenticationConfiguration extends
            GlobalAuthenticationConfigurerAdapter {

        @Override
        public void init(AuthenticationManagerBuilder auth) throws Exception {
            auth.ldapAuthentication()
                .userSearchBase("")
                .userSearchFilter("(&(cn={0}))").contextSource()
                .managerDn("<username>")
                .managerPassword("<password>")
                .url("ldap://<url>");
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

java spring-security spring-ldap

9
推荐指数
1
解决办法
1万
查看次数

ldap搜索非常慢

我正在使用JNDI连接到LDAP活动目录,我想搜索名称中包含搜索字符串的用户,所以我的搜索方法如下:

public static List<LDAPUser> searchContactsByName(
        ExtendedDirContext extendedDirContext, String name) {

    try {

        LdapContext ldapContext = extendedDirContext.getLdapContext();
        String searchBaseStr = extendedDirContext.getSearchBase();

        String sortKey = LDAPAttributes.NAME;
        ldapContext.setRequestControls(new Control[] { new SortControl(
                sortKey, Control.CRITICAL) });

        SearchControls searchCtls = new SearchControls();
        searchCtls.setTimeLimit(1000 * 10);

        String returnedAtts[] = { LDAPAttributes.USER_NAME,
                LDAPAttributes.NAME };
        searchCtls.setReturningAttributes(returnedAtts);

        searchCtls.setSearchScope(SearchControls.SUBTREE_SCOPE);

        String searchFilter = "(&(ObjectCategory=person)(cn=*" + name
                + "*))";

        NamingEnumeration<SearchResult> results = ldapContext.search(
                searchBaseStr, searchFilter, searchCtls);

        List<LDAPUser> users = new ArrayList<LDAPUser>(0);
        while (results.hasMoreElements()) {
            SearchResult sr = (SearchResult) results.next();
            Attributes attrs = …
Run Code Online (Sandbox Code Playgroud)

java jndi ldap active-directory

2
推荐指数
1
解决办法
1万
查看次数