简体   繁体   English

使用嵌入式 LDAP 进行 spring 身份验证

[英]spring authentication with Embedded Ldap

I'm trying to integrate spring authentication with embedded ldap.我正在尝试将 spring 身份验证与嵌入式 ldap 集成。

I have user info in local ldif file.我在本地 ldif 文件中有用户信息。

User1用户 1

 dn: uid=joe,ou=otherpeople,dc=springframework,dc=org
objectclass: top
objectclass: person
objectclass: organizationalPerson
objectclass: inetOrgPerson
cn: Joe Smeth
sn: Smeth
uid: joe
userPassword: joespassword

User 2用户 2

dn: uid=bob,ou=people,dc=springframework,dc=org
objectclass: top
objectclass: person
objectclass: organizationalPerson
objectclass: inetOrgPerson
cn: Bob Hamilton
sn: Hamilton
uid: bob
userPassword: bobspassword

Spring WebsecurityConfigFile Spring WebsecurityConfig 文件

@Configuration
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
            .authorizeRequests()
                .anyRequest().fullyAuthenticated()
                .and()
            .formLogin();
    }

    @Override
    public void configure(AuthenticationManagerBuilder auth) throws Exception {

        auth
            .ldapAuthentication()
                .userDnPatterns("uid={0},ou=people")
                .contextSource()
                    .url("ldap://localhost:8389/dc=springframework,dc=org")
                    .and()
                .passwordCompare()
                    .passwordAttribute("userPassword");
   }
}

userDnPattern in config file I have taken ou=people (uid={0},ou=people) so I'm able to authenticate bob .配置文件中的userDnPattern我采用了 ou=people (uid={0},ou=people) 所以我能够验证bob When it comes to joe his directory path is different.说到joe,他的目录路径是不同的。 So I'm not able to login using joe's username and password.所以我无法使用 joe 的用户名和密码登录。

在此处输入图片说明

What should be my SpringConfiguration for authenticating all the users irrespective of the directory structure?无论目录结构如何,用于验证所有用户的 SpringConfiguration 应该是什么?

Authentication for any user in the DIT (Directory information tree) using userSearchFilter .使用userSearchFilter对 DIT(目录信息树)中的任何用户进行身份验证。

Spring configuration is, Spring配置是,

auth.ldapAuthentication()
            .userSearchFilter("(uid={0})")
                    .contextSource()
                        .url("ldap://localhost:8389/dc=springframework,dc=org")
                        .and()
                    .passwordCompare()        
                .passwordAttribute("userPassword");

Thanks @EricLavault谢谢@EricLavault

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

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