Reduce method visibility when possible

Reduce method visibility for package private classes when possible.

In the case of abstract classes that will eventually be made public,
the class has been made public and a package-private constructor has
been added.

Issue gh-8945
This commit is contained in:
Phillip Webb 2020-07-29 22:05:08 -07:00 committed by Rob Winch
parent ec6a4cb3f0
commit 8d3f039f76
155 changed files with 508 additions and 477 deletions

View File

@ -142,7 +142,7 @@ class AclClassIdUtils {
return object.getClass().isAssignableFrom(String.class); return object.getClass().isAssignableFrom(String.class);
} }
public void setConversionService(ConversionService conversionService) { void setConversionService(ConversionService conversionService) {
Assert.notNull(conversionService, "conversionService must not be null"); Assert.notNull(conversionService, "conversionService must not be null");
this.conversionService = conversionService; this.conversionService = conversionService;
} }

View File

@ -655,15 +655,15 @@ public class BasicLookupStrategy implements LookupStrategy {
this.id = id; this.id = id;
} }
Long getId() {
return this.id;
}
@Override @Override
public List<AccessControlEntry> getEntries() { public List<AccessControlEntry> getEntries() {
throw new UnsupportedOperationException("Stub only"); throw new UnsupportedOperationException("Stub only");
} }
public Long getId() {
return this.id;
}
@Override @Override
public ObjectIdentity getObjectIdentity() { public ObjectIdentity getObjectIdentity() {
throw new UnsupportedOperationException("Stub only"); throw new UnsupportedOperationException("Stub only");

View File

@ -175,29 +175,29 @@ public class JdbcAclServiceTests {
.isEqualTo(UUID.fromString("25d93b3f-c3aa-4814-9d5e-c7c96ced7762")); .isEqualTo(UUID.fromString("25d93b3f-c3aa-4814-9d5e-c7c96ced7762"));
} }
private class MockLongIdDomainObject { class MockLongIdDomainObject {
private Object id; private Object id;
public Object getId() { Object getId() {
return this.id; return this.id;
} }
public void setId(Object id) { void setId(Object id) {
this.id = id; this.id = id;
} }
} }
private class MockUntypedIdDomainObject { class MockUntypedIdDomainObject {
private Object id; private Object id;
public Object getId() { Object getId() {
return this.id; return this.id;
} }
public void setId(Object id) { void setId(Object id) {
this.id = id; this.id = id;
} }

View File

@ -273,7 +273,7 @@ public class LdapAuthenticationProviderBuilderSecurityBuilderTests {
abstract static class BaseLdapServerConfig extends BaseLdapProviderConfig { abstract static class BaseLdapServerConfig extends BaseLdapProviderConfig {
@Bean @Bean
public ApacheDSContainer ldapServer() throws Exception { ApacheDSContainer ldapServer() throws Exception {
ApacheDSContainer apacheDSContainer = new ApacheDSContainer("dc=springframework,dc=org", ApacheDSContainer apacheDSContainer = new ApacheDSContainer("dc=springframework,dc=org",
"classpath:/test-server.ldif"); "classpath:/test-server.ldif");
apacheDSContainer.setPort(getPort()); apacheDSContainer.setPort(getPort());
@ -288,7 +288,7 @@ public class LdapAuthenticationProviderBuilderSecurityBuilderTests {
abstract static class BaseLdapProviderConfig extends WebSecurityConfigurerAdapter { abstract static class BaseLdapProviderConfig extends WebSecurityConfigurerAdapter {
@Bean @Bean
public BaseLdapPathContextSource contextSource() throws Exception { BaseLdapPathContextSource contextSource() throws Exception {
DefaultSpringSecurityContextSource contextSource = new DefaultSpringSecurityContextSource( DefaultSpringSecurityContextSource contextSource = new DefaultSpringSecurityContextSource(
"ldap://127.0.0.1:" + getPort() + "/dc=springframework,dc=org"); "ldap://127.0.0.1:" + getPort() + "/dc=springframework,dc=org");
contextSource.setUserDn("uid=admin,ou=system"); contextSource.setUserDn("uid=admin,ou=system");
@ -298,7 +298,7 @@ public class LdapAuthenticationProviderBuilderSecurityBuilderTests {
} }
@Bean @Bean
public AuthenticationManager authenticationManager(AuthenticationManagerBuilder auth) throws Exception { AuthenticationManager authenticationManager(AuthenticationManagerBuilder auth) throws Exception {
configure(auth); configure(auth);
return auth.build(); return auth.build();
} }

View File

@ -116,19 +116,19 @@ public class HelloRSocketITests {
static class Config { static class Config {
@Bean @Bean
public ServerController controller() { ServerController controller() {
return new ServerController(); return new ServerController();
} }
@Bean @Bean
public RSocketMessageHandler messageHandler() { RSocketMessageHandler messageHandler() {
RSocketMessageHandler handler = new RSocketMessageHandler(); RSocketMessageHandler handler = new RSocketMessageHandler();
handler.setRSocketStrategies(rsocketStrategies()); handler.setRSocketStrategies(rsocketStrategies());
return handler; return handler;
} }
@Bean @Bean
public RSocketStrategies rsocketStrategies() { RSocketStrategies rsocketStrategies() {
return RSocketStrategies.builder().encoder(new BasicAuthenticationEncoder()).build(); return RSocketStrategies.builder().encoder(new BasicAuthenticationEncoder()).build();
} }

View File

@ -137,19 +137,19 @@ public class JwtITests {
static class Config { static class Config {
@Bean @Bean
public ServerController controller() { ServerController controller() {
return new ServerController(); return new ServerController();
} }
@Bean @Bean
public RSocketMessageHandler messageHandler() { RSocketMessageHandler messageHandler() {
RSocketMessageHandler handler = new RSocketMessageHandler(); RSocketMessageHandler handler = new RSocketMessageHandler();
handler.setRSocketStrategies(rsocketStrategies()); handler.setRSocketStrategies(rsocketStrategies());
return handler; return handler;
} }
@Bean @Bean
public RSocketStrategies rsocketStrategies() { RSocketStrategies rsocketStrategies() {
return RSocketStrategies.builder().encoder(new BearerTokenAuthenticationEncoder()).build(); return RSocketStrategies.builder().encoder(new BearerTokenAuthenticationEncoder()).build();
} }

View File

@ -204,19 +204,19 @@ public class RSocketMessageHandlerConnectionITests {
static class Config { static class Config {
@Bean @Bean
public ServerController controller() { ServerController controller() {
return new ServerController(); return new ServerController();
} }
@Bean @Bean
public RSocketMessageHandler messageHandler() { RSocketMessageHandler messageHandler() {
RSocketMessageHandler handler = new RSocketMessageHandler(); RSocketMessageHandler handler = new RSocketMessageHandler();
handler.setRSocketStrategies(rsocketStrategies()); handler.setRSocketStrategies(rsocketStrategies());
return handler; return handler;
} }
@Bean @Bean
public RSocketStrategies rsocketStrategies() { RSocketStrategies rsocketStrategies() {
return RSocketStrategies.builder().encoder(new BasicAuthenticationEncoder()).build(); return RSocketStrategies.builder().encoder(new BasicAuthenticationEncoder()).build();
} }

View File

@ -186,19 +186,19 @@ public class RSocketMessageHandlerITests {
static class Config { static class Config {
@Bean @Bean
public ServerController controller() { ServerController controller() {
return new ServerController(); return new ServerController();
} }
@Bean @Bean
public RSocketMessageHandler messageHandler() { RSocketMessageHandler messageHandler() {
RSocketMessageHandler handler = new RSocketMessageHandler(); RSocketMessageHandler handler = new RSocketMessageHandler();
handler.setRSocketStrategies(rsocketStrategies()); handler.setRSocketStrategies(rsocketStrategies());
return handler; return handler;
} }
@Bean @Bean
public RSocketStrategies rsocketStrategies() { RSocketStrategies rsocketStrategies() {
return RSocketStrategies.builder().encoder(new BasicAuthenticationEncoder()).build(); return RSocketStrategies.builder().encoder(new BasicAuthenticationEncoder()).build();
} }

View File

@ -121,19 +121,19 @@ public class SimpleAuthenticationITests {
static class Config { static class Config {
@Bean @Bean
public ServerController controller() { ServerController controller() {
return new ServerController(); return new ServerController();
} }
@Bean @Bean
public RSocketMessageHandler messageHandler() { RSocketMessageHandler messageHandler() {
RSocketMessageHandler handler = new RSocketMessageHandler(); RSocketMessageHandler handler = new RSocketMessageHandler();
handler.setRSocketStrategies(rsocketStrategies()); handler.setRSocketStrategies(rsocketStrategies());
return handler; return handler;
} }
@Bean @Bean
public RSocketStrategies rsocketStrategies() { RSocketStrategies rsocketStrategies() {
return RSocketStrategies.builder().encoder(new SimpleAuthenticationEncoder()).build(); return RSocketStrategies.builder().encoder(new SimpleAuthenticationEncoder()).build();
} }

View File

@ -33,7 +33,7 @@ import org.springframework.security.crypto.password.PasswordEncoder;
* @author Rob Winch * @author Rob Winch
* @since 3.2 * @since 3.2
*/ */
abstract class AbstractDaoAuthenticationConfigurer<B extends ProviderManagerBuilder<B>, C extends AbstractDaoAuthenticationConfigurer<B, C, U>, U extends UserDetailsService> public abstract class AbstractDaoAuthenticationConfigurer<B extends ProviderManagerBuilder<B>, C extends AbstractDaoAuthenticationConfigurer<B, C, U>, U extends UserDetailsService>
extends UserDetailsAwareConfigurer<B, U> { extends UserDetailsAwareConfigurer<B, U> {
private DaoAuthenticationProvider provider = new DaoAuthenticationProvider(); private DaoAuthenticationProvider provider = new DaoAuthenticationProvider();
@ -44,7 +44,7 @@ abstract class AbstractDaoAuthenticationConfigurer<B extends ProviderManagerBuil
* Creates a new instance * Creates a new instance
* @param userDetailsService * @param userDetailsService
*/ */
protected AbstractDaoAuthenticationConfigurer(U userDetailsService) { AbstractDaoAuthenticationConfigurer(U userDetailsService) {
this.userDetailsService = userDetailsService; this.userDetailsService = userDetailsService;
this.provider.setUserDetailsService(userDetailsService); this.provider.setUserDetailsService(userDetailsService);
if (userDetailsService instanceof UserDetailsPasswordService) { if (userDetailsService instanceof UserDetailsPasswordService) {

View File

@ -28,7 +28,7 @@ class Jsr250MetadataSourceConfiguration {
@Bean @Bean
@Role(BeanDefinition.ROLE_INFRASTRUCTURE) @Role(BeanDefinition.ROLE_INFRASTRUCTURE)
public Jsr250MethodSecurityMetadataSource jsr250MethodSecurityMetadataSource() { Jsr250MethodSecurityMetadataSource jsr250MethodSecurityMetadataSource() {
return new Jsr250MethodSecurityMetadataSource(); return new Jsr250MethodSecurityMetadataSource();
} }

View File

@ -51,7 +51,7 @@ class ReactiveMethodSecurityConfiguration implements ImportAware {
@Bean @Bean
@Role(BeanDefinition.ROLE_INFRASTRUCTURE) @Role(BeanDefinition.ROLE_INFRASTRUCTURE)
public MethodSecurityMetadataSourceAdvisor methodSecurityInterceptor(AbstractMethodSecurityMetadataSource source) { MethodSecurityMetadataSourceAdvisor methodSecurityInterceptor(AbstractMethodSecurityMetadataSource source) {
MethodSecurityMetadataSourceAdvisor advisor = new MethodSecurityMetadataSourceAdvisor( MethodSecurityMetadataSourceAdvisor advisor = new MethodSecurityMetadataSourceAdvisor(
"securityMethodInterceptor", source, "methodMetadataSource"); "securityMethodInterceptor", source, "methodMetadataSource");
advisor.setOrder(this.advisorOrder); advisor.setOrder(this.advisorOrder);
@ -60,7 +60,7 @@ class ReactiveMethodSecurityConfiguration implements ImportAware {
@Bean @Bean
@Role(BeanDefinition.ROLE_INFRASTRUCTURE) @Role(BeanDefinition.ROLE_INFRASTRUCTURE)
public DelegatingMethodSecurityMetadataSource methodMetadataSource( DelegatingMethodSecurityMetadataSource methodMetadataSource(
MethodSecurityExpressionHandler methodSecurityExpressionHandler) { MethodSecurityExpressionHandler methodSecurityExpressionHandler) {
ExpressionBasedAnnotationAttributeFactory attributeFactory = new ExpressionBasedAnnotationAttributeFactory( ExpressionBasedAnnotationAttributeFactory attributeFactory = new ExpressionBasedAnnotationAttributeFactory(
methodSecurityExpressionHandler); methodSecurityExpressionHandler);
@ -70,7 +70,7 @@ class ReactiveMethodSecurityConfiguration implements ImportAware {
} }
@Bean @Bean
public PrePostAdviceReactiveMethodInterceptor securityMethodInterceptor(AbstractMethodSecurityMetadataSource source, PrePostAdviceReactiveMethodInterceptor securityMethodInterceptor(AbstractMethodSecurityMetadataSource source,
MethodSecurityExpressionHandler handler) { MethodSecurityExpressionHandler handler) {
ExpressionBasedPostInvocationAdvice postAdvice = new ExpressionBasedPostInvocationAdvice(handler); ExpressionBasedPostInvocationAdvice postAdvice = new ExpressionBasedPostInvocationAdvice(handler);
@ -82,7 +82,7 @@ class ReactiveMethodSecurityConfiguration implements ImportAware {
@Bean @Bean
@Role(BeanDefinition.ROLE_INFRASTRUCTURE) @Role(BeanDefinition.ROLE_INFRASTRUCTURE)
public DefaultMethodSecurityExpressionHandler methodSecurityExpressionHandler() { DefaultMethodSecurityExpressionHandler methodSecurityExpressionHandler() {
DefaultMethodSecurityExpressionHandler handler = new DefaultMethodSecurityExpressionHandler(); DefaultMethodSecurityExpressionHandler handler = new DefaultMethodSecurityExpressionHandler();
if (this.grantedAuthorityDefaults != null) { if (this.grantedAuthorityDefaults != null) {
handler.setDefaultRolePrefix(this.grantedAuthorityDefaults.getRolePrefix()); handler.setDefaultRolePrefix(this.grantedAuthorityDefaults.getRolePrefix());

View File

@ -60,7 +60,7 @@ class RSocketSecurityConfiguration {
@Bean(name = RSOCKET_SECURITY_BEAN_NAME) @Bean(name = RSOCKET_SECURITY_BEAN_NAME)
@Scope("prototype") @Scope("prototype")
public RSocketSecurity rsocketSecurity(ApplicationContext context) { RSocketSecurity rsocketSecurity(ApplicationContext context) {
RSocketSecurity security = new RSocketSecurity().authenticationManager(authenticationManager()); RSocketSecurity security = new RSocketSecurity().authenticationManager(authenticationManager());
security.setApplicationContext(context); security.setApplicationContext(context);
return security; return security;

View File

@ -235,6 +235,9 @@ public abstract class AbstractRequestMatcherRegistry<C> {
*/ */
private static final class RequestMatchers { private static final class RequestMatchers {
private RequestMatchers() {
}
/** /**
* Create a {@link List} of {@link AntPathRequestMatcher} instances. * Create a {@link List} of {@link AntPathRequestMatcher} instances.
* @param httpMethod the {@link HttpMethod} to use or {@code null} for any * @param httpMethod the {@link HttpMethod} to use or {@code null} for any
@ -243,7 +246,7 @@ public abstract class AbstractRequestMatcherRegistry<C> {
* from * from
* @return a {@link List} of {@link AntPathRequestMatcher} instances * @return a {@link List} of {@link AntPathRequestMatcher} instances
*/ */
public static List<RequestMatcher> antMatchers(HttpMethod httpMethod, String... antPatterns) { static List<RequestMatcher> antMatchers(HttpMethod httpMethod, String... antPatterns) {
String method = httpMethod == null ? null : httpMethod.toString(); String method = httpMethod == null ? null : httpMethod.toString();
List<RequestMatcher> matchers = new ArrayList<>(); List<RequestMatcher> matchers = new ArrayList<>();
for (String pattern : antPatterns) { for (String pattern : antPatterns) {
@ -259,7 +262,7 @@ public abstract class AbstractRequestMatcherRegistry<C> {
* from * from
* @return a {@link List} of {@link AntPathRequestMatcher} instances * @return a {@link List} of {@link AntPathRequestMatcher} instances
*/ */
public static List<RequestMatcher> antMatchers(String... antPatterns) { static List<RequestMatcher> antMatchers(String... antPatterns) {
return antMatchers(null, antPatterns); return antMatchers(null, antPatterns);
} }
@ -271,7 +274,7 @@ public abstract class AbstractRequestMatcherRegistry<C> {
* {@link RegexRequestMatcher} from * {@link RegexRequestMatcher} from
* @return a {@link List} of {@link RegexRequestMatcher} instances * @return a {@link List} of {@link RegexRequestMatcher} instances
*/ */
public static List<RequestMatcher> regexMatchers(HttpMethod httpMethod, String... regexPatterns) { static List<RequestMatcher> regexMatchers(HttpMethod httpMethod, String... regexPatterns) {
String method = httpMethod == null ? null : httpMethod.toString(); String method = httpMethod == null ? null : httpMethod.toString();
List<RequestMatcher> matchers = new ArrayList<>(); List<RequestMatcher> matchers = new ArrayList<>();
for (String pattern : regexPatterns) { for (String pattern : regexPatterns) {
@ -287,13 +290,10 @@ public abstract class AbstractRequestMatcherRegistry<C> {
* {@link RegexRequestMatcher} from * {@link RegexRequestMatcher} from
* @return a {@link List} of {@link RegexRequestMatcher} instances * @return a {@link List} of {@link RegexRequestMatcher} instances
*/ */
public static List<RequestMatcher> regexMatchers(String... regexPatterns) { static List<RequestMatcher> regexMatchers(String... regexPatterns) {
return regexMatchers(null, regexPatterns); return regexMatchers(null, regexPatterns);
} }
private RequestMatchers() {
}
} }
} }

View File

@ -125,7 +125,7 @@ final class FilterComparator implements Comparator<Filter>, Serializable {
* @param filter * @param filter
* @return * @return
*/ */
public boolean isRegistered(Class<? extends Filter> filter) { boolean isRegistered(Class<? extends Filter> filter) {
return getOrder(filter) != null; return getOrder(filter) != null;
} }
@ -136,7 +136,7 @@ final class FilterComparator implements Comparator<Filter>, Serializable {
* @param afterFilter the {@link Filter} that is already registered and that * @param afterFilter the {@link Filter} that is already registered and that
* {@code filter} should be placed after. * {@code filter} should be placed after.
*/ */
public void registerAfter(Class<? extends Filter> filter, Class<? extends Filter> afterFilter) { void registerAfter(Class<? extends Filter> filter, Class<? extends Filter> afterFilter) {
Integer position = getOrder(afterFilter); Integer position = getOrder(afterFilter);
if (position == null) { if (position == null) {
throw new IllegalArgumentException("Cannot register after unregistered Filter " + afterFilter); throw new IllegalArgumentException("Cannot register after unregistered Filter " + afterFilter);
@ -151,7 +151,7 @@ final class FilterComparator implements Comparator<Filter>, Serializable {
* @param atFilter the {@link Filter} that is already registered and that * @param atFilter the {@link Filter} that is already registered and that
* {@code filter} should be placed at. * {@code filter} should be placed at.
*/ */
public void registerAt(Class<? extends Filter> filter, Class<? extends Filter> atFilter) { void registerAt(Class<? extends Filter> filter, Class<? extends Filter> atFilter) {
Integer position = getOrder(atFilter); Integer position = getOrder(atFilter);
if (position == null) { if (position == null) {
throw new IllegalArgumentException("Cannot register after unregistered Filter " + atFilter); throw new IllegalArgumentException("Cannot register after unregistered Filter " + atFilter);
@ -167,7 +167,7 @@ final class FilterComparator implements Comparator<Filter>, Serializable {
* @param beforeFilter the {@link Filter} that is already registered and that * @param beforeFilter the {@link Filter} that is already registered and that
* {@code filter} should be placed before. * {@code filter} should be placed before.
*/ */
public void registerBefore(Class<? extends Filter> filter, Class<? extends Filter> beforeFilter) { void registerBefore(Class<? extends Filter> filter, Class<? extends Filter> beforeFilter) {
Integer position = getOrder(beforeFilter); Integer position = getOrder(beforeFilter);
if (position == null) { if (position == null) {
throw new IllegalArgumentException("Cannot register after unregistered Filter " + beforeFilter); throw new IllegalArgumentException("Cannot register after unregistered Filter " + beforeFilter);

View File

@ -35,9 +35,8 @@ import org.springframework.util.Assert;
* {@link ApplicationContext} but ignoring the parent. * {@link ApplicationContext} but ignoring the parent.
* *
* @author Rob Winch * @author Rob Winch
*
*/ */
final class AutowiredWebSecurityConfigurersIgnoreParents { public final class AutowiredWebSecurityConfigurersIgnoreParents {
private final ConfigurableListableBeanFactory beanFactory; private final ConfigurableListableBeanFactory beanFactory;

View File

@ -56,7 +56,7 @@ class HttpSecurityConfiguration {
private ApplicationContext context; private ApplicationContext context;
@Autowired @Autowired
public void setObjectPostProcessor(ObjectPostProcessor<Object> objectPostProcessor) { void setObjectPostProcessor(ObjectPostProcessor<Object> objectPostProcessor) {
this.objectPostProcessor = objectPostProcessor; this.objectPostProcessor = objectPostProcessor;
} }
@ -66,18 +66,18 @@ class HttpSecurityConfiguration {
} }
@Autowired @Autowired
public void setAuthenticationConfiguration(AuthenticationConfiguration authenticationConfiguration) { void setAuthenticationConfiguration(AuthenticationConfiguration authenticationConfiguration) {
this.authenticationConfiguration = authenticationConfiguration; this.authenticationConfiguration = authenticationConfiguration;
} }
@Autowired @Autowired
public void setApplicationContext(ApplicationContext context) { void setApplicationContext(ApplicationContext context) {
this.context = context; this.context = context;
} }
@Bean(HTTPSECURITY_BEAN_NAME) @Bean(HTTPSECURITY_BEAN_NAME)
@Scope("prototype") @Scope("prototype")
public HttpSecurity httpSecurity() throws Exception { HttpSecurity httpSecurity() throws Exception {
WebSecurityConfigurerAdapter.LazyPasswordEncoder passwordEncoder = new WebSecurityConfigurerAdapter.LazyPasswordEncoder( WebSecurityConfigurerAdapter.LazyPasswordEncoder passwordEncoder = new WebSecurityConfigurerAdapter.LazyPasswordEncoder(
this.context); this.context);

View File

@ -66,7 +66,7 @@ class WebMvcSecurityConfiguration implements WebMvcConfigurer, ApplicationContex
} }
@Bean @Bean
public RequestDataValueProcessor requestDataValueProcessor() { RequestDataValueProcessor requestDataValueProcessor() {
return new CsrfRequestDataValueProcessor(); return new CsrfRequestDataValueProcessor();
} }

View File

@ -122,20 +122,20 @@ public abstract class AbstractConfigAttributeRequestMatcherRegistry<C> extends A
*/ */
static final class UrlMapping { static final class UrlMapping {
private RequestMatcher requestMatcher; private final RequestMatcher requestMatcher;
private Collection<ConfigAttribute> configAttrs; private final Collection<ConfigAttribute> configAttrs;
UrlMapping(RequestMatcher requestMatcher, Collection<ConfigAttribute> configAttrs) { UrlMapping(RequestMatcher requestMatcher, Collection<ConfigAttribute> configAttrs) {
this.requestMatcher = requestMatcher; this.requestMatcher = requestMatcher;
this.configAttrs = configAttrs; this.configAttrs = configAttrs;
} }
public RequestMatcher getRequestMatcher() { RequestMatcher getRequestMatcher() {
return this.requestMatcher; return this.requestMatcher;
} }
public Collection<ConfigAttribute> getConfigAttrs() { Collection<ConfigAttribute> getConfigAttrs() {
return this.configAttrs; return this.configAttrs;
} }

View File

@ -61,13 +61,16 @@ import org.springframework.security.web.access.intercept.FilterSecurityIntercept
* @see ExpressionUrlAuthorizationConfigurer * @see ExpressionUrlAuthorizationConfigurer
* @see UrlAuthorizationConfigurer * @see UrlAuthorizationConfigurer
*/ */
abstract class AbstractInterceptUrlConfigurer<C extends AbstractInterceptUrlConfigurer<C, H>, H extends HttpSecurityBuilder<H>> public abstract class AbstractInterceptUrlConfigurer<C extends AbstractInterceptUrlConfigurer<C, H>, H extends HttpSecurityBuilder<H>>
extends AbstractHttpConfigurer<C, H> { extends AbstractHttpConfigurer<C, H> {
private Boolean filterSecurityInterceptorOncePerRequest; private Boolean filterSecurityInterceptorOncePerRequest;
private AccessDecisionManager accessDecisionManager; private AccessDecisionManager accessDecisionManager;
AbstractInterceptUrlConfigurer() {
}
@Override @Override
public void configure(H http) throws Exception { public void configure(H http) throws Exception {
FilterInvocationSecurityMetadataSource metadataSource = createMetadataSource(http); FilterInvocationSecurityMetadataSource metadataSource = createMetadataSource(http);
@ -145,9 +148,12 @@ abstract class AbstractInterceptUrlConfigurer<C extends AbstractInterceptUrlConf
return securityInterceptor; return securityInterceptor;
} }
abstract class AbstractInterceptUrlRegistry<R extends AbstractInterceptUrlRegistry<R, T>, T> public abstract class AbstractInterceptUrlRegistry<R extends AbstractInterceptUrlRegistry<R, T>, T>
extends AbstractConfigAttributeRequestMatcherRegistry<T> { extends AbstractConfigAttributeRequestMatcherRegistry<T> {
AbstractInterceptUrlRegistry() {
}
/** /**
* Allows setting the {@link AccessDecisionManager}. If none is provided, a * Allows setting the {@link AccessDecisionManager}. If none is provided, a
* default {@link AccessDecisionManager} is created. * default {@link AccessDecisionManager} is created.

View File

@ -338,7 +338,7 @@ public final class CsrfConfigurer<H extends HttpSecurityBuilder<H>>
return mvcMatchers(null, mvcPatterns); return mvcMatchers(null, mvcPatterns);
} }
public CsrfConfigurer<H> and() { CsrfConfigurer<H> and() {
return CsrfConfigurer.this; return CsrfConfigurer.this;
} }
@ -366,7 +366,7 @@ public final class CsrfConfigurer<H extends HttpSecurityBuilder<H>>
this.mvcMatchers = mvcMatchers; this.mvcMatchers = mvcMatchers;
} }
public IgnoreCsrfProtectionRegistry servletPath(String servletPath) { IgnoreCsrfProtectionRegistry servletPath(String servletPath) {
for (MvcRequestMatcher matcher : this.mvcMatchers) { for (MvcRequestMatcher matcher : this.mvcMatchers) {
matcher.setServletPath(servletPath); matcher.setServletPath(servletPath);
} }

View File

@ -31,7 +31,10 @@ import org.springframework.security.web.util.matcher.RequestMatcher;
*/ */
final class PermitAllSupport { final class PermitAllSupport {
public static void permitAll(HttpSecurityBuilder<? extends HttpSecurityBuilder<?>> http, String... urls) { private PermitAllSupport() {
}
static void permitAll(HttpSecurityBuilder<? extends HttpSecurityBuilder<?>> http, String... urls) {
for (String url : urls) { for (String url : urls) {
if (url != null) { if (url != null) {
permitAll(http, new ExactUrlRequestMatcher(url)); permitAll(http, new ExactUrlRequestMatcher(url));
@ -40,7 +43,7 @@ final class PermitAllSupport {
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public static void permitAll(HttpSecurityBuilder<? extends HttpSecurityBuilder<?>> http, static void permitAll(HttpSecurityBuilder<? extends HttpSecurityBuilder<?>> http,
RequestMatcher... requestMatchers) { RequestMatcher... requestMatchers) {
ExpressionUrlAuthorizationConfigurer<?> configurer = http ExpressionUrlAuthorizationConfigurer<?> configurer = http
.getConfigurer(ExpressionUrlAuthorizationConfigurer.class); .getConfigurer(ExpressionUrlAuthorizationConfigurer.class);
@ -90,7 +93,4 @@ final class PermitAllSupport {
} }
private PermitAllSupport() {
}
} }

View File

@ -511,7 +511,7 @@ public final class OAuth2ResourceServerConfigurer<H extends HttpSecurityBuilder<
} }
} }
public void setBearerTokenResolver(BearerTokenResolver tokenResolver) { void setBearerTokenResolver(BearerTokenResolver tokenResolver) {
Assert.notNull(tokenResolver, "resolver cannot be null"); Assert.notNull(tokenResolver, "resolver cannot be null");
this.bearerTokenResolver = tokenResolver; this.bearerTokenResolver = tokenResolver;
} }

View File

@ -78,17 +78,17 @@ final class ReactiveOAuth2ClientImportSelector implements ImportSelector {
} }
@Autowired(required = false) @Autowired(required = false)
public void setClientRegistrationRepository(ReactiveClientRegistrationRepository clientRegistrationRepository) { void setClientRegistrationRepository(ReactiveClientRegistrationRepository clientRegistrationRepository) {
this.clientRegistrationRepository = clientRegistrationRepository; this.clientRegistrationRepository = clientRegistrationRepository;
} }
@Autowired(required = false) @Autowired(required = false)
public void setAuthorizedClientRepository(ServerOAuth2AuthorizedClientRepository authorizedClientRepository) { void setAuthorizedClientRepository(ServerOAuth2AuthorizedClientRepository authorizedClientRepository) {
this.authorizedClientRepository = authorizedClientRepository; this.authorizedClientRepository = authorizedClientRepository;
} }
@Autowired(required = false) @Autowired(required = false)
public void setAuthorizedClientService(List<ReactiveOAuth2AuthorizedClientService> authorizedClientService) { void setAuthorizedClientService(List<ReactiveOAuth2AuthorizedClientService> authorizedClientService) {
if (authorizedClientService.size() == 1) { if (authorizedClientService.size() == 1) {
this.authorizedClientService = authorizedClientService.get(0); this.authorizedClientService = authorizedClientService.get(0);
} }

View File

@ -89,18 +89,20 @@ class ServerHttpSecurityConfiguration {
} }
@Bean @Bean
public WebFluxConfigurer authenticationPrincipalArgumentResolverConfigurer( WebFluxConfigurer authenticationPrincipalArgumentResolverConfigurer(
ObjectProvider<AuthenticationPrincipalArgumentResolver> authenticationPrincipalArgumentResolver) { ObjectProvider<AuthenticationPrincipalArgumentResolver> authenticationPrincipalArgumentResolver) {
return new WebFluxConfigurer() { return new WebFluxConfigurer() {
@Override @Override
public void configureArgumentResolvers(ArgumentResolverConfigurer configurer) { public void configureArgumentResolvers(ArgumentResolverConfigurer configurer) {
configurer.addCustomResolver(authenticationPrincipalArgumentResolver.getObject()); configurer.addCustomResolver(authenticationPrincipalArgumentResolver.getObject());
} }
}; };
} }
@Bean @Bean
public AuthenticationPrincipalArgumentResolver authenticationPrincipalArgumentResolver() { AuthenticationPrincipalArgumentResolver authenticationPrincipalArgumentResolver() {
AuthenticationPrincipalArgumentResolver resolver = new AuthenticationPrincipalArgumentResolver( AuthenticationPrincipalArgumentResolver resolver = new AuthenticationPrincipalArgumentResolver(
this.adapterRegistry); this.adapterRegistry);
if (this.beanFactory != null) { if (this.beanFactory != null) {
@ -110,7 +112,7 @@ class ServerHttpSecurityConfiguration {
} }
@Bean @Bean
public CurrentSecurityContextArgumentResolver reactiveCurrentSecurityContextArgumentResolver() { CurrentSecurityContextArgumentResolver reactiveCurrentSecurityContextArgumentResolver() {
CurrentSecurityContextArgumentResolver resolver = new CurrentSecurityContextArgumentResolver( CurrentSecurityContextArgumentResolver resolver = new CurrentSecurityContextArgumentResolver(
this.adapterRegistry); this.adapterRegistry);
if (this.beanFactory != null) { if (this.beanFactory != null) {
@ -121,7 +123,7 @@ class ServerHttpSecurityConfiguration {
@Bean(HTTPSECURITY_BEAN_NAME) @Bean(HTTPSECURITY_BEAN_NAME)
@Scope("prototype") @Scope("prototype")
public ServerHttpSecurity httpSecurity() { ServerHttpSecurity httpSecurity() {
ContextAwareServerHttpSecurity http = new ContextAwareServerHttpSecurity(); ContextAwareServerHttpSecurity http = new ContextAwareServerHttpSecurity();
return http.authenticationManager(authenticationManager()).headers().and().logout().and(); return http.authenticationManager(authenticationManager()).headers().and().logout().and();
} }

View File

@ -65,17 +65,17 @@ class WebFluxSecurityConfiguration {
@Bean(SPRING_SECURITY_WEBFILTERCHAINFILTER_BEAN_NAME) @Bean(SPRING_SECURITY_WEBFILTERCHAINFILTER_BEAN_NAME)
@Order(WEB_FILTER_CHAIN_FILTER_ORDER) @Order(WEB_FILTER_CHAIN_FILTER_ORDER)
public WebFilterChainProxy springSecurityWebFilterChainFilter() { WebFilterChainProxy springSecurityWebFilterChainFilter() {
return new WebFilterChainProxy(getSecurityWebFilterChains()); return new WebFilterChainProxy(getSecurityWebFilterChains());
} }
@Bean(name = AbstractView.REQUEST_DATA_VALUE_PROCESSOR_BEAN_NAME) @Bean(name = AbstractView.REQUEST_DATA_VALUE_PROCESSOR_BEAN_NAME)
public CsrfRequestDataValueProcessor requestDataValueProcessor() { CsrfRequestDataValueProcessor requestDataValueProcessor() {
return new CsrfRequestDataValueProcessor(); return new CsrfRequestDataValueProcessor();
} }
@Bean @Bean
public static BeanFactoryPostProcessor conversionServicePostProcessor() { static BeanFactoryPostProcessor conversionServicePostProcessor() {
return new RsaKeyConversionServicePostProcessor(); return new RsaKeyConversionServicePostProcessor();
} }

View File

@ -459,7 +459,7 @@ public class HttpSecurityBeanDefinitionParser implements BeanDefinitionParser {
* cannot determine if it should be on or off). * cannot determine if it should be on or off).
* @return * @return
*/ */
public boolean isEraseCredentialsAfterAuthentication() { boolean isEraseCredentialsAfterAuthentication() {
return false; return false;
} }

View File

@ -455,7 +455,7 @@ final class OAuth2LoginBeanDefinitionParser implements BeanDefinitionParser {
} }
@SuppressWarnings({ "unchecked", "unused" }) @SuppressWarnings({ "unchecked", "unused" })
public Map<String, String> getLoginLinks() { Map<String, String> getLoginLinks() {
Iterable<ClientRegistration> clientRegistrations = null; Iterable<ClientRegistration> clientRegistrations = null;
ClientRegistrationRepository clientRegistrationRepository = this.context ClientRegistrationRepository clientRegistrationRepository = this.context
.getBean(ClientRegistrationRepository.class); .getBean(ClientRegistrationRepository.class);

View File

@ -27,17 +27,18 @@ import org.springframework.util.StringUtils;
* @author Luke Taylor * @author Luke Taylor
* @author Ben Alex * @author Ben Alex
*/ */
abstract class WebConfigUtils { final class WebConfigUtils {
public static int countNonEmpty(String[] objects) { private WebConfigUtils() {
}
static int countNonEmpty(String[] objects) {
int nonNulls = 0; int nonNulls = 0;
for (String object : objects) { for (String object : objects) {
if (StringUtils.hasText(object)) { if (StringUtils.hasText(object)) {
nonNulls++; nonNulls++;
} }
} }
return nonNulls; return nonNulls;
} }

View File

@ -35,7 +35,7 @@ import org.springframework.util.ClassUtils;
* @author Luke Taylor * @author Luke Taylor
* @since 3.0 * @since 3.0
*/ */
class ContextSourceSettingPostProcessor implements BeanFactoryPostProcessor, Ordered { public class ContextSourceSettingPostProcessor implements BeanFactoryPostProcessor, Ordered {
private static final String REQUIRED_CONTEXT_SOURCE_CLASS_NAME = "org.springframework.ldap.core.support.BaseLdapPathContextSource"; private static final String REQUIRED_CONTEXT_SOURCE_CLASS_NAME = "org.springframework.ldap.core.support.BaseLdapPathContextSource";
@ -45,6 +45,9 @@ class ContextSourceSettingPostProcessor implements BeanFactoryPostProcessor, Ord
*/ */
private boolean defaultNameRequired; private boolean defaultNameRequired;
ContextSourceSettingPostProcessor() {
}
@Override @Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory bf) throws BeansException { public void postProcessBeanFactory(ConfigurableListableBeanFactory bf) throws BeansException {
Class<?> contextSourceClass; Class<?> contextSourceClass;

View File

@ -514,7 +514,7 @@ public class GlobalMethodSecurityBeanDefinitionParser implements BeanDefinitionP
private Jsr250MethodSecurityMetadataSource source = new Jsr250MethodSecurityMetadataSource(); private Jsr250MethodSecurityMetadataSource source = new Jsr250MethodSecurityMetadataSource();
public Jsr250MethodSecurityMetadataSource getBean() { Jsr250MethodSecurityMetadataSource getBean() {
this.source.setDefaultRolePrefix(this.rolePrefix); this.source.setDefaultRolePrefix(this.rolePrefix);
return this.source; return this.source;
} }
@ -525,7 +525,7 @@ public class GlobalMethodSecurityBeanDefinitionParser implements BeanDefinitionP
private DefaultMethodSecurityExpressionHandler handler = new DefaultMethodSecurityExpressionHandler(); private DefaultMethodSecurityExpressionHandler handler = new DefaultMethodSecurityExpressionHandler();
public DefaultMethodSecurityExpressionHandler getBean() { DefaultMethodSecurityExpressionHandler getBean() {
this.handler.setDefaultRolePrefix(this.rolePrefix); this.handler.setDefaultRolePrefix(this.rolePrefix);
return this.handler; return this.handler;
} }

View File

@ -28,7 +28,10 @@ import org.springframework.security.web.server.util.matcher.ServerWebExchangeMat
* @author Rob Winch * @author Rob Winch
* @since 5.0 * @since 5.0
*/ */
abstract class AbstractServerWebExchangeMatcherRegistry<T> { public abstract class AbstractServerWebExchangeMatcherRegistry<T> {
AbstractServerWebExchangeMatcherRegistry() {
}
/** /**
* Maps any request. * Maps any request.

View File

@ -32,7 +32,7 @@ class ConcereteSecurityConfigurerAdapter extends SecurityConfigurerAdapter<Objec
this.list = postProcess(this.list); this.list = postProcess(this.list);
} }
public ConcereteSecurityConfigurerAdapter list(List<Object> l) { ConcereteSecurityConfigurerAdapter list(List<Object> l) {
this.list = l; this.list = l;
return this; return this;
} }

View File

@ -47,7 +47,7 @@ public class ObjectPostProcessorTests {
static class PerformConversion { static class PerformConversion {
public static List<?> perform(ArrayList<?> l) { static List<?> perform(ArrayList<?> l) {
return new ListToLinkedListObjectPostProcessor().postProcess(l); return new ListToLinkedListObjectPostProcessor().postProcess(l);
} }

View File

@ -59,7 +59,7 @@ public class SecurityConfigurerAdapterClosureTests {
this.list = postProcess(this.list); this.list = postProcess(this.list);
} }
public ConcereteSecurityConfigurerAdapter list(List<Object> l) { ConcereteSecurityConfigurerAdapter list(List<Object> l) {
this.list = l; this.list = l;
return this; return this;
} }

View File

@ -235,19 +235,19 @@ public class AuthenticationManagerBuilderTests {
Resource users; Resource users;
@Bean @Bean
public AuthenticationManager authenticationManager() throws Exception { AuthenticationManager authenticationManager() throws Exception {
return new ProviderManager(Arrays.asList(authenticationProvider())); return new ProviderManager(Arrays.asList(authenticationProvider()));
} }
@Bean @Bean
public AuthenticationProvider authenticationProvider() throws Exception { AuthenticationProvider authenticationProvider() throws Exception {
DaoAuthenticationProvider provider = new DaoAuthenticationProvider(); DaoAuthenticationProvider provider = new DaoAuthenticationProvider();
provider.setUserDetailsService(userDetailsService()); provider.setUserDetailsService(userDetailsService());
return provider; return provider;
} }
@Bean @Bean
public UserDetailsService userDetailsService() throws Exception { UserDetailsService userDetailsService() throws Exception {
Properties properties = new Properties(); Properties properties = new Properties();
properties.load(this.users.getInputStream()); properties.load(this.users.getInputStream());
return new InMemoryUserDetailsManager(properties); return new InMemoryUserDetailsManager(properties);

View File

@ -81,7 +81,7 @@ public class NamespaceAuthenticationManagerTests {
static class EraseCredentialsTrueDefaultConfig extends WebSecurityConfigurerAdapter { static class EraseCredentialsTrueDefaultConfig extends WebSecurityConfigurerAdapter {
@Autowired @Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
// @formatter:off // @formatter:off
auth auth
.inMemoryAuthentication() .inMemoryAuthentication()
@ -110,7 +110,7 @@ public class NamespaceAuthenticationManagerTests {
static class GlobalEraseCredentialsFalseConfig extends WebSecurityConfigurerAdapter { static class GlobalEraseCredentialsFalseConfig extends WebSecurityConfigurerAdapter {
@Autowired @Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
// @formatter:off // @formatter:off
auth auth
.eraseCredentials(false) .eraseCredentials(false)

View File

@ -73,7 +73,7 @@ public class NamespaceAuthenticationProviderTests {
} }
@Bean @Bean
public DaoAuthenticationProvider authenticationProvider() { DaoAuthenticationProvider authenticationProvider() {
DaoAuthenticationProvider result = new DaoAuthenticationProvider(); DaoAuthenticationProvider result = new DaoAuthenticationProvider();
result.setUserDetailsService(new InMemoryUserDetailsManager(PasswordEncodedUser.user())); result.setUserDetailsService(new InMemoryUserDetailsManager(PasswordEncodedUser.user()));
return result; return result;

View File

@ -87,7 +87,7 @@ public class NamespaceJdbcUserServiceTests {
static class DataSourceConfig { static class DataSourceConfig {
@Bean @Bean
public DataSource dataSource() { DataSource dataSource() {
EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder(); EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder();
return builder.setType(EmbeddedDatabaseType.HSQL).build(); return builder.setType(EmbeddedDatabaseType.HSQL).build();
} }
@ -144,7 +144,7 @@ public class NamespaceJdbcUserServiceTests {
static class CustomDataSourceConfig { static class CustomDataSourceConfig {
@Bean @Bean
public DataSource dataSource() { DataSource dataSource() {
EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder() EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder()
// simulate that the DB already has the schema loaded and users in it // simulate that the DB already has the schema loaded and users in it
.addScript("CustomJdbcUserServiceSampleConfig.sql"); .addScript("CustomJdbcUserServiceSampleConfig.sql");

View File

@ -104,7 +104,7 @@ public class NamespacePasswordEncoderTests {
} }
@Bean @Bean
public DataSource dataSource() { DataSource dataSource() {
EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder(); EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder();
return builder.setType(EmbeddedDatabaseType.HSQL).build(); return builder.setType(EmbeddedDatabaseType.HSQL).build();
} }
@ -133,7 +133,7 @@ public class NamespacePasswordEncoderTests {
} }
@Bean @Bean
public DataSource dataSource() { DataSource dataSource() {
EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder(); EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder();
return builder.setType(EmbeddedDatabaseType.HSQL).build(); return builder.setType(EmbeddedDatabaseType.HSQL).build();
} }

View File

@ -74,7 +74,7 @@ public class PasswordEncoderConfigurerTests {
} }
@Bean @Bean
public BCryptPasswordEncoder passwordEncoder() { BCryptPasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder(); return new BCryptPasswordEncoder();
} }
@ -95,7 +95,7 @@ public class PasswordEncoderConfigurerTests {
} }
@Bean @Bean
public BCryptPasswordEncoder passwordEncoder() { BCryptPasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder(); return new BCryptPasswordEncoder();
} }

View File

@ -356,7 +356,7 @@ public class AuthenticationConfigurationTests {
AuthenticationManager authenticationManager = mock(AuthenticationManager.class); AuthenticationManager authenticationManager = mock(AuthenticationManager.class);
@Bean @Bean
public AuthenticationManager authenticationManager() { AuthenticationManager authenticationManager() {
return this.authenticationManager; return this.authenticationManager;
} }
@ -366,7 +366,7 @@ public class AuthenticationConfigurationTests {
static class ServicesConfig { static class ServicesConfig {
@Bean @Bean
public Service service() { Service service() {
return new ServiceImpl(); return new ServiceImpl();
} }
@ -466,12 +466,12 @@ public class AuthenticationConfigurationTests {
static class Sec2531Config { static class Sec2531Config {
@Bean @Bean
public ObjectPostProcessor objectPostProcessor() { ObjectPostProcessor objectPostProcessor() {
return mock(ObjectPostProcessor.class); return mock(ObjectPostProcessor.class);
} }
@Bean @Bean
public AuthenticationManager manager() { AuthenticationManager manager() {
return null; return null;
} }
@ -488,7 +488,7 @@ public class AuthenticationConfigurationTests {
static class Sec2822WebSecurity extends WebSecurityConfigurerAdapter { static class Sec2822WebSecurity extends WebSecurityConfigurerAdapter {
@Autowired @Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication(); auth.inMemoryAuthentication();
} }
@ -498,14 +498,14 @@ public class AuthenticationConfigurationTests {
static class Sec2822UseAuth { static class Sec2822UseAuth {
@Autowired @Autowired
public void useAuthenticationManager(AuthenticationConfiguration auth) throws Exception { void useAuthenticationManager(AuthenticationConfiguration auth) throws Exception {
auth.getAuthenticationManager(); auth.getAuthenticationManager();
} }
// Ensures that Sec2822UseAuth is initialized before Sec2822WebSecurity // Ensures that Sec2822UseAuth is initialized before Sec2822WebSecurity
// must have additional GlobalAuthenticationConfigurerAdapter to trigger SEC-2822 // must have additional GlobalAuthenticationConfigurerAdapter to trigger SEC-2822
@Bean @Bean
public static GlobalAuthenticationConfigurerAdapter bootGlobalAuthenticationConfigurerAdapter() { static GlobalAuthenticationConfigurerAdapter bootGlobalAuthenticationConfigurerAdapter() {
return new BootGlobalAuthenticationConfigurerAdapter(); return new BootGlobalAuthenticationConfigurerAdapter();
} }
@ -621,12 +621,12 @@ public class AuthenticationConfigurationTests {
@Bean @Bean
@Primary @Primary
public AuthenticationManager manager1() { AuthenticationManager manager1() {
return mock(AuthenticationManager.class); return mock(AuthenticationManager.class);
} }
@Bean @Bean
public AuthenticationManager manager2() { AuthenticationManager manager2() {
return mock(AuthenticationManager.class); return mock(AuthenticationManager.class);
} }

View File

@ -71,7 +71,7 @@ public class EnableGlobalAuthenticationTests {
static class Config { static class Config {
@Autowired @Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication().withUser("user").password("password").roles("USER"); auth.inMemoryAuthentication().withUser("user").password("password").roles("USER");
} }
@ -81,12 +81,12 @@ public class EnableGlobalAuthenticationTests {
static class BeanProxyEnabledByDefaultConfig { static class BeanProxyEnabledByDefaultConfig {
@Bean @Bean
public Child child() { Child child() {
return new Child(); return new Child();
} }
@Bean @Bean
public Parent parent() { Parent parent() {
return new Parent(child()); return new Parent(child());
} }
@ -97,12 +97,12 @@ public class EnableGlobalAuthenticationTests {
static class BeanProxyDisabledConfig { static class BeanProxyDisabledConfig {
@Bean @Bean
public Child child() { Child child() {
return new Child(); return new Child();
} }
@Bean @Bean
public Parent parent() { Parent parent() {
return new Parent(child()); return new Parent(child());
} }
@ -116,7 +116,7 @@ public class EnableGlobalAuthenticationTests {
this.child = child; this.child = child;
} }
public Child getChild() { Child getChild() {
return this.child; return this.child;
} }

View File

@ -150,7 +150,7 @@ public class AutowireBeanFactoryObjectPostProcessorTests {
static class Config { static class Config {
@Bean @Bean
public ObjectPostProcessor objectPostProcessor(AutowireCapableBeanFactory beanFactory) { ObjectPostProcessor objectPostProcessor(AutowireCapableBeanFactory beanFactory) {
return new AutowireBeanFactoryObjectPostProcessor(beanFactory); return new AutowireBeanFactoryObjectPostProcessor(beanFactory);
} }
@ -162,7 +162,7 @@ public class AutowireBeanFactoryObjectPostProcessorTests {
SmartInitializingSingleton toTest = mock(SmartInitializingSingleton.class); SmartInitializingSingleton toTest = mock(SmartInitializingSingleton.class);
@Autowired @Autowired
public void configure(ObjectPostProcessor<Object> p) { void configure(ObjectPostProcessor<Object> p) {
p.postProcess(this.toTest); p.postProcess(this.toTest);
} }
@ -172,12 +172,12 @@ public class AutowireBeanFactoryObjectPostProcessorTests {
static class WithBeanNameAutoProxyCreatorConfig { static class WithBeanNameAutoProxyCreatorConfig {
@Bean @Bean
public ObjectPostProcessor objectPostProcessor(AutowireCapableBeanFactory beanFactory) { ObjectPostProcessor objectPostProcessor(AutowireCapableBeanFactory beanFactory) {
return new AutowireBeanFactoryObjectPostProcessor(beanFactory); return new AutowireBeanFactoryObjectPostProcessor(beanFactory);
} }
@Autowired @Autowired
public void configure(ObjectPostProcessor<Object> p) { void configure(ObjectPostProcessor<Object> p) {
p.postProcess(new Object()); p.postProcess(new Object());
} }

View File

@ -470,12 +470,12 @@ public class EnableReactiveMethodSecurityTests {
ReactiveMessageService delegate = mock(ReactiveMessageService.class); ReactiveMessageService delegate = mock(ReactiveMessageService.class);
@Bean @Bean
public DelegatingReactiveMessageService defaultMessageService() { DelegatingReactiveMessageService defaultMessageService() {
return new DelegatingReactiveMessageService(this.delegate); return new DelegatingReactiveMessageService(this.delegate);
} }
@Bean @Bean
public Authz authz() { Authz authz() {
return new Authz(); return new Authz();
} }

View File

@ -340,12 +340,12 @@ public class GlobalMethodSecurityConfigurationTests {
static class CustomTrustResolverConfig { static class CustomTrustResolverConfig {
@Bean @Bean
public AuthenticationTrustResolver trustResolver() { AuthenticationTrustResolver trustResolver() {
return mock(AuthenticationTrustResolver.class); return mock(AuthenticationTrustResolver.class);
} }
@Bean @Bean
public MethodSecurityServiceImpl service() { MethodSecurityServiceImpl service() {
return new MethodSecurityServiceImpl(); return new MethodSecurityServiceImpl();
} }
@ -355,12 +355,12 @@ public class GlobalMethodSecurityConfigurationTests {
static class ExpressionHandlerHasBeanResolverSetConfig { static class ExpressionHandlerHasBeanResolverSetConfig {
@Bean @Bean
public MethodSecurityServiceImpl service() { MethodSecurityServiceImpl service() {
return new MethodSecurityServiceImpl(); return new MethodSecurityServiceImpl();
} }
@Bean @Bean
public Authz authz() { Authz authz() {
return new Authz(); return new Authz();
} }
@ -370,7 +370,7 @@ public class GlobalMethodSecurityConfigurationTests {
static class MethodSecurityServiceConfig { static class MethodSecurityServiceConfig {
@Bean @Bean
public MethodSecurityService service() { MethodSecurityService service() {
return new MethodSecurityServiceImpl(); return new MethodSecurityServiceImpl();
} }
@ -380,12 +380,12 @@ public class GlobalMethodSecurityConfigurationTests {
public static class AutowirePermissionEvaluatorConfig { public static class AutowirePermissionEvaluatorConfig {
@Bean @Bean
public PermissionEvaluator permissionEvaluator() { PermissionEvaluator permissionEvaluator() {
return mock(PermissionEvaluator.class); return mock(PermissionEvaluator.class);
} }
@Bean @Bean
public MethodSecurityService service() { MethodSecurityService service() {
return new MethodSecurityServiceImpl(); return new MethodSecurityServiceImpl();
} }
@ -395,12 +395,12 @@ public class GlobalMethodSecurityConfigurationTests {
public static class MultiPermissionEvaluatorConfig { public static class MultiPermissionEvaluatorConfig {
@Bean @Bean
public PermissionEvaluator permissionEvaluator() { PermissionEvaluator permissionEvaluator() {
return mock(PermissionEvaluator.class); return mock(PermissionEvaluator.class);
} }
@Bean @Bean
public PermissionEvaluator permissionEvaluator2() { PermissionEvaluator permissionEvaluator2() {
return mock(PermissionEvaluator.class); return mock(PermissionEvaluator.class);
} }
@ -415,7 +415,7 @@ public class GlobalMethodSecurityConfigurationTests {
static class ParentConfig { static class ParentConfig {
@Bean @Bean
public MethodSecurityService service() { MethodSecurityService service() {
return new MethodSecurityServiceImpl(); return new MethodSecurityServiceImpl();
} }
@ -425,7 +425,7 @@ public class GlobalMethodSecurityConfigurationTests {
static class Sec2479ParentConfig { static class Sec2479ParentConfig {
@Bean @Bean
public AuthenticationManager am() { AuthenticationManager am() {
return mock(AuthenticationManager.class); return mock(AuthenticationManager.class);
} }
@ -435,7 +435,7 @@ public class GlobalMethodSecurityConfigurationTests {
static class Sec2479ChildConfig { static class Sec2479ChildConfig {
@Bean @Bean
public MethodSecurityService service() { MethodSecurityService service() {
return new MethodSecurityServiceImpl(); return new MethodSecurityServiceImpl();
} }
@ -445,17 +445,17 @@ public class GlobalMethodSecurityConfigurationTests {
static class Sec2815Config { static class Sec2815Config {
@Bean @Bean
public MethodSecurityService service() { MethodSecurityService service() {
return new MethodSecurityServiceImpl(); return new MethodSecurityServiceImpl();
} }
@Bean @Bean
public MockBeanPostProcessor mockBeanPostProcessor() { MockBeanPostProcessor mockBeanPostProcessor() {
return new MockBeanPostProcessor(); return new MockBeanPostProcessor();
} }
@Bean @Bean
public DataSource dataSource() { DataSource dataSource() {
return mock(DataSource.class); return mock(DataSource.class);
} }
@ -499,12 +499,12 @@ public class GlobalMethodSecurityConfigurationTests {
static class Sec3005Config { static class Sec3005Config {
@Bean @Bean
public MethodSecurityService service() { MethodSecurityService service() {
return new MethodSecurityServiceImpl(); return new MethodSecurityServiceImpl();
} }
@Autowired @Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication(); auth.inMemoryAuthentication();
} }
@ -548,24 +548,24 @@ public class GlobalMethodSecurityConfigurationTests {
static class CustomGrantedAuthorityConfig { static class CustomGrantedAuthorityConfig {
@Bean @Bean
public GrantedAuthorityDefaults ga() { GrantedAuthorityDefaults ga() {
return new GrantedAuthorityDefaults("ROLE:"); return new GrantedAuthorityDefaults("ROLE:");
} }
@Bean @Bean
public CustomAuthorityService service() { CustomAuthorityService service() {
return new CustomAuthorityService(); return new CustomAuthorityService();
} }
@Bean @Bean
public MethodSecurityServiceImpl methodSecurityService() { MethodSecurityServiceImpl methodSecurityService() {
return new MethodSecurityServiceImpl(); return new MethodSecurityServiceImpl();
} }
static class CustomAuthorityService { static class CustomAuthorityService {
@PreAuthorize("hasRole('ROLE:USER')") @PreAuthorize("hasRole('ROLE:USER')")
public void customPrefixRoleUser() { void customPrefixRoleUser() {
} }
} }
@ -576,24 +576,24 @@ public class GlobalMethodSecurityConfigurationTests {
static class EmptyRolePrefixGrantedAuthorityConfig { static class EmptyRolePrefixGrantedAuthorityConfig {
@Bean @Bean
public GrantedAuthorityDefaults ga() { GrantedAuthorityDefaults ga() {
return new GrantedAuthorityDefaults(""); return new GrantedAuthorityDefaults("");
} }
@Bean @Bean
public CustomAuthorityService service() { CustomAuthorityService service() {
return new CustomAuthorityService(); return new CustomAuthorityService();
} }
@Bean @Bean
public MethodSecurityServiceImpl methodSecurityService() { MethodSecurityServiceImpl methodSecurityService() {
return new MethodSecurityServiceImpl(); return new MethodSecurityServiceImpl();
} }
static class CustomAuthorityService { static class CustomAuthorityService {
@Secured("USER") @Secured("USER")
public void emptyPrefixRoleUser() { void emptyPrefixRoleUser() {
} }
} }

View File

@ -109,7 +109,7 @@ public class ReactiveMethodSecurityConfigurationTests {
} }
private static class Foo { static class Foo {
public void bar(String param) { public void bar(String param) {
} }

View File

@ -81,7 +81,7 @@ public class SampleEnableGlobalMethodSecurityTests {
static class SampleWebSecurityConfig { static class SampleWebSecurityConfig {
@Bean @Bean
public MethodSecurityService methodSecurityService() { MethodSecurityService methodSecurityService() {
return new MethodSecurityServiceImpl(); return new MethodSecurityServiceImpl();
} }

View File

@ -99,7 +99,7 @@ public class Sec2758Tests {
} }
@Bean @Bean
public Service service() { Service service() {
return new Service(); return new Service();
} }
@ -112,7 +112,7 @@ public class Sec2758Tests {
static class RootController { static class RootController {
@GetMapping("/") @GetMapping("/")
public String ok() { String ok() {
return "ok"; return "ok";
} }
@ -123,11 +123,11 @@ public class Sec2758Tests {
static class Service { static class Service {
@PreAuthorize("hasRole('CUSTOM')") @PreAuthorize("hasRole('CUSTOM')")
public void doPreAuthorize() { void doPreAuthorize() {
} }
@RolesAllowed("CUSTOM") @RolesAllowed("CUSTOM")
public void doJsr250() { void doJsr250() {
} }
} }

View File

@ -284,7 +284,7 @@ public class WebSecurityConfigurerAdapterTests {
static class InMemoryConfigureGlobalConfig extends WebSecurityConfigurerAdapter { static class InMemoryConfigureGlobalConfig extends WebSecurityConfigurerAdapter {
@Autowired @Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
// @formatter:off // @formatter:off
auth auth
.inMemoryAuthentication() .inMemoryAuthentication()
@ -308,7 +308,7 @@ public class WebSecurityConfigurerAdapterTests {
private ContentNegotiationStrategy contentNegotiationStrategySharedObject; private ContentNegotiationStrategy contentNegotiationStrategySharedObject;
@Bean @Bean
public ContentNegotiationStrategy contentNegotiationStrategy() { ContentNegotiationStrategy contentNegotiationStrategy() {
return CONTENT_NEGOTIATION_STRATEGY_BEAN; return CONTENT_NEGOTIATION_STRATEGY_BEAN;
} }
@ -337,7 +337,7 @@ public class WebSecurityConfigurerAdapterTests {
static class RequiresUserDetailsServiceConfig { static class RequiresUserDetailsServiceConfig {
@Bean @Bean
public MyFilter myFilter(UserDetailsService userDetailsService) { MyFilter myFilter(UserDetailsService userDetailsService) {
return new MyFilter(userDetailsService); return new MyFilter(userDetailsService);
} }
@ -408,7 +408,7 @@ public class WebSecurityConfigurerAdapterTests {
private AuthenticationTrustResolver authenticationTrustResolverSharedObject; private AuthenticationTrustResolver authenticationTrustResolverSharedObject;
@Bean @Bean
public AuthenticationTrustResolver authenticationTrustResolver() { AuthenticationTrustResolver authenticationTrustResolver() {
return AUTHENTICATION_TRUST_RESOLVER_BEAN; return AUTHENTICATION_TRUST_RESOLVER_BEAN;
} }
@ -439,7 +439,7 @@ public class WebSecurityConfigurerAdapterTests {
} }
@Bean @Bean
public AuthenticationEventPublisher authenticationEventPublisher() { AuthenticationEventPublisher authenticationEventPublisher() {
return mock(AuthenticationEventPublisher.class); return mock(AuthenticationEventPublisher.class);
} }

View File

@ -613,7 +613,7 @@ public class NamespaceHttpTests {
static Class<? extends HttpServletRequest> HTTP_SERVLET_REQUEST_TYPE; static Class<? extends HttpServletRequest> HTTP_SERVLET_REQUEST_TYPE;
@GetMapping("/") @GetMapping("/")
public String index(HttpServletRequest request) { String index(HttpServletRequest request) {
HTTP_SERVLET_REQUEST_TYPE = request.getClass(); HTTP_SERVLET_REQUEST_TYPE = request.getClass();
return "index"; return "index";
} }

View File

@ -183,7 +183,7 @@ public class WebSecurityTests {
static class PathController { static class PathController {
@RequestMapping("/path") @RequestMapping("/path")
public String path() { String path() {
return "path"; return "path";
} }
@ -228,7 +228,7 @@ public class WebSecurityTests {
static class PathController { static class PathController {
@RequestMapping("/path") @RequestMapping("/path")
public String path() { String path() {
return "path"; return "path";
} }

View File

@ -192,12 +192,12 @@ public class EnableWebSecurityTests {
static class BeanProxyEnabledByDefaultConfig extends WebSecurityConfigurerAdapter { static class BeanProxyEnabledByDefaultConfig extends WebSecurityConfigurerAdapter {
@Bean @Bean
public Child child() { Child child() {
return new Child(); return new Child();
} }
@Bean @Bean
public Parent parent() { Parent parent() {
return new Parent(child()); return new Parent(child());
} }
@ -208,12 +208,12 @@ public class EnableWebSecurityTests {
static class BeanProxyDisabledConfig extends WebSecurityConfigurerAdapter { static class BeanProxyDisabledConfig extends WebSecurityConfigurerAdapter {
@Bean @Bean
public Child child() { Child child() {
return new Child(); return new Child();
} }
@Bean @Bean
public Parent parent() { Parent parent() {
return new Parent(child()); return new Parent(child());
} }
@ -227,7 +227,7 @@ public class EnableWebSecurityTests {
this.child = child; this.child = child;
} }
public Child getChild() { Child getChild() {
return this.child; return this.child;
} }

View File

@ -168,7 +168,7 @@ public class HttpSecurityConfigurationTests {
static class NameController { static class NameController {
@GetMapping("/name") @GetMapping("/name")
public Callable<String> name() { Callable<String> name() {
return () -> SecurityContextHolder.getContext().getAuthentication().getName(); return () -> SecurityContextHolder.getContext().getAuthentication().getName();
} }
@ -178,7 +178,7 @@ public class HttpSecurityConfigurationTests {
static class DefaultWithFilterChainConfig { static class DefaultWithFilterChainConfig {
@Bean @Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
return http.build(); return http.build();
} }
@ -188,7 +188,7 @@ public class HttpSecurityConfigurationTests {
static class AuthorizeRequestsConfig { static class AuthorizeRequestsConfig {
@Bean @Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
return http.authorizeRequests((authorize) -> authorize.anyRequest().permitAll()).build(); return http.authorizeRequests((authorize) -> authorize.anyRequest().permitAll()).build();
} }
@ -198,7 +198,7 @@ public class HttpSecurityConfigurationTests {
static class SecurityEnabledConfig { static class SecurityEnabledConfig {
@Bean @Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
return http.authorizeRequests((authorize) -> authorize.anyRequest().authenticated()) return http.authorizeRequests((authorize) -> authorize.anyRequest().authenticated())
.formLogin(withDefaults()).build(); .formLogin(withDefaults()).build();
} }
@ -209,7 +209,7 @@ public class HttpSecurityConfigurationTests {
static class UserDetailsConfig { static class UserDetailsConfig {
@Bean @Bean
public UserDetailsService userDetailsService() { UserDetailsService userDetailsService() {
UserDetails user = User.withDefaultPasswordEncoder().username("user").password("password").roles("USER") UserDetails user = User.withDefaultPasswordEncoder().username("user").password("password").roles("USER")
.build(); .build();
return new InMemoryUserDetailsManager(user); return new InMemoryUserDetailsManager(user);
@ -221,7 +221,7 @@ public class HttpSecurityConfigurationTests {
static class BaseController { static class BaseController {
@GetMapping("/") @GetMapping("/")
public void index() { void index() {
} }
} }
@ -230,7 +230,7 @@ public class HttpSecurityConfigurationTests {
static class UserController { static class UserController {
@GetMapping("/user") @GetMapping("/user")
public void user(HttpServletRequest request) { void user(HttpServletRequest request) {
if (!request.isUserInRole("USER")) { if (!request.isUserInRole("USER")) {
throw new AccessDeniedException("This resource is only available to users"); throw new AccessDeniedException("This resource is only available to users");
} }

View File

@ -217,25 +217,25 @@ public class OAuth2ClientConfigurationTests {
} }
@Bean @Bean
public ClientRegistrationRepository clientRegistrationRepository() { ClientRegistrationRepository clientRegistrationRepository() {
return CLIENT_REGISTRATION_REPOSITORY; return CLIENT_REGISTRATION_REPOSITORY;
} }
@Bean @Bean
public OAuth2AuthorizedClientRepository authorizedClientRepository() { OAuth2AuthorizedClientRepository authorizedClientRepository() {
return AUTHORIZED_CLIENT_REPOSITORY; return AUTHORIZED_CLIENT_REPOSITORY;
} }
@Bean @Bean
public OAuth2AccessTokenResponseClient<OAuth2ClientCredentialsGrantRequest> accessTokenResponseClient() { OAuth2AccessTokenResponseClient<OAuth2ClientCredentialsGrantRequest> accessTokenResponseClient() {
return ACCESS_TOKEN_RESPONSE_CLIENT; return ACCESS_TOKEN_RESPONSE_CLIENT;
} }
@RestController @RestController
public class Controller { class Controller {
@GetMapping("/authorized-client") @GetMapping("/authorized-client")
public String authorizedClient( String authorizedClient(
@RegisteredOAuth2AuthorizedClient("client1") OAuth2AuthorizedClient authorizedClient) { @RegisteredOAuth2AuthorizedClient("client1") OAuth2AuthorizedClient authorizedClient) {
return authorizedClient != null ? "resolved" : "not-resolved"; return authorizedClient != null ? "resolved" : "not-resolved";
} }
@ -260,22 +260,22 @@ public class OAuth2ClientConfigurationTests {
} }
@Bean @Bean
public ClientRegistrationRepository clientRegistrationRepository() { ClientRegistrationRepository clientRegistrationRepository() {
return mock(ClientRegistrationRepository.class); return mock(ClientRegistrationRepository.class);
} }
@Bean @Bean
public OAuth2AuthorizedClientRepository authorizedClientRepository1() { OAuth2AuthorizedClientRepository authorizedClientRepository1() {
return mock(OAuth2AuthorizedClientRepository.class); return mock(OAuth2AuthorizedClientRepository.class);
} }
@Bean @Bean
public OAuth2AuthorizedClientRepository authorizedClientRepository2() { OAuth2AuthorizedClientRepository authorizedClientRepository2() {
return mock(OAuth2AuthorizedClientRepository.class); return mock(OAuth2AuthorizedClientRepository.class);
} }
@Bean @Bean
public OAuth2AccessTokenResponseClient<OAuth2ClientCredentialsGrantRequest> accessTokenResponseClient() { OAuth2AccessTokenResponseClient<OAuth2ClientCredentialsGrantRequest> accessTokenResponseClient() {
return mock(OAuth2AccessTokenResponseClient.class); return mock(OAuth2AccessTokenResponseClient.class);
} }
@ -314,22 +314,22 @@ public class OAuth2ClientConfigurationTests {
} }
@Bean @Bean
public ClientRegistrationRepository clientRegistrationRepository1() { ClientRegistrationRepository clientRegistrationRepository1() {
return mock(ClientRegistrationRepository.class); return mock(ClientRegistrationRepository.class);
} }
@Bean @Bean
public ClientRegistrationRepository clientRegistrationRepository2() { ClientRegistrationRepository clientRegistrationRepository2() {
return mock(ClientRegistrationRepository.class); return mock(ClientRegistrationRepository.class);
} }
@Bean @Bean
public OAuth2AuthorizedClientRepository authorizedClientRepository() { OAuth2AuthorizedClientRepository authorizedClientRepository() {
return mock(OAuth2AuthorizedClientRepository.class); return mock(OAuth2AuthorizedClientRepository.class);
} }
@Bean @Bean
public OAuth2AccessTokenResponseClient<OAuth2ClientCredentialsGrantRequest> accessTokenResponseClient() { OAuth2AccessTokenResponseClient<OAuth2ClientCredentialsGrantRequest> accessTokenResponseClient() {
return mock(OAuth2AccessTokenResponseClient.class); return mock(OAuth2AccessTokenResponseClient.class);
} }
@ -351,22 +351,22 @@ public class OAuth2ClientConfigurationTests {
} }
@Bean @Bean
public ClientRegistrationRepository clientRegistrationRepository() { ClientRegistrationRepository clientRegistrationRepository() {
return mock(ClientRegistrationRepository.class); return mock(ClientRegistrationRepository.class);
} }
@Bean @Bean
public OAuth2AuthorizedClientRepository authorizedClientRepository() { OAuth2AuthorizedClientRepository authorizedClientRepository() {
return mock(OAuth2AuthorizedClientRepository.class); return mock(OAuth2AuthorizedClientRepository.class);
} }
@Bean @Bean
public OAuth2AccessTokenResponseClient<OAuth2ClientCredentialsGrantRequest> accessTokenResponseClient1() { OAuth2AccessTokenResponseClient<OAuth2ClientCredentialsGrantRequest> accessTokenResponseClient1() {
return mock(OAuth2AccessTokenResponseClient.class); return mock(OAuth2AccessTokenResponseClient.class);
} }
@Bean @Bean
public OAuth2AccessTokenResponseClient<OAuth2ClientCredentialsGrantRequest> accessTokenResponseClient2() { OAuth2AccessTokenResponseClient<OAuth2ClientCredentialsGrantRequest> accessTokenResponseClient2() {
return mock(OAuth2AccessTokenResponseClient.class); return mock(OAuth2AccessTokenResponseClient.class);
} }
@ -385,25 +385,25 @@ public class OAuth2ClientConfigurationTests {
} }
@Bean @Bean
public ClientRegistrationRepository clientRegistrationRepository() { ClientRegistrationRepository clientRegistrationRepository() {
return CLIENT_REGISTRATION_REPOSITORY; return CLIENT_REGISTRATION_REPOSITORY;
} }
@Bean @Bean
public OAuth2AuthorizedClientRepository authorizedClientRepository() { OAuth2AuthorizedClientRepository authorizedClientRepository() {
return AUTHORIZED_CLIENT_REPOSITORY; return AUTHORIZED_CLIENT_REPOSITORY;
} }
@Bean @Bean
public OAuth2AuthorizedClientManager authorizedClientManager() { OAuth2AuthorizedClientManager authorizedClientManager() {
return AUTHORIZED_CLIENT_MANAGER; return AUTHORIZED_CLIENT_MANAGER;
} }
@RestController @RestController
public class Controller { class Controller {
@GetMapping("/authorized-client") @GetMapping("/authorized-client")
public String authorizedClient( String authorizedClient(
@RegisteredOAuth2AuthorizedClient("client1") OAuth2AuthorizedClient authorizedClient) { @RegisteredOAuth2AuthorizedClient("client1") OAuth2AuthorizedClient authorizedClient) {
return authorizedClient != null ? "resolved" : "not-resolved"; return authorizedClient != null ? "resolved" : "not-resolved";
} }

View File

@ -121,7 +121,7 @@ public class SecurityReactorContextConfigurationResourceServerTests {
} }
@GetMapping("/token") @GetMapping("/token")
public String token() { String token() {
return this.rest.get().uri(this.uri).retrieve().bodyToMono(String.class) return this.rest.get().uri(this.uri).retrieve().bodyToMono(String.class)
.flatMap((result) -> this.rest.get().uri(this.uri).retrieve().bodyToMono(String.class)).block(); .flatMap((result) -> this.rest.get().uri(this.uri).retrieve().bodyToMono(String.class)).block();
} }

View File

@ -106,18 +106,18 @@ public class WebMvcSecurityConfigurationTests {
static class TestController { static class TestController {
@RequestMapping("/authentication-principal") @RequestMapping("/authentication-principal")
public ModelAndView authenticationPrincipal(@AuthenticationPrincipal String principal) { ModelAndView authenticationPrincipal(@AuthenticationPrincipal String principal) {
return new ModelAndView("authentication-principal-view", "result", principal); return new ModelAndView("authentication-principal-view", "result", principal);
} }
@RequestMapping("/deprecated-authentication-principal") @RequestMapping("/deprecated-authentication-principal")
public ModelAndView deprecatedAuthenticationPrincipal( ModelAndView deprecatedAuthenticationPrincipal(
@org.springframework.security.web.bind.annotation.AuthenticationPrincipal String principal) { @org.springframework.security.web.bind.annotation.AuthenticationPrincipal String principal) {
return new ModelAndView("deprecated-authentication-principal-view", "result", principal); return new ModelAndView("deprecated-authentication-principal-view", "result", principal);
} }
@RequestMapping("/csrf") @RequestMapping("/csrf")
public ModelAndView csrf(CsrfToken token) { ModelAndView csrf(CsrfToken token) {
return new ModelAndView("view", "result", token); return new ModelAndView("view", "result", token);
} }
@ -129,7 +129,7 @@ public class WebMvcSecurityConfigurationTests {
static class Config { static class Config {
@Bean @Bean
public TestController testController() { TestController testController() {
return new TestController(); return new TestController();
} }

View File

@ -516,7 +516,7 @@ public class WebSecurityConfigurationTests {
}; };
@Bean @Bean
public PermissionEvaluator permissionEvaluator() { PermissionEvaluator permissionEvaluator() {
return PERMIT_ALL_PERMISSION_EVALUATOR; return PERMIT_ALL_PERMISSION_EVALUATOR;
} }
@ -564,10 +564,10 @@ public class WebSecurityConfigurationTests {
} }
@RestController @RestController
public class HomeController { class HomeController {
@GetMapping("/") @GetMapping("/")
public String home() { String home() {
return "home"; return "home";
} }
@ -591,7 +591,7 @@ public class WebSecurityConfigurationTests {
static class ParentConfig extends WebSecurityConfigurerAdapter { static class ParentConfig extends WebSecurityConfigurerAdapter {
@Autowired @Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication(); auth.inMemoryAuthentication();
} }

View File

@ -480,7 +480,7 @@ public class AuthorizeRequestsTests {
} }
@Bean @Bean
public RoleHierarchy roleHiearchy() { RoleHierarchy roleHiearchy() {
RoleHierarchyImpl result = new RoleHierarchyImpl(); RoleHierarchyImpl result = new RoleHierarchyImpl();
result.setHierarchy("ROLE_USER > ROLE_ADMIN"); result.setHierarchy("ROLE_USER > ROLE_ADMIN");
return result; return result;
@ -515,7 +515,7 @@ public class AuthorizeRequestsTests {
static class PathController { static class PathController {
@RequestMapping("/path") @RequestMapping("/path")
public String path() { String path() {
return "path"; return "path";
} }
@ -552,7 +552,7 @@ public class AuthorizeRequestsTests {
static class PathController { static class PathController {
@RequestMapping("/path") @RequestMapping("/path")
public String path() { String path() {
return "path"; return "path";
} }
@ -587,7 +587,7 @@ public class AuthorizeRequestsTests {
static class PathController { static class PathController {
@RequestMapping("/path") @RequestMapping("/path")
public String path() { String path() {
return "path"; return "path";
} }
@ -624,7 +624,7 @@ public class AuthorizeRequestsTests {
static class PathController { static class PathController {
@RequestMapping("/path") @RequestMapping("/path")
public String path() { String path() {
return "path"; return "path";
} }
@ -659,7 +659,7 @@ public class AuthorizeRequestsTests {
static class PathController { static class PathController {
@RequestMapping("/path") @RequestMapping("/path")
public String path() { String path() {
return "path"; return "path";
} }
@ -696,7 +696,7 @@ public class AuthorizeRequestsTests {
static class PathController { static class PathController {
@RequestMapping("/path") @RequestMapping("/path")
public String path() { String path() {
return "path"; return "path";
} }
@ -731,7 +731,7 @@ public class AuthorizeRequestsTests {
static class PathController { static class PathController {
@RequestMapping("/path") @RequestMapping("/path")
public String path() { String path() {
return "path"; return "path";
} }

View File

@ -90,7 +90,7 @@ public class CsrfConfigurerNoWebMvcTests {
@Bean @Bean
@Primary @Primary
public RequestDataValueProcessor requestDataValueProcessor() { RequestDataValueProcessor requestDataValueProcessor() {
return mock(RequestDataValueProcessor.class); return mock(RequestDataValueProcessor.class);
} }

View File

@ -738,11 +738,11 @@ public class CsrfConfigurerTests {
static class BasicController { static class BasicController {
@GetMapping("/") @GetMapping("/")
public void rootGet() { void rootGet() {
} }
@PostMapping("/") @PostMapping("/")
public void rootPost() { void rootPost() {
} }
} }

View File

@ -139,7 +139,7 @@ public class DefaultFiltersTests {
static class FilterChainProxyBuilderMissingConfig { static class FilterChainProxyBuilderMissingConfig {
@Autowired @Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
// @formatter:off // @formatter:off
auth auth
.inMemoryAuthentication() .inMemoryAuthentication()
@ -153,7 +153,7 @@ public class DefaultFiltersTests {
static class UserDetailsServiceConfig { static class UserDetailsServiceConfig {
@Bean @Bean
public UserDetailsService userDetailsService() { UserDetailsService userDetailsService() {
return new InMemoryUserDetailsManager(PasswordEncodedUser.user(), PasswordEncodedUser.admin()); return new InMemoryUserDetailsManager(PasswordEncodedUser.user(), PasswordEncodedUser.admin());
} }

View File

@ -267,7 +267,7 @@ public class ExceptionHandlingConfigurerTests {
static class DefaultSecurityConfig { static class DefaultSecurityConfig {
@Bean @Bean
public InMemoryUserDetailsManager userDetailsManager() { InMemoryUserDetailsManager userDetailsManager() {
// @formatter:off // @formatter:off
return new InMemoryUserDetailsManager(User.withDefaultPasswordEncoder() return new InMemoryUserDetailsManager(User.withDefaultPasswordEncoder()
.username("user") .username("user")
@ -310,7 +310,7 @@ public class ExceptionHandlingConfigurerTests {
static ContentNegotiationStrategy CNS = mock(ContentNegotiationStrategy.class); static ContentNegotiationStrategy CNS = mock(ContentNegotiationStrategy.class);
@Bean @Bean
public static ContentNegotiationStrategy cns() { static ContentNegotiationStrategy cns() {
return CNS; return CNS;
} }

View File

@ -805,7 +805,7 @@ public class ExpressionUrlAuthorizationConfigurerTests {
} }
@Bean @Bean
public ApplicationListener<AuthorizedEvent> applicationListener() { ApplicationListener<AuthorizedEvent> applicationListener() {
return AL; return AL;
} }
@ -827,7 +827,7 @@ public class ExpressionUrlAuthorizationConfigurerTests {
} }
@Bean @Bean
public Checker permission() { Checker permission() {
return new Checker(); return new Checker();
} }
@ -858,7 +858,7 @@ public class ExpressionUrlAuthorizationConfigurerTests {
} }
@Bean @Bean
public CustomExpressionHandler expressionHandler() { CustomExpressionHandler expressionHandler() {
return new CustomExpressionHandler(); return new CustomExpressionHandler();
} }
@ -937,8 +937,9 @@ public class ExpressionUrlAuthorizationConfigurerTests {
} }
@Bean @Bean
public PermissionEvaluator permissionEvaluator() { PermissionEvaluator permissionEvaluator() {
return new PermissionEvaluator() { return new PermissionEvaluator() {
@Override @Override
public boolean hasPermission(Authentication authentication, Object targetDomainObject, public boolean hasPermission(Authentication authentication, Object targetDomainObject,
Object permission) { Object permission) {
@ -950,6 +951,7 @@ public class ExpressionUrlAuthorizationConfigurerTests {
Object permission) { Object permission) {
return "ID".equals(targetId) && "TYPE".equals(targetType) && "PERMISSION".equals(permission); return "ID".equals(targetId) && "TYPE".equals(targetType) && "PERMISSION".equals(permission);
} }
}; };
} }
@ -970,7 +972,7 @@ public class ExpressionUrlAuthorizationConfigurerTests {
} }
@Bean @Bean
public RoleHierarchy roleHierarchy() { RoleHierarchy roleHierarchy() {
RoleHierarchyImpl roleHierarchy = new RoleHierarchyImpl(); RoleHierarchyImpl roleHierarchy = new RoleHierarchyImpl();
roleHierarchy.setHierarchy("ROLE_USER > ROLE_MEMBER"); roleHierarchy.setHierarchy("ROLE_USER > ROLE_MEMBER");
return roleHierarchy; return roleHierarchy;
@ -982,11 +984,11 @@ public class ExpressionUrlAuthorizationConfigurerTests {
static class BasicController { static class BasicController {
@GetMapping("/") @GetMapping("/")
public void rootGet() { void rootGet() {
} }
@PostMapping("/") @PostMapping("/")
public void rootPost() { void rootPost() {
} }
} }
@ -995,7 +997,7 @@ public class ExpressionUrlAuthorizationConfigurerTests {
static class WildcardController { static class WildcardController {
@GetMapping("/{path}") @GetMapping("/{path}")
public void wildcard(@PathVariable String path) { void wildcard(@PathVariable String path) {
} }
} }

View File

@ -247,7 +247,7 @@ public class HttpSecurityRequestMatchersTests {
static class PathController { static class PathController {
@RequestMapping("/path") @RequestMapping("/path")
public String path() { String path() {
return "path"; return "path";
} }
@ -285,7 +285,7 @@ public class HttpSecurityRequestMatchersTests {
static class PathController { static class PathController {
@RequestMapping("/path") @RequestMapping("/path")
public String path() { String path() {
return "path"; return "path";
} }
@ -318,7 +318,7 @@ public class HttpSecurityRequestMatchersTests {
static class PathController { static class PathController {
@RequestMapping("/path") @RequestMapping("/path")
public String path() { String path() {
return "path"; return "path";
} }
@ -357,7 +357,7 @@ public class HttpSecurityRequestMatchersTests {
static class PathController { static class PathController {
@RequestMapping("/path") @RequestMapping("/path")
public String path() { String path() {
return "path"; return "path";
} }
@ -391,7 +391,7 @@ public class HttpSecurityRequestMatchersTests {
static class PathController { static class PathController {
@RequestMapping("/path") @RequestMapping("/path")
public String path() { String path() {
return "path"; return "path";
} }

View File

@ -162,7 +162,7 @@ public class NamespaceHttpBasicTests {
static class UserConfig { static class UserConfig {
@Bean @Bean
public UserDetailsService userDetailsService() { UserDetailsService userDetailsService() {
return new InMemoryUserDetailsManager( return new InMemoryUserDetailsManager(
// @formatter:off // @formatter:off
User.withDefaultPasswordEncoder() User.withDefaultPasswordEncoder()

View File

@ -192,15 +192,9 @@ public class NamespaceHttpCustomFilterTests {
static class UserDetailsServiceConfig { static class UserDetailsServiceConfig {
@Bean @Bean
public UserDetailsService userDetailsService() { UserDetailsService userDetailsService() {
return new InMemoryUserDetailsManager( return new InMemoryUserDetailsManager(
// @formatter:off User.withDefaultPasswordEncoder().username("user").password("password").roles("USER").build());
User.withDefaultPasswordEncoder()
.username("user")
.password("password")
.roles("USER")
.build());
// @formatter:on
} }
} }

View File

@ -178,7 +178,7 @@ public class NamespaceHttpFormLoginTests {
static class UserDetailsServiceConfig { static class UserDetailsServiceConfig {
@Bean @Bean
public UserDetailsService userDetailsService() { UserDetailsService userDetailsService() {
return new InMemoryUserDetailsManager( return new InMemoryUserDetailsManager(
// @formatter:off // @formatter:off
User.withDefaultPasswordEncoder() User.withDefaultPasswordEncoder()

View File

@ -152,27 +152,27 @@ public class NamespaceHttpInterceptUrlTests {
static class BaseController { static class BaseController {
@GetMapping("/users") @GetMapping("/users")
public String users() { String users() {
return "ok"; return "ok";
} }
@GetMapping("/sessions") @GetMapping("/sessions")
public String sessions() { String sessions() {
return "sessions"; return "sessions";
} }
@RequestMapping("/admin/post") @RequestMapping("/admin/post")
public String adminPost() { String adminPost() {
return "adminPost"; return "adminPost";
} }
@GetMapping("/admin/another-post") @GetMapping("/admin/another-post")
public String adminAnotherPost() { String adminAnotherPost() {
return "adminAnotherPost"; return "adminAnotherPost";
} }
@GetMapping("/signup") @GetMapping("/signup")
public String signup() { String signup() {
return "signup"; return "signup";
} }

View File

@ -147,12 +147,12 @@ public class NamespaceHttpJeeTests {
static class BaseController { static class BaseController {
@GetMapping("/authenticated") @GetMapping("/authenticated")
public String authenticated(Authentication authentication) { String authenticated(Authentication authentication) {
return authentication.getName(); return authentication.getName();
} }
@GetMapping("/roles") @GetMapping("/roles")
public String roles(Authentication authentication) { String roles(Authentication authentication) {
return authentication.getAuthorities().stream().map(Object::toString).collect(Collectors.joining(",")); return authentication.getAuthorities().stream().map(Object::toString).collect(Collectors.joining(","));
} }

View File

@ -293,15 +293,9 @@ public class NamespaceHttpOpenIDLoginTests {
static class UserDetailsServiceConfig { static class UserDetailsServiceConfig {
@Bean @Bean
public UserDetailsService userDetailsService() { UserDetailsService userDetailsService() {
return new InMemoryUserDetailsManager( return new InMemoryUserDetailsManager(
// @formatter:off User.withDefaultPasswordEncoder().username("user").password("password").roles("USER").build());
User.withDefaultPasswordEncoder()
.username("user")
.password("password")
.roles("USER")
.build());
// @formatter:on
} }
} }

View File

@ -106,7 +106,7 @@ public class NamespaceHttpRequestCacheTests {
} }
@Bean @Bean
public RequestCache requestCache() { RequestCache requestCache() {
return mock(RequestCache.class); return mock(RequestCache.class);
} }

View File

@ -371,7 +371,7 @@ public class NamespaceSessionManagementTests {
} }
@Bean @Bean
public MockEventListener eventListener() { MockEventListener eventListener() {
return spy(new MockEventListener()); return spy(new MockEventListener());
} }
@ -425,12 +425,12 @@ public class NamespaceSessionManagementTests {
static class BasicController { static class BasicController {
@GetMapping("/") @GetMapping("/")
public String ok() { String ok() {
return "ok"; return "ok";
} }
@GetMapping("/auth") @GetMapping("/auth")
public String auth(Principal principal) { String auth(Principal principal) {
return principal.getName(); return principal.getName();
} }
@ -444,17 +444,17 @@ public class NamespaceSessionManagementTests {
private Boolean exists = true; private Boolean exists = true;
public ResultMatcher exists(boolean exists) { ResultMatcher exists(boolean exists) {
this.exists = exists; this.exists = exists;
return this; return this;
} }
public ResultMatcher valid(boolean valid) { ResultMatcher valid(boolean valid) {
this.valid = valid; this.valid = valid;
return this.exists(true); return this.exists(true);
} }
public ResultMatcher id(String id) { ResultMatcher id(String id) {
this.id = id; this.id = id;
return this.exists(true); return this.exists(true);
} }

View File

@ -317,7 +317,7 @@ public class RememberMeConfigurerTests {
} }
@Autowired @Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
// @formatter:off // @formatter:off
auth auth
.inMemoryAuthentication() .inMemoryAuthentication()
@ -344,7 +344,7 @@ public class RememberMeConfigurerTests {
} }
@Autowired @Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
// @formatter:off // @formatter:off
auth auth
.inMemoryAuthentication() .inMemoryAuthentication()
@ -372,7 +372,7 @@ public class RememberMeConfigurerTests {
} }
@Autowired @Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
// @formatter:off // @formatter:off
auth auth
.inMemoryAuthentication() .inMemoryAuthentication()
@ -402,7 +402,7 @@ public class RememberMeConfigurerTests {
} }
@Autowired @Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
// @formatter:off // @formatter:off
auth auth
.inMemoryAuthentication() .inMemoryAuthentication()
@ -434,7 +434,7 @@ public class RememberMeConfigurerTests {
} }
@Autowired @Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
// @formatter:off // @formatter:off
auth auth
.inMemoryAuthentication() .inMemoryAuthentication()

View File

@ -387,7 +387,7 @@ public class RequestCacheConfigurerTests {
static class DefaultSecurityConfig { static class DefaultSecurityConfig {
@Bean @Bean
public InMemoryUserDetailsManager userDetailsManager() { InMemoryUserDetailsManager userDetailsManager() {
// @formatter:off // @formatter:off
return new InMemoryUserDetailsManager(User.withDefaultPasswordEncoder() return new InMemoryUserDetailsManager(User.withDefaultPasswordEncoder()
.username("user") .username("user")

View File

@ -256,7 +256,7 @@ public class ServletApiConfigurerTests {
} }
@Bean @Bean
public AuthenticationManager customAuthenticationManager() throws Exception { AuthenticationManager customAuthenticationManager() throws Exception {
return super.authenticationManagerBean(); return super.authenticationManagerBean();
} }
@ -356,7 +356,7 @@ public class ServletApiConfigurerTests {
static class AdminController { static class AdminController {
@GetMapping("/admin") @GetMapping("/admin")
public void admin(HttpServletRequest request) { void admin(HttpServletRequest request) {
if (!request.isUserInRole("ADMIN")) { if (!request.isUserInRole("ADMIN")) {
throw new AccessDeniedException("This resource is only available to admins"); throw new AccessDeniedException("This resource is only available to admins");
} }

View File

@ -111,7 +111,7 @@ public class SessionManagementConfigurerSessionCreationPolicyTests {
static class BasicController { static class BasicController {
@GetMapping("/") @GetMapping("/")
public String root() { String root() {
return "ok"; return "ok";
} }

View File

@ -515,7 +515,7 @@ public class SessionManagementConfigurerTests {
} }
@Bean @Bean
public SessionRegistry sessionRegistry() { SessionRegistry sessionRegistry() {
return SESSION_REGISTRY; return SESSION_REGISTRY;
} }
@ -538,12 +538,12 @@ public class SessionManagementConfigurerTests {
} }
@Bean @Bean
public SessionRegistry sessionRegistryOne() { SessionRegistry sessionRegistryOne() {
return SESSION_REGISTRY_ONE; return SESSION_REGISTRY_ONE;
} }
@Bean @Bean
public SessionRegistry sessionRegistryTwo() { SessionRegistry sessionRegistryTwo() {
return SESSION_REGISTRY_TWO; return SESSION_REGISTRY_TWO;
} }

View File

@ -183,7 +183,7 @@ public class UrlAuthorizationConfigurerTests {
static class PathController { static class PathController {
@RequestMapping("/path") @RequestMapping("/path")
public String path() { String path() {
return "path"; return "path";
} }
@ -218,7 +218,7 @@ public class UrlAuthorizationConfigurerTests {
static class PathController { static class PathController {
@RequestMapping("/path") @RequestMapping("/path")
public String path() { String path() {
return "path"; return "path";
} }

View File

@ -265,20 +265,20 @@ public class OAuth2ClientConfigurerTests {
} }
@Bean @Bean
public ClientRegistrationRepository clientRegistrationRepository() { ClientRegistrationRepository clientRegistrationRepository() {
return clientRegistrationRepository; return clientRegistrationRepository;
} }
@Bean @Bean
public OAuth2AuthorizedClientRepository authorizedClientRepository() { OAuth2AuthorizedClientRepository authorizedClientRepository() {
return authorizedClientRepository; return authorizedClientRepository;
} }
@RestController @RestController
public class ResourceController { class ResourceController {
@GetMapping("/resource1") @GetMapping("/resource1")
public String resource1( String resource1(
@RegisteredOAuth2AuthorizedClient("registration-1") OAuth2AuthorizedClient authorizedClient) { @RegisteredOAuth2AuthorizedClient("registration-1") OAuth2AuthorizedClient authorizedClient) {
return "resource1"; return "resource1";
} }
@ -304,12 +304,12 @@ public class OAuth2ClientConfigurerTests {
} }
@Bean @Bean
public ClientRegistrationRepository clientRegistrationRepository() { ClientRegistrationRepository clientRegistrationRepository() {
return clientRegistrationRepository; return clientRegistrationRepository;
} }
@Bean @Bean
public OAuth2AuthorizedClientRepository authorizedClientRepository() { OAuth2AuthorizedClientRepository authorizedClientRepository() {
return authorizedClientRepository; return authorizedClientRepository;
} }

View File

@ -1907,7 +1907,7 @@ public class OAuth2ResourceServerConfigurerTests {
} }
@Bean @Bean
public JwtDecoder decoder() { JwtDecoder decoder() {
return mock(JwtDecoder.class); return mock(JwtDecoder.class);
} }
@ -1930,7 +1930,7 @@ public class OAuth2ResourceServerConfigurerTests {
} }
@Bean @Bean
public AuthenticationProvider authenticationProvider() { AuthenticationProvider authenticationProvider() {
return mock(AuthenticationProvider.class); return mock(AuthenticationProvider.class);
} }
@ -1955,7 +1955,7 @@ public class OAuth2ResourceServerConfigurerTests {
// @formatter:on // @formatter:on
} }
public OAuth2TokenValidator<Jwt> getJwtValidator() { OAuth2TokenValidator<Jwt> getJwtValidator() {
return this.jwtValidator; return this.jwtValidator;
} }
@ -2122,7 +2122,7 @@ public class OAuth2ResourceServerConfigurerTests {
} }
@Bean @Bean
public AuthenticationProvider authenticationProvider() { AuthenticationProvider authenticationProvider() {
return mock(AuthenticationProvider.class); return mock(AuthenticationProvider.class);
} }
@ -2150,7 +2150,7 @@ public class OAuth2ResourceServerConfigurerTests {
} }
@Bean @Bean
public AuthenticationProvider authenticationProvider() { AuthenticationProvider authenticationProvider() {
return mock(AuthenticationProvider.class); return mock(AuthenticationProvider.class);
} }
@ -2234,7 +2234,7 @@ public class OAuth2ResourceServerConfigurerTests {
static class JwtDecoderConfig { static class JwtDecoderConfig {
@Bean @Bean
public JwtDecoder jwtDecoder() { JwtDecoder jwtDecoder() {
return mock(JwtDecoder.class); return mock(JwtDecoder.class);
} }
@ -2244,35 +2244,35 @@ public class OAuth2ResourceServerConfigurerTests {
static class BasicController { static class BasicController {
@GetMapping("/") @GetMapping("/")
public String get() { String get() {
return "ok"; return "ok";
} }
@PostMapping("/post") @PostMapping("/post")
public String post() { String post() {
return "post"; return "post";
} }
@RequestMapping(value = "/authenticated", method = { RequestMethod.GET, RequestMethod.POST }) @RequestMapping(value = "/authenticated", method = { RequestMethod.GET, RequestMethod.POST })
public String authenticated(Authentication authentication) { String authenticated(Authentication authentication) {
return authentication.getName(); return authentication.getName();
} }
@GetMapping("/requires-read-scope") @GetMapping("/requires-read-scope")
public String requiresReadScope(JwtAuthenticationToken token) { String requiresReadScope(JwtAuthenticationToken token) {
return token.getAuthorities().stream().map(GrantedAuthority::getAuthority).collect(Collectors.toList()) return token.getAuthorities().stream().map(GrantedAuthority::getAuthority).collect(Collectors.toList())
.toString(); .toString();
} }
@GetMapping("/ms-requires-read-scope") @GetMapping("/ms-requires-read-scope")
@PreAuthorize("hasAuthority('SCOPE_message:read')") @PreAuthorize("hasAuthority('SCOPE_message:read')")
public String msRequiresReadScope(JwtAuthenticationToken token) { String msRequiresReadScope(JwtAuthenticationToken token) {
return requiresReadScope(token); return requiresReadScope(token);
} }
@GetMapping("/ms-deny") @GetMapping("/ms-deny")
@PreAuthorize("denyAll") @PreAuthorize("denyAll")
public String deny() { String deny() {
return "hmm, that's odd"; return "hmm, that's odd";
} }
@ -2284,7 +2284,7 @@ public class OAuth2ResourceServerConfigurerTests {
private final MockWebServer server = new MockWebServer(); private final MockWebServer server = new MockWebServer();
@PreDestroy @PreDestroy
public void shutdown() throws IOException { void shutdown() throws IOException {
this.server.shutdown(); this.server.shutdown();
} }
@ -2297,7 +2297,7 @@ public class OAuth2ResourceServerConfigurerTests {
} }
@Bean @Bean
public MockWebServer web() { MockWebServer web() {
return this.server; return this.server;
} }
@ -2354,7 +2354,7 @@ public class OAuth2ResourceServerConfigurerTests {
this.token = token; this.token = token;
} }
public BearerTokenRequestPostProcessor asParam() { BearerTokenRequestPostProcessor asParam() {
this.asRequestParameter = true; this.asRequestParameter = true;
return this; return this;
} }

View File

@ -270,13 +270,13 @@ public class EnableWebFluxSecurityTests {
static class CustomPasswordEncoderConfig { static class CustomPasswordEncoderConfig {
@Bean @Bean
public ReactiveUserDetailsService userDetailsService(PasswordEncoder encoder) { ReactiveUserDetailsService userDetailsService(PasswordEncoder encoder) {
return new MapReactiveUserDetailsService( return new MapReactiveUserDetailsService(
User.withUsername("user").password(encoder.encode("password")).roles("USER").build()); User.withUsername("user").password(encoder.encode("password")).roles("USER").build());
} }
@Bean @Bean
public static PasswordEncoder passwordEncoder() { static PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder(); return new BCryptPasswordEncoder();
} }
@ -286,7 +286,7 @@ public class EnableWebFluxSecurityTests {
static class MapReactiveUserDetailsServiceConfig { static class MapReactiveUserDetailsServiceConfig {
@Bean @Bean
public MapReactiveUserDetailsService userDetailsService() { MapReactiveUserDetailsService userDetailsService() {
// @formatter:off // @formatter:off
return new MapReactiveUserDetailsService(User.withUsername("user") return new MapReactiveUserDetailsService(User.withUsername("user")
.password("{noop}password") .password("{noop}password")
@ -304,14 +304,14 @@ public class EnableWebFluxSecurityTests {
@Order(Ordered.HIGHEST_PRECEDENCE) @Order(Ordered.HIGHEST_PRECEDENCE)
@Bean @Bean
public SecurityWebFilterChain apiHttpSecurity(ServerHttpSecurity http) { SecurityWebFilterChain apiHttpSecurity(ServerHttpSecurity http) {
http.securityMatcher(new PathPatternParserServerWebExchangeMatcher("/api/**")).authorizeExchange() http.securityMatcher(new PathPatternParserServerWebExchangeMatcher("/api/**")).authorizeExchange()
.anyExchange().denyAll(); .anyExchange().denyAll();
return http.build(); return http.build();
} }
@Bean @Bean
public SecurityWebFilterChain httpSecurity(ServerHttpSecurity http) { SecurityWebFilterChain httpSecurity(ServerHttpSecurity http) {
return http.build(); return http.build();
} }
@ -323,7 +323,7 @@ public class EnableWebFluxSecurityTests {
static class AuthenticationPrincipalConfig { static class AuthenticationPrincipalConfig {
@Bean @Bean
public PrincipalBean principalBean() { PrincipalBean principalBean() {
return new PrincipalBean(); return new PrincipalBean();
} }
@ -336,7 +336,7 @@ public class EnableWebFluxSecurityTests {
} }
@RestController @RestController
public static class AuthenticationPrincipalResolver { static class AuthenticationPrincipalResolver {
@GetMapping("/spel") @GetMapping("/spel")
String username(@AuthenticationPrincipal(expression = "@principalBean.username(#this)") String username) { String username(@AuthenticationPrincipal(expression = "@principalBean.username(#this)") String username) {
@ -352,12 +352,12 @@ public class EnableWebFluxSecurityTests {
static class BeanProxyEnabledByDefaultConfig { static class BeanProxyEnabledByDefaultConfig {
@Bean @Bean
public Child child() { Child child() {
return new Child(); return new Child();
} }
@Bean @Bean
public Parent parent() { Parent parent() {
return new Parent(child()); return new Parent(child());
} }
@ -369,12 +369,12 @@ public class EnableWebFluxSecurityTests {
static class BeanProxyDisabledConfig { static class BeanProxyDisabledConfig {
@Bean @Bean
public Child child() { Child child() {
return new Child(); return new Child();
} }
@Bean @Bean
public Parent parent() { Parent parent() {
return new Parent(child()); return new Parent(child());
} }
@ -388,7 +388,7 @@ public class EnableWebFluxSecurityTests {
this.child = child; this.child = child;
} }
public Child getChild() { Child getChild() {
return this.child; return this.child;
} }

View File

@ -120,7 +120,7 @@ public class AbstractSecurityWebSocketMessageBrokerConfigurerDocTests {
static class MyController { static class MyController {
@MessageMapping("/authentication") @MessageMapping("/authentication")
public void authentication(@AuthenticationPrincipal String un) { void authentication(@AuthenticationPrincipal String un) {
// ... do something ... // ... do something ...
} }
@ -161,7 +161,7 @@ public class AbstractSecurityWebSocketMessageBrokerConfigurerDocTests {
} }
@Bean @Bean
public MyController myController() { MyController myController() {
return new MyController(); return new MyController();
} }
@ -171,7 +171,7 @@ public class AbstractSecurityWebSocketMessageBrokerConfigurerDocTests {
static class SyncExecutorConfig { static class SyncExecutorConfig {
@Bean @Bean
public static SyncExecutorSubscribableChannelPostProcessor postProcessor() { static SyncExecutorSubscribableChannelPostProcessor postProcessor() {
return new SyncExecutorSubscribableChannelPostProcessor(); return new SyncExecutorSubscribableChannelPostProcessor();
} }

View File

@ -441,7 +441,7 @@ public class AbstractSecurityWebSocketMessageBrokerConfigurerTests {
} }
@Bean @Bean
public TestHandshakeHandler testHandshakeHandler() { TestHandshakeHandler testHandshakeHandler() {
return new TestHandshakeHandler(); return new TestHandshakeHandler();
} }
@ -480,7 +480,7 @@ public class AbstractSecurityWebSocketMessageBrokerConfigurerTests {
} }
@Bean @Bean
public TestHandshakeHandler testHandshakeHandler() { TestHandshakeHandler testHandshakeHandler() {
return new TestHandshakeHandler(); return new TestHandshakeHandler();
} }
@ -516,7 +516,7 @@ public class AbstractSecurityWebSocketMessageBrokerConfigurerTests {
} }
@Bean @Bean
public TestHandshakeHandler testHandshakeHandler() { TestHandshakeHandler testHandshakeHandler() {
return new TestHandshakeHandler(); return new TestHandshakeHandler();
} }
@ -545,18 +545,22 @@ public class AbstractSecurityWebSocketMessageBrokerConfigurerTests {
// @formatter:on // @formatter:on
@Bean @Bean
public static SecurityExpressionHandler<Message<Object>> messageSecurityExpressionHandler() { static SecurityExpressionHandler<Message<Object>> messageSecurityExpressionHandler() {
return new DefaultMessageSecurityExpressionHandler<Object>() { return new DefaultMessageSecurityExpressionHandler<Object>() {
@Override @Override
protected SecurityExpressionOperations createSecurityExpressionRoot(Authentication authentication, protected SecurityExpressionOperations createSecurityExpressionRoot(Authentication authentication,
Message<Object> invocation) { Message<Object> invocation) {
return new MessageSecurityExpressionRoot(authentication, invocation) { return new MessageSecurityExpressionRoot(authentication, invocation) {
public boolean denyRob() { public boolean denyRob() {
Authentication auth = getAuthentication(); Authentication auth = getAuthentication();
return auth != null && !"rob".equals(auth.getName()); return auth != null && !"rob".equals(auth.getName());
} }
}; };
} }
}; };
} }

View File

@ -113,7 +113,7 @@ public class AuthenticationConfigurationGh3935Tests {
} }
@Bean @Bean
public UserDetailsService userDetailsService() { UserDetailsService userDetailsService() {
return mock(UserDetailsService.class); return mock(UserDetailsService.class);
} }

View File

@ -166,7 +166,7 @@ public class GrantedAuthorityDefaultsJcTests {
static class Config extends WebSecurityConfigurerAdapter { static class Config extends WebSecurityConfigurerAdapter {
@Autowired @Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
// @formatter:off // @formatter:off
auth auth
.inMemoryAuthentication() .inMemoryAuthentication()
@ -184,12 +184,12 @@ public class GrantedAuthorityDefaultsJcTests {
} }
@Bean @Bean
public MessageService messageService() { MessageService messageService() {
return new HelloWorldMessageService(); return new HelloWorldMessageService();
} }
@Bean @Bean
public static GrantedAuthorityDefaults grantedAuthorityDefaults() { static GrantedAuthorityDefaults grantedAuthorityDefaults() {
return new GrantedAuthorityDefaults(""); return new GrantedAuthorityDefaults("");
} }

View File

@ -47,7 +47,7 @@ public class ReactiveUserDetailsServiceResourceFactoryBeanPropertiesResourceITes
static class Config { static class Config {
@Bean @Bean
public ReactiveUserDetailsServiceResourceFactoryBean userDetailsService() { ReactiveUserDetailsServiceResourceFactoryBean userDetailsService() {
return ReactiveUserDetailsServiceResourceFactoryBean return ReactiveUserDetailsServiceResourceFactoryBean
.fromResource(new InMemoryResource("user=password,ROLE_USER")); .fromResource(new InMemoryResource("user=password,ROLE_USER"));
} }

View File

@ -46,7 +46,7 @@ public class ReactiveUserDetailsServiceResourceFactoryBeanPropertiesResourceLoca
static class Config { static class Config {
@Bean @Bean
public ReactiveUserDetailsServiceResourceFactoryBean userDetailsService() { ReactiveUserDetailsServiceResourceFactoryBean userDetailsService() {
return ReactiveUserDetailsServiceResourceFactoryBean.fromResourceLocation("classpath:users.properties"); return ReactiveUserDetailsServiceResourceFactoryBean.fromResourceLocation("classpath:users.properties");
} }

View File

@ -46,7 +46,7 @@ public class ReactiveUserDetailsServiceResourceFactoryBeanStringITests {
static class Config { static class Config {
@Bean @Bean
public ReactiveUserDetailsServiceResourceFactoryBean userDetailsService() { ReactiveUserDetailsServiceResourceFactoryBean userDetailsService() {
return ReactiveUserDetailsServiceResourceFactoryBean.fromString("user=password,ROLE_USER"); return ReactiveUserDetailsServiceResourceFactoryBean.fromString("user=password,ROLE_USER");
} }

View File

@ -228,12 +228,12 @@ public class InterceptUrlConfigTests {
static class PathController { static class PathController {
@RequestMapping("/path") @RequestMapping("/path")
public String path() { String path() {
return "path"; return "path";
} }
@RequestMapping("/path/{un}/path") @RequestMapping("/path/{un}/path")
public String path(@PathVariable("un") String name) { String path(@PathVariable("un") String name) {
return name; return name;
} }

View File

@ -751,12 +751,12 @@ public class MiscHttpConfigTests {
static class BasicController { static class BasicController {
@RequestMapping("/unprotected") @RequestMapping("/unprotected")
public String unprotected() { String unprotected() {
return "ok"; return "ok";
} }
@RequestMapping("/protected") @RequestMapping("/protected")
public String protectedMethod(@AuthenticationPrincipal String name) { String protectedMethod(@AuthenticationPrincipal String name) {
return name; return name;
} }
@ -766,7 +766,7 @@ public class MiscHttpConfigTests {
static class CustomKeyController { static class CustomKeyController {
@GetMapping("/customKey") @GetMapping("/customKey")
public String customKey() { String customKey() {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if (authentication != null && authentication instanceof AnonymousAuthenticationToken) { if (authentication != null && authentication instanceof AnonymousAuthenticationToken) {
@ -782,18 +782,18 @@ public class MiscHttpConfigTests {
static class AuthenticationController { static class AuthenticationController {
@GetMapping("/password") @GetMapping("/password")
public String password(@AuthenticationPrincipal Authentication authentication) { String password(@AuthenticationPrincipal Authentication authentication) {
return (String) authentication.getCredentials(); return (String) authentication.getCredentials();
} }
@GetMapping("/roles") @GetMapping("/roles")
public String roles(@AuthenticationPrincipal Authentication authentication) { String roles(@AuthenticationPrincipal Authentication authentication) {
return authentication.getAuthorities().stream().map(GrantedAuthority::getAuthority) return authentication.getAuthorities().stream().map(GrantedAuthority::getAuthority)
.collect(Collectors.joining(",")); .collect(Collectors.joining(","));
} }
@GetMapping("/details") @GetMapping("/details")
public String details(@AuthenticationPrincipal Authentication authentication) { String details(@AuthenticationPrincipal Authentication authentication) {
return authentication.getDetails().getClass().getName(); return authentication.getDetails().getClass().getName();
} }
@ -803,7 +803,7 @@ public class MiscHttpConfigTests {
static class JaasController { static class JaasController {
@GetMapping("/username") @GetMapping("/username")
public String username() { String username() {
Subject subject = Subject.getSubject(AccessController.getContext()); Subject subject = Subject.getSubject(AccessController.getContext());
return subject.getPrincipals().iterator().next().getName(); return subject.getPrincipals().iterator().next().getName();
} }

View File

@ -97,7 +97,7 @@ public class MultiHttpBlockConfigTests {
static class BasicController { static class BasicController {
@GetMapping("/first") @GetMapping("/first")
public String first() { String first() {
return "ok"; return "ok";
} }

View File

@ -194,7 +194,7 @@ public class OpenIDConfigTests {
static class CustomLoginController { static class CustomLoginController {
@GetMapping("/login") @GetMapping("/login")
public String custom() { String custom() {
return "a custom login page"; return "a custom login page";
} }

View File

@ -534,12 +534,12 @@ public class SessionManagementConfigTests {
static class BasicController { static class BasicController {
@GetMapping("/") @GetMapping("/")
public String ok() { String ok() {
return "ok"; return "ok";
} }
@GetMapping("/auth") @GetMapping("/auth")
public String auth(Principal principal) { String auth(Principal principal) {
return principal.getName(); return principal.getName();
} }
@ -553,17 +553,17 @@ public class SessionManagementConfigTests {
private Boolean exists = true; private Boolean exists = true;
public ResultMatcher exists(boolean exists) { ResultMatcher exists(boolean exists) {
this.exists = exists; this.exists = exists;
return this; return this;
} }
public ResultMatcher valid(boolean valid) { ResultMatcher valid(boolean valid) {
this.valid = valid; this.valid = valid;
return this.exists(true); return this.exists(true);
} }
public ResultMatcher id(String id) { ResultMatcher id(String id) {
this.id = id; this.id = id;
return this.exists(true); return this.exists(true);
} }

View File

@ -132,7 +132,7 @@ public class CustomHttpSecurityConfigurerTests {
} }
@Bean @Bean
public static PropertyPlaceholderConfigurer propertyPlaceholderConfigurer() { static PropertyPlaceholderConfigurer propertyPlaceholderConfigurer() {
// Typically externalize this as a properties file // Typically externalize this as a properties file
Properties properties = new Properties(); Properties properties = new Properties();
properties.setProperty("permitAllPattern", "/public/**"); properties.setProperty("permitAllPattern", "/public/**");
@ -160,7 +160,7 @@ public class CustomHttpSecurityConfigurerTests {
} }
@Bean @Bean
public static PropertyPlaceholderConfigurer propertyPlaceholderConfigurer() { static PropertyPlaceholderConfigurer propertyPlaceholderConfigurer() {
// Typically externalize this as a properties file // Typically externalize this as a properties file
Properties properties = new Properties(); Properties properties = new Properties();
properties.setProperty("permitAllPattern", "/public/**"); properties.setProperty("permitAllPattern", "/public/**");

View File

@ -47,7 +47,7 @@ public class UserDetailsManagerResourceFactoryBeanPropertiesResourceITests {
static class Config { static class Config {
@Bean @Bean
public UserDetailsManagerResourceFactoryBean userDetailsService() { UserDetailsManagerResourceFactoryBean userDetailsService() {
return UserDetailsManagerResourceFactoryBean.fromResource(new InMemoryResource("user=password,ROLE_USER")); return UserDetailsManagerResourceFactoryBean.fromResource(new InMemoryResource("user=password,ROLE_USER"));
} }

View File

@ -46,7 +46,7 @@ public class UserDetailsManagerResourceFactoryBeanPropertiesResourceLocationITes
static class Config { static class Config {
@Bean @Bean
public UserDetailsManagerResourceFactoryBean userDetailsService() { UserDetailsManagerResourceFactoryBean userDetailsService() {
return UserDetailsManagerResourceFactoryBean.fromResourceLocation("classpath:users.properties"); return UserDetailsManagerResourceFactoryBean.fromResourceLocation("classpath:users.properties");
} }

View File

@ -46,7 +46,7 @@ public class UserDetailsManagerResourceFactoryBeanStringITests {
static class Config { static class Config {
@Bean @Bean
public UserDetailsManagerResourceFactoryBean userDetailsService() { UserDetailsManagerResourceFactoryBean userDetailsService() {
return UserDetailsManagerResourceFactoryBean.fromString("user=password,ROLE_USER"); return UserDetailsManagerResourceFactoryBean.fromString("user=password,ROLE_USER");
} }

View File

@ -201,7 +201,7 @@ public class HttpsRedirectSpecTests {
} }
@Bean @Bean
public PortMapper portMapper() { PortMapper portMapper() {
return mock(PortMapper.class); return mock(PortMapper.class);
} }
@ -225,7 +225,7 @@ public class HttpsRedirectSpecTests {
} }
@Bean @Bean
public PortMapper portMapper() { PortMapper portMapper() {
return mock(PortMapper.class); return mock(PortMapper.class);
} }

View File

@ -256,7 +256,7 @@ public class OAuth2ClientSpecTests {
ServerRequestCache requestCache = mock(ServerRequestCache.class); ServerRequestCache requestCache = mock(ServerRequestCache.class);
@Bean @Bean
public SecurityWebFilterChain springSecurityFilter(ServerHttpSecurity http) { SecurityWebFilterChain springSecurityFilter(ServerHttpSecurity http) {
// @formatter:off // @formatter:off
http http
.oauth2Client() .oauth2Client()
@ -284,7 +284,7 @@ public class OAuth2ClientSpecTests {
ServerRequestCache requestCache = mock(ServerRequestCache.class); ServerRequestCache requestCache = mock(ServerRequestCache.class);
@Bean @Bean
public SecurityWebFilterChain springSecurityFilter(ServerHttpSecurity http) { SecurityWebFilterChain springSecurityFilter(ServerHttpSecurity http) {
// @formatter:off // @formatter:off
http http
.oauth2Client((oauth2Client) -> .oauth2Client((oauth2Client) ->

Some files were not shown because too many files have changed in this diff Show More