From ae0860801146b860586280594d7fc6431b766b18 Mon Sep 17 00:00:00 2001 From: Filip Hanik Date: Thu, 10 Dec 2020 10:50:32 -0800 Subject: [PATCH] LdapAuthoritiesPopulator should be postProcessed To enable customizations through withObjectPostProcessor --- .../LdapAuthenticationProviderConfigurer.java | 2 +- ...AuthenticationProviderConfigurerTests.java | 49 +++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/config/src/main/java/org/springframework/security/config/annotation/authentication/configurers/ldap/LdapAuthenticationProviderConfigurer.java b/config/src/main/java/org/springframework/security/config/annotation/authentication/configurers/ldap/LdapAuthenticationProviderConfigurer.java index 07605a3fea..5b6c19f4b1 100644 --- a/config/src/main/java/org/springframework/security/config/annotation/authentication/configurers/ldap/LdapAuthenticationProviderConfigurer.java +++ b/config/src/main/java/org/springframework/security/config/annotation/authentication/configurers/ldap/LdapAuthenticationProviderConfigurer.java @@ -141,7 +141,7 @@ public class LdapAuthenticationProviderConfigurer() { + @Override + public O postProcess(O object) { + if (object instanceof DefaultLdapAuthoritiesPopulator) { + return (O)new TestPostProcessLdapAuthoritiesPopulator(); + } + else { + return object; + } + } + } + ); + invokeMethod(this.configurer, "getLdapAuthoritiesPopulator"); + assertThat(getField(this.configurer, "ldapAuthoritiesPopulator")) + .isInstanceOf(TestPostProcessLdapAuthoritiesPopulator.class); + } + + private static class TestPostProcessLdapAuthoritiesPopulator implements LdapAuthoritiesPopulator { + @Override + public Collection getGrantedAuthorities( + DirContextOperations userData, String username) { + return null; + } + } + }