春季启动安全LDAP认证
问题描述:
我试图使用自定义登录页面,但做LDAP认证提供了不低于工作是我的安全和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 =鲍勃,OU =人,DC = springframework的,DC =组织 对象类:顶 对象类:人 对象类:organizationalPerson 对象类:为inetOrgPerson CN:鲍勃·汉密尔顿 SN :Hamilton uid:bob userPassword:bobspassword
我在寻找只有有效的用户才能访问应用程序中的其他页面。
配置是否有任何问题,并会感谢您的答案。
答
您应该更改您的代码如下:通过将
.antMatchers("/**").permitAll()
你只要让每一位用户无需任何身份验证,访问的每个页面
@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");
。