首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

如何使用Spring Security对Active Directory服务器进行身份验证?

要使用Spring Security对Active Directory服务器进行身份验证,您需要遵循以下步骤:

  1. 添加依赖

在您的项目中添加Spring Security和Spring Security LDAP的依赖。

代码语言:xml<dependency>
复制
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-security</artifactId>
</dependency><dependency>
   <groupId>org.springframework.security</groupId>
   <artifactId>spring-security-ldap</artifactId>
</dependency>
  1. 配置Spring Security

在您的Spring Security配置类中,配置LDAP身份验证。

代码语言:java
复制
@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();
    }
}
  1. 测试

启动您的应用程序,并使用您的Active Directory凭据进行身份验证。

注意:在进行身份验证之前,您需要确保您的Active Directory服务器已正确配置。

推荐的腾讯云相关产品:

页面内容是否对你有帮助?
有帮助
没帮助

相关·内容

领券