Java Spring引导安全LDAP身份验证
我正在尝试使用自定义登录页面进行LDAP身份验证,但下面的安全和LDAP配置不起作用Java Spring引导安全LDAP身份验证,java,spring,spring-security,spring-boot,ldap,Java,Spring,Spring Security,Spring Boot,Ldap,我正在尝试使用自定义登录页面进行LDAP身份验证,但下面的安全和LDAP配置不起作用 @Configuration @EnableWebSecurity @Order(SecurityProperties.ACCESS_OVERRIDE_ORDER) public class WebSecurityConfig extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecuri
@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
对象类:top
对象类:person
对象类:organizationalPerson
对象类:inetOrgPerson
cn:鲍勃·汉密尔顿
序号:汉密尔顿
鲍勃
用户密码:bobspassword
我正在寻找只有有效的用户可以访问应用程序中的其他页面
配置是否有任何问题,我们将感谢您的回答。您应该将代码更改为以下内容:
@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()
您只需允许每个用户访问每个页面而无需任何身份验证