|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2018 the original author or authors. |
| 2 | + * Copyright 2002-2021 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
@@ -57,6 +57,8 @@ public class AuthenticationManagerBeanDefinitionParser implements BeanDefinition
|
57 | 57 |
|
58 | 58 | private static final String ATT_ERASE_CREDENTIALS = "erase-credentials";
|
59 | 59 |
|
| 60 | + private static final String AUTHENTICATION_EVENT_PUBLISHER_BEAN_NAME = "defaultAuthenticationEventPublisher"; |
| 61 | + |
60 | 62 | @Override
|
61 | 63 | public BeanDefinition parse(Element element, ParserContext pc) {
|
62 | 64 | String id = element.getAttribute("id");
|
@@ -86,11 +88,15 @@ public BeanDefinition parse(Element element, ParserContext pc) {
|
86 | 88 | if ("false".equals(element.getAttribute(ATT_ERASE_CREDENTIALS))) {
|
87 | 89 | providerManagerBldr.addPropertyValue("eraseCredentialsAfterAuthentication", false);
|
88 | 90 | }
|
89 |
| - // Add the default event publisher |
90 |
| - BeanDefinition publisher = new RootBeanDefinition(DefaultAuthenticationEventPublisher.class); |
91 |
| - String pubId = pc.getReaderContext().generateBeanName(publisher); |
92 |
| - pc.registerBeanComponent(new BeanComponentDefinition(publisher, pubId)); |
93 |
| - providerManagerBldr.addPropertyReference("authenticationEventPublisher", pubId); |
| 91 | + |
| 92 | + if (!pc.getRegistry().containsBeanDefinition(AUTHENTICATION_EVENT_PUBLISHER_BEAN_NAME)) { |
| 93 | + // Add the default event publisher to the context |
| 94 | + BeanDefinition publisher = new RootBeanDefinition(DefaultAuthenticationEventPublisher.class); |
| 95 | + pc.registerBeanComponent(new BeanComponentDefinition(publisher, AUTHENTICATION_EVENT_PUBLISHER_BEAN_NAME)); |
| 96 | + } |
| 97 | + |
| 98 | + providerManagerBldr.addPropertyReference("authenticationEventPublisher", |
| 99 | + AUTHENTICATION_EVENT_PUBLISHER_BEAN_NAME); |
94 | 100 | pc.registerBeanComponent(new BeanComponentDefinition(providerManagerBldr.getBeanDefinition(), id));
|
95 | 101 | if (StringUtils.hasText(alias)) {
|
96 | 102 | pc.getRegistry().registerAlias(id, alias);
|
|
0 commit comments