ldapAuthentication和inMemoryAuthentication有什么区别?

时间:2017-04-25 16:04:27

标签: java spring spring-mvc spring-boot

我目前正在关注Spring.io教程。链接为Authenicating-ladpsecuring-web

我可以看到除了配置之外它们非常相似。

LDAP

@Override
    public void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth
            .ldapAuthentication()
                .userDnPatterns("uid={0},ou=people")
                .groupSearchBase("ou=groups")
                .contextSource(contextSource())
                .passwordCompare()
                    .passwordEncoder(new LdapShaPasswordEncoder())
                    .passwordAttribute("userPassword");
    }

    @Bean
    public DefaultSpringSecurityContextSource contextSource() {
        return  new DefaultSpringSecurityContextSource(Arrays.asList("ldap://localhost:8389/"), "dc=springframework,dc=org");
    }

固定幅材

@Autowired
    public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
        auth
            .inMemoryAuthentication()
                .withUser("user").password("password").roles("USER");
    }

使用每种产品的利弊是什么?哪一个是最佳实践的首选?

1 个答案:

答案 0 :(得分:0)

内存中身份验证是最简单的形式,并要求在代码本身中指定所有用户的凭据。除了最简单的情况之外,这是不切实际的。

LDAP身份验证涉及对LDAP访问系统进行身份验证,该系统在全球许多组织和企业中使用。它更灵活,因此更复杂。

相关问题