简体   繁体   English

Spring LDAP身份验证(自动或不自动?)

[英]Spring LDAP Authentication (Automatic or not?)

I read through the Spring LDAP reference docs and was unable to figure out whether user authentication against the LDAP server is automated or not. 我阅读了Spring LDAP参考文档 ,但无法确定针对LDAP服务器的用户身份验证是否自动化。

By "automated" I mean that it happens automatically on bean instantiation if you provide userDn and password in your ContextSource . “自动化”是指如果在ContextSource提供userDn和密码,它会在bean实例化时自动发生。 That is to say, the programmer never has to call LdapTemplate.authenticate(...) - it happens "behind-the-scenes". 也就是说,程序员永远LdapTemplate.authenticate(...)调用LdapTemplate.authenticate(...) - 它发生在“幕后”。

So I would like to know 所以我想知道

  1. If Spring LDAP authentication is automatic 如果Spring LDAP身份验证是自动的
  2. If there are fields I can set to change this behavior 如果有字段我可以设置更改此行为

Thanks, 谢谢,
ktm KTM


EDIT: I ask this question in the context of some code that I wrote. 编辑:我在我写的一些代码的上下文中问这个问题。 The following ContextSource is one of the context sources in my beans file, which the user can opt to use. 以下ContextSource是我的beans文件中的上下文源之一,用户可以选择使用它。 It is used to configure the userDn and password at runtime (for security reasons). 它用于在运行时配置userDn和密码(出于安全原因)。 I want to know whether the LDAP application will actually use the userDn/password that I collect at runtime in the authentication. 我想知道LDAP应用程序是否实际使用我在运行时在身份验证中收集的userDn / password。 (Does the authentication precede the execution of my code? Does it ignore the userDn/password fields that my code configures?) (验证是否在我的代码执行之前?它是否忽略我的代码配置的userDn / password字段?)

public class RuntimeContext extends LdapContextSource {

    public RuntimeContext() {
        super();
        if (!resolveAuthInfo()) {
            System.out.println("Failed to resolve auth info. Exiting...");
            System.exit(1);
        }
    }

    public boolean resolveAuthInfo()
    {
        String myUserDn, myPassword;
        try {
            BufferedReader br = new BufferedReader(
                    new InputStreamReader(System.in));
            System.out.print("userDn: ");
            myUserDn = br.readLine();
            System.out.print("password: ");
            myPassword = br.readLine();
        } catch (IOException e) {
            return false;
        }
        super.setUserDn(myUserDn);
        super.setPassword(myPassword);
        return true;
    }
}

I want to know whether the LDAP application will actually use the userDn/password that I collect at runtime in the authentication. 我想知道LDAP应用程序是否实际使用我在运行时在身份验证中收集的userDn / password。

http://static.springsource.org/spring-security/site/docs/3.0.x/reference/ldap.html http://static.springsource.org/spring-security/site/docs/3.0.x/reference/ldap.html

It will use the userDn and password that you collect at runtime. 它将使用您在运行时收集的userDn和密码。 Based on how you configure your beans, LDAP authentication will use one of two paths in Spring: 根据您配置bean的方式,LDAP身份验证将使用Spring中的两个路径之一:

  1. Bind Authentication (using BindAuthenticator ) 绑定身份验证(使用BindAuthenticator
  2. Password Comparison (using PasswordComparisonAuthenticator ) 密码比较(使用PasswordComparisonAuthenticator

These authenticators are called within the context of the LdapAuthenticationProvider which can be configured as an authenticator in the security namespace configuration: 这些验证器在LdapAuthenticationProvider的上下文中调用,可以将其配置为安全命名空间配置中的验证器:

<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>

When the UsernamePasswordAuthenticationFilter is invoked (via the /auth/login page): 调用UsernamePasswordAuthenticationFilter (通过/ auth / login页面):

<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>

a token is created with the username and password. 使用用户名和密码创建令牌。 The LdapAuthenticationProvider responds to that token type: LdapAuthenticationProvider响应该令牌类型:

public class LdapAuthenticationProvider implements AuthenticationProvider, MessageSourceAware {

    ...

    public boolean supports(Class<?> authentication) {
        return (UsernamePasswordAuthenticationToken.class.isAssignableFrom(authentication));
    }
}

And uses the information you stored in the LdapContextSource to do the authentication. 并使用您存储在LdapContextSource中的信息进行身份验证。

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

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