![](/img/trans.png)
[英]how to achieve Ldap Authentication using spring security(spring boot)
[英]Spring Boot Security LDAP authentication
我正在尝试使用自定义登录页面进行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对象类:顶级对象类:person对象类:organizationalPerson对象类:inetOrgPerson cn:Bob Hamilton sn:Hamilton uid:bob userPassword: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()
您只允许每个用户无需任何身份验证即可访问每个页面。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.