Skip to content

Commit 5937ba9

Browse files
kse-musicrwinch
authored andcommitted
Polish use getBeanProvider instead of getBeanNamesForType
1 parent 4bc6e5b commit 5937ba9

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

config/src/main/java/org/springframework/security/config/annotation/web/configurers/AbstractHttpConfigurer.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2024 the original author or authors.
2+
* Copyright 2002-2025 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.
@@ -31,6 +31,7 @@
3131
* {@link HttpSecurity}.
3232
*
3333
* @author Rob Winch
34+
* @author Ding Hao
3435
*/
3536
public abstract class AbstractHttpConfigurer<T extends AbstractHttpConfigurer<T, B>, B extends HttpSecurityBuilder<B>>
3637
extends SecurityConfigurerAdapter<DefaultSecurityFilterChain, B> {
@@ -70,13 +71,8 @@ protected SecurityContextHolderStrategy getSecurityContextHolderStrategy() {
7071
return this.securityContextHolderStrategy;
7172
}
7273
ApplicationContext context = getBuilder().getSharedObject(ApplicationContext.class);
73-
String[] names = context.getBeanNamesForType(SecurityContextHolderStrategy.class);
74-
if (names.length == 1) {
75-
this.securityContextHolderStrategy = context.getBean(SecurityContextHolderStrategy.class);
76-
}
77-
else {
78-
this.securityContextHolderStrategy = SecurityContextHolder.getContextHolderStrategy();
79-
}
74+
this.securityContextHolderStrategy = context.getBeanProvider(SecurityContextHolderStrategy.class)
75+
.getIfUnique(SecurityContextHolder::getContextHolderStrategy);
8076
return this.securityContextHolderStrategy;
8177
}
8278

0 commit comments

Comments
 (0)