cleanup compatibility method based on spring-projects#8868

This commit is contained in:
Aditya Sekhar 2020-11-08 21:52:54 +05:30 committed by Rob Winch
parent 4602e9a661
commit a26975f780
1 changed files with 2 additions and 25 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -16,8 +16,6 @@
package org.springframework.security.web.context.support;
import java.util.Enumeration;
import javax.servlet.ServletContext;
import org.springframework.util.Assert;
@ -48,32 +46,11 @@ public abstract class SecurityWebApplicationContextUtils extends WebApplicationC
* @see ServletContext#getAttributeNames()
*/
public static WebApplicationContext findRequiredWebApplicationContext(ServletContext servletContext) {
WebApplicationContext webApplicationContext = compatiblyFindWebApplicationContext(servletContext);
WebApplicationContext webApplicationContext = findWebApplicationContext(servletContext);
Assert.state(webApplicationContext != null,
"No WebApplicationContext found: no ContextLoaderListener registered?");
return webApplicationContext;
}
/**
* Copy of {@link #findWebApplicationContext(ServletContext)} for compatibility with
* spring framework 4.1.x.
* @see #findWebApplicationContext(ServletContext)
*/
private static WebApplicationContext compatiblyFindWebApplicationContext(ServletContext sc) {
WebApplicationContext webApplicationContext = getWebApplicationContext(sc);
if (webApplicationContext == null) {
Enumeration<String> attrNames = sc.getAttributeNames();
while (attrNames.hasMoreElements()) {
String attrName = attrNames.nextElement();
Object attrValue = sc.getAttribute(attrName);
if (attrValue instanceof WebApplicationContext) {
Assert.state(webApplicationContext == null, "No unique WebApplicationContext found: more than one "
+ "DispatcherServlet registered with publishContext=true?");
webApplicationContext = (WebApplicationContext) attrValue;
}
}
}
return webApplicationContext;
}
}