DEV Community

Al-Karid
Al-Karid

Posted on

3

Authenticating a Spring Boot Application with Active Directory

Authentication with Active Directory in a Spring Boot application is straightforward and requires minimal setup. You don't need to install an embedded server for testing connectivity or additional complex packages. In fact, the process is streamlined with just a couple of dependencies and a simple configuration.

Dependencies

First, ensure you have the necessary dependencies in your pom.xml or build.gradle:

<dependency>
    <groupId>org.springframework.security</groupId>
    <artifactId>spring-security-ldap</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-ldap</artifactId>
</dependency>
Enter fullscreen mode Exit fullscreen mode

Configuration

Next, configure your Spring Security in a WebSecurityConfig class:

@EnableWebSecurity
public class WebSecurityConfig{

    @Bean
    SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
        http
            .authorizeHttpRequests((authorize) -> authorize.anyRequest().fullyAuthenticated())
            .formLogin(Customizer.withDefaults());

        return http.build();

    @Bean
    public ActiveDirectoryLdapAuthenticationProvider authenticationProvider() {
        return new ActiveDirectoryLdapAuthenticationProvider("domain.com", "ldap://ip-addr");
    }
}

Enter fullscreen mode Exit fullscreen mode

And that's it, happy securing 😎 !!

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read full post →

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more