|
@@ -1,5 +1,5 @@
|
|
/*
|
|
/*
|
|
- * Copyright 2002-2016 the original author or authors.
|
|
|
|
|
|
+ * Copyright 2002-2021 the original author or authors.
|
|
*
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* you may not use this file except in compliance with the License.
|
|
@@ -20,6 +20,7 @@ import org.junit.Test;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.context.ApplicationListener;
|
|
import org.springframework.context.ApplicationListener;
|
|
import org.springframework.context.ConfigurableApplicationContext;
|
|
import org.springframework.context.ConfigurableApplicationContext;
|
|
|
|
+import org.springframework.security.authentication.AuthenticationEventPublisher;
|
|
import org.springframework.security.authentication.AuthenticationProvider;
|
|
import org.springframework.security.authentication.AuthenticationProvider;
|
|
import org.springframework.security.authentication.DefaultAuthenticationEventPublisher;
|
|
import org.springframework.security.authentication.DefaultAuthenticationEventPublisher;
|
|
import org.springframework.security.authentication.ProviderManager;
|
|
import org.springframework.security.authentication.ProviderManager;
|
|
@@ -49,6 +50,18 @@ public class AuthenticationManagerBeanDefinitionParserTests {
|
|
+ " </user-service>"
|
|
+ " </user-service>"
|
|
+ " </authentication-provider>"
|
|
+ " </authentication-provider>"
|
|
+ "</authentication-manager>";
|
|
+ "</authentication-manager>";
|
|
|
|
+
|
|
|
|
+ // Issue #7282
|
|
|
|
+ // @formatter:off
|
|
|
|
+ private static final String CONTEXT_MULTI = "<authentication-manager id='amSecondary'>"
|
|
|
|
+ + " <authentication-provider>"
|
|
|
|
+ + " <user-service>"
|
|
|
|
+ + " <user name='john' password='{noop}doe' authorities='ROLE_C,ROLE_D' />"
|
|
|
|
+ + " </user-service>"
|
|
|
|
+ + " </authentication-provider>"
|
|
|
|
+ + "</authentication-manager>";
|
|
|
|
+ // @formatter:on
|
|
|
|
+
|
|
@Rule
|
|
@Rule
|
|
public final SpringTestRule spring = new SpringTestRule();
|
|
public final SpringTestRule spring = new SpringTestRule();
|
|
|
|
|
|
@@ -60,6 +73,18 @@ public class AuthenticationManagerBeanDefinitionParserTests {
|
|
assertThat(context.getBeansOfType(AuthenticationProvider.class)).hasSize(1);
|
|
assertThat(context.getBeansOfType(AuthenticationProvider.class)).hasSize(1);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Test
|
|
|
|
+ public void eventPublishersAreRegisteredAsTopLevelBeans() {
|
|
|
|
+ ConfigurableApplicationContext context = this.spring.context(CONTEXT).getContext();
|
|
|
|
+ assertThat(context.getBeansOfType(AuthenticationEventPublisher.class)).hasSize(1);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Test
|
|
|
|
+ public void onlyOneEventPublisherIsRegisteredForMultipleAuthenticationManagers() {
|
|
|
|
+ ConfigurableApplicationContext context = this.spring.context(CONTEXT + '\n' + CONTEXT_MULTI).getContext();
|
|
|
|
+ assertThat(context.getBeansOfType(AuthenticationEventPublisher.class)).hasSize(1);
|
|
|
|
+ }
|
|
|
|
+
|
|
@Test
|
|
@Test
|
|
public void eventsArePublishedByDefault() throws Exception {
|
|
public void eventsArePublishedByDefault() throws Exception {
|
|
ConfigurableApplicationContext appContext = this.spring.context(CONTEXT)
|
|
ConfigurableApplicationContext appContext = this.spring.context(CONTEXT)
|