mirror of
https://github.com/spring-projects/spring-security.git
synced 2025-06-24 13:02:13 +00:00
Polish use getBeanProvider instead of getBeanNamesForType
This commit is contained in:
parent
4bc6e5b9d2
commit
5937ba9a06
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2024 the original author or authors.
|
* Copyright 2002-2025 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.
|
||||||
@ -31,6 +31,7 @@ import org.springframework.security.web.DefaultSecurityFilterChain;
|
|||||||
* {@link HttpSecurity}.
|
* {@link HttpSecurity}.
|
||||||
*
|
*
|
||||||
* @author Rob Winch
|
* @author Rob Winch
|
||||||
|
* @author Ding Hao
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractHttpConfigurer<T extends AbstractHttpConfigurer<T, B>, B extends HttpSecurityBuilder<B>>
|
public abstract class AbstractHttpConfigurer<T extends AbstractHttpConfigurer<T, B>, B extends HttpSecurityBuilder<B>>
|
||||||
extends SecurityConfigurerAdapter<DefaultSecurityFilterChain, B> {
|
extends SecurityConfigurerAdapter<DefaultSecurityFilterChain, B> {
|
||||||
@ -70,13 +71,8 @@ public abstract class AbstractHttpConfigurer<T extends AbstractHttpConfigurer<T,
|
|||||||
return this.securityContextHolderStrategy;
|
return this.securityContextHolderStrategy;
|
||||||
}
|
}
|
||||||
ApplicationContext context = getBuilder().getSharedObject(ApplicationContext.class);
|
ApplicationContext context = getBuilder().getSharedObject(ApplicationContext.class);
|
||||||
String[] names = context.getBeanNamesForType(SecurityContextHolderStrategy.class);
|
this.securityContextHolderStrategy = context.getBeanProvider(SecurityContextHolderStrategy.class)
|
||||||
if (names.length == 1) {
|
.getIfUnique(SecurityContextHolder::getContextHolderStrategy);
|
||||||
this.securityContextHolderStrategy = context.getBean(SecurityContextHolderStrategy.class);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
this.securityContextHolderStrategy = SecurityContextHolder.getContextHolderStrategy();
|
|
||||||
}
|
|
||||||
return this.securityContextHolderStrategy;
|
return this.securityContextHolderStrategy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user