【问题标题】:Spring Boot Security LDAP authenticationSpring Boot 安全 LDAP 身份验证
【发布时间】:2016-09-23 20:48:25
【问题描述】:

我正在尝试使用自定义登录页面进行 LDAP 身份验证,但它在下面不起作用是我的安全和 ldap 配置

@Configuration
@EnableWebSecurity
@Order(SecurityProperties.ACCESS_OVERRIDE_ORDER)
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {

        http.httpBasic().and().authorizeRequests().antMatchers("/**").permitAll()
            .anyRequest().authenticated()
            .and().formLogin().loginPage("/login")
            .usernameParameter("username")
            .passwordParameter("password")
            .failureUrl("/login?error");

    }

    @Autowired
    public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
        auth
            .ldapAuthentication()
                .userDnPatterns("uid={0},ou=people")
                .groupSearchBase("ou=groups")
                .contextSource().ldif("classpath:test-server.ldif");
    }
}

以下是放置在资源文件夹中的示例 LDif 文件

dn: uid=bob,ou=people,dc=springframework,dc=org 对象类:顶部 对象类:人 对象类:organizationalPerson 对象类:inetOrgPerson cn:鲍勃·汉密尔顿 sn:汉密尔顿 uid:鲍勃 用户密码:bobspassword

我正在寻找只有有效用户才能访问应用程序中的其他页面。

配置有什么问题吗,不胜感激。

【问题讨论】:

    标签: java spring spring-security spring-boot ldap


    【解决方案1】:

    您应该将代码更改为以下内容:

       @Override
       protected void configure(HttpSecurity http) throws Exception {
       http.httpBasic().and().authorizeRequests()
       .anyRequest().authenticated()
       .and().formLogin().loginPage("/login")
       .usernameParameter("username")
       .passwordParameter("password")
       .failureUrl("/login?error");
    

    通过放

    .antMatchers("/**").permitAll()
    

    您只是允许每个用户无需任何身份验证即可访问每个页面。

    【讨论】:

      猜你喜欢
      • 2011-05-04
      • 2017-04-12
      • 2012-12-13
      • 1970-01-01
      • 2019-02-21
      • 2017-07-30
      • 2022-01-20
      • 2013-03-15
      • 2018-03-11
      相关资源
      最近更新 更多