要使用Spring Security对Active Directory服务器进行身份验证,您需要遵循以下步骤:
在您的项目中添加Spring Security和Spring Security LDAP的依赖。
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency><dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-ldap</artifactId>
</dependency>
在您的Spring Security配置类中,配置LDAP身份验证。
@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth
.ldapAuthentication()
.userDnPatterns("uid={0},ou=people")
.groupSearchBase("ou=groups")
.contextSource()
.url("ldap://localhost:8389/dc=springframework,dc=org")
.managerDn("cn=admin,dc=springframework,dc=org")
.managerPassword("password");
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.anyRequest().authenticated()
.and()
.formLogin();
}
}
启动您的应用程序,并使用您的Active Directory凭据进行身份验证。
注意:在进行身份验证之前,您需要确保您的Active Directory服务器已正确配置。
推荐的腾讯云相关产品:
领取专属 10元无门槛券
手把手带您无忧上云