Skip to content

Commit

Permalink
πŸ› : prevent spring from loading LdapAutoConfiguration
Browse files Browse the repository at this point in the history
when gaia.ldap.enabled = false
  • Loading branch information
juwit committed Apr 27, 2021
1 parent 9e43922 commit 8f7c767
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package io.gaia_app.config.security.ldap;

import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.ldap.LdapAutoConfiguration;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableAutoConfiguration(exclude = LdapAutoConfiguration.class)
@ConditionalOnProperty(prefix = "gaia", name = "ldap.enabled", havingValue = "false", matchIfMissing = true)
public class CustomLdapAutoConfiguration {
// this blocks the load of ldap auto configuration if the ldap is not enabled
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.ldap.core.LdapTemplate;
import org.testcontainers.junit.jupiter.Testcontainers;

import static org.junit.jupiter.api.Assertions.assertNotNull;
Expand All @@ -21,6 +22,12 @@ void ldapSecurityConfig_shouldNotBeInstantiated(
@Autowired(required = false) LdapSecurityConfig ldapSecurityConfig) {
assertNull(ldapSecurityConfig);
}

@Test
void ldapTemplate_shouldNotBeInstantiated(
@Autowired(required = false) LdapTemplate ldapTemplate) {
assertNull(ldapTemplate);
}
}

@Nested
Expand All @@ -35,5 +42,11 @@ void ldapSecurityConfig_shouldBeInstantiated(
@Autowired(required = false) LdapSecurityConfig ldapSecurityConfig) {
assertNotNull(ldapSecurityConfig);
}

@Test
void ldapTemplate_shouldBeInstantiated(
@Autowired(required = false) LdapTemplate ldapTemplate) {
assertNotNull(ldapTemplate);
}
}
}

0 comments on commit 8f7c767

Please sign in to comment.