Skip to content

Commit aad371f

Browse files
committed
Delay initialization AuthenticationProvider in Global Authentication
1 parent b9d5493 commit aad371f

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

config/src/main/java/org/springframework/security/config/annotation/authentication/configuration/InitializeAuthenticationProviderBeanManagerConfigurer.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,6 +18,7 @@
1818

1919
import java.util.ArrayList;
2020
import java.util.List;
21+
import java.util.function.Supplier;
2122

2223
import org.apache.commons.logging.Log;
2324
import org.apache.commons.logging.LogFactory;
@@ -94,25 +95,26 @@ private <T> List<BeanWithName<T>> getBeansWithName(Class<T> type) {
9495
String[] beanNames = InitializeAuthenticationProviderBeanManagerConfigurer.this.context
9596
.getBeanNamesForType(type);
9697
for (String beanName : beanNames) {
97-
T bean = InitializeAuthenticationProviderBeanManagerConfigurer.this.context.getBean(beanName, type);
98-
beanWithNames.add(new BeanWithName<T>(bean, beanName));
98+
Supplier<T> bean = () -> InitializeAuthenticationProviderBeanManagerConfigurer.this.context
99+
.getBean(beanName, type);
100+
beanWithNames.add(new BeanWithName<>(bean, beanName));
99101
}
100102
return beanWithNames;
101103
}
102104

103105
static class BeanWithName<T> {
104106

105-
private final T bean;
107+
private final Supplier<T> bean;
106108

107109
private final String name;
108110

109-
BeanWithName(T bean, String name) {
111+
BeanWithName(Supplier<T> bean, String name) {
110112
this.bean = bean;
111113
this.name = name;
112114
}
113115

114116
T getBean() {
115-
return this.bean;
117+
return this.bean.get();
116118
}
117119

118120
String getName() {

0 commit comments

Comments
 (0)