Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/354.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Spring LDAP身份验证(是否自动?)_Java_Ldap_Spring Ldap - Fatal编程技术网

Java Spring LDAP身份验证(是否自动?)

Java Spring LDAP身份验证(是否自动?),java,ldap,spring-ldap,Java,Ldap,Spring Ldap,我通读了Spring,无法确定针对LDAP服务器的用户身份验证是否是自动的 所谓“自动化”,我的意思是,如果您在ContextSource中提供userDn和密码,那么它会在bean实例化时自动发生。也就是说,程序员永远不必调用LdapTemplate.authenticate(…)——它发生在“幕后” 所以我想知道 如果Spring LDAP身份验证是自动的 如果有字段可以设置为更改此行为 谢谢, ktm 编辑:我在我编写的一些代码的上下文中问这个问题。下面的ContextSource是我的

我通读了Spring,无法确定针对LDAP服务器的用户身份验证是否是自动的

所谓“自动化”,我的意思是,如果您在
ContextSource
中提供userDn和密码,那么它会在bean实例化时自动发生。也就是说,程序员永远不必调用LdapTemplate.authenticate(…)——它发生在“幕后”

所以我想知道

  • 如果Spring LDAP身份验证是自动的
  • 如果有字段可以设置为更改此行为
  • 谢谢,
    ktm


    编辑:我在我编写的一些代码的上下文中问这个问题。下面的
    ContextSource
    是我的bean文件中的一个上下文源,用户可以选择使用它。它用于在运行时配置userDn和密码(出于安全原因)。我想知道LDAP应用程序是否实际使用我在运行时在身份验证中收集的userDn/密码。(身份验证是否在执行我的代码之前?它是否忽略我的代码配置的userDn/密码字段?)

    我想知道LDAP应用程序是否实际使用我在运行时在身份验证中收集的userDn/密码

    它将使用您在运行时收集的userDn和密码。根据您配置bean的方式,LDAP身份验证将在Spring中使用以下两种路径之一:

  • 绑定身份验证(使用
    BindAuthenticator
  • 密码比较(使用PasswordComparisonAuthenticator)
  • 这些验证器在
    ldapaauthenticationprovider
    的上下文中调用,该上下文可配置为安全命名空间配置中的验证器:

    <authentication-manager alias="authenticationManager">
        <authentication-provider user-service-ref="usernamePasswordUserDetailsService">
            <password-encoder ref="passwordEncoder">
                <salt-source ref="saltSource"/>
            </password-encoder>
        </authentication-provider>
        <authentication-provider ref="ldapAuthenticationProvider"/>
    </authentication-manager>
    
    将使用用户名和密码创建令牌。
    ldapaauthenticationprovider
    响应该令牌类型:

    public class LdapAuthenticationProvider implements AuthenticationProvider, MessageSourceAware {
    
        ...
    
        public boolean supports(Class<?> authentication) {
            return (UsernamePasswordAuthenticationToken.class.isAssignableFrom(authentication));
        }
    }
    
    公共类LdapAuthenticationProvider实现AuthenticationProvider,MessageSourceAware{
    ...
    公共布尔支持(类身份验证){
    返回(UsernamePasswordAuthenticationToken.class.isAssignableFrom(authentication));
    }
    }
    

    并使用存储在
    LdapContextSource
    中的信息进行身份验证。

    添加了一些相关的源代码我相信它确实有效。。。我尝试了以下测试:从beans文件中删除url属性,并改为在上面的resolveAuthInfo方法中设置url(使用setUrl调用)。该应用程序仍能正常工作,并成功完成查询。当然,如果没有setUrl调用,它将无法工作。所以上面的代码正在做一些事情。
    <http auto-config="true">
        <form-login login-page="/auth/login"
                    login-processing-url="/auth/j_security_check"/>
        <logout invalidate-session="true" logout-url="/auth/logout"/>
    </http>
    
    public class LdapAuthenticationProvider implements AuthenticationProvider, MessageSourceAware {
    
        ...
    
        public boolean supports(Class<?> authentication) {
            return (UsernamePasswordAuthenticationToken.class.isAssignableFrom(authentication));
        }
    }