Skip to content

Commit

Permalink
Guard ErrorPageSecurityFilter configuration with ConditionalOnClass
Browse files Browse the repository at this point in the history
Update `ErrorPageSecurityFilterConfiguration` to guard against the case
where `spring-security-core` is on the classpath but
`spring-security-web` is not.

Fixes gh-28774
  • Loading branch information
mbhave authored and philwebb committed Nov 24, 2021
1 parent 49e4088 commit e7ff2cf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
Expand Up @@ -21,6 +21,7 @@
import javax.servlet.DispatcherType;

import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.filter.ErrorPageSecurityFilter;
Expand All @@ -35,6 +36,7 @@
* @author Madhura Bhave
*/
@Configuration(proxyBeanMethods = false)
@ConditionalOnClass(WebInvocationPrivilegeEvaluator.class)
@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET)
class ErrorPageSecurityFilterConfiguration {

Expand Down
Expand Up @@ -242,6 +242,18 @@ void filterRegistrationBeanForErrorPageSecurityInterceptor() {
}));
}

@Test
void filterForErrorPageSecurityInterceptorWhenWebInvocationPrivilegeEvaluatorNotPresent() {
this.contextRunner.withClassLoader(new FilteredClassLoader("org.springframework.security.config"))
.run((context) -> assertThat(context).doesNotHaveBean("errorPageSecurityFilter"));
}

@Test
void filterForErrorPageSecurityInterceptorConditionalOnClass() {
this.contextRunner.withClassLoader(new FilteredClassLoader("org.springframework.security.web"))
.run((context) -> assertThat(context).doesNotHaveBean("errorPageSecurityFilter"));
}

@Configuration(proxyBeanMethods = false)
@TestAutoConfigurationPackage(City.class)
static class EntityConfiguration {
Expand Down

0 comments on commit e7ff2cf

Please sign in to comment.