SEC-3158 findRequiredWebApplicationContext() compatibility with spring framework 4.1.x
This commit is contained in:
parent
ed01213a27
commit
3af4140742
|
@ -15,6 +15,7 @@
|
||||||
*/
|
*/
|
||||||
package org.springframework.security.web.context.support;
|
package org.springframework.security.web.context.support;
|
||||||
|
|
||||||
|
import java.util.Enumeration;
|
||||||
import javax.servlet.ServletContext;
|
import javax.servlet.ServletContext;
|
||||||
|
|
||||||
import org.springframework.web.context.WebApplicationContext;
|
import org.springframework.web.context.WebApplicationContext;
|
||||||
|
@ -43,10 +44,33 @@ public abstract class SecurityWebApplicationContextUtils extends WebApplicationC
|
||||||
* @throws IllegalStateException if no WebApplicationContext can be found
|
* @throws IllegalStateException if no WebApplicationContext can be found
|
||||||
*/
|
*/
|
||||||
public static WebApplicationContext findRequiredWebApplicationContext(ServletContext servletContext) {
|
public static WebApplicationContext findRequiredWebApplicationContext(ServletContext servletContext) {
|
||||||
WebApplicationContext wac = findWebApplicationContext(servletContext);
|
WebApplicationContext wac = _findWebApplicationContext(servletContext);
|
||||||
if (wac == null) {
|
if (wac == null) {
|
||||||
throw new IllegalStateException("No WebApplicationContext found: no ContextLoaderListener registered?");
|
throw new IllegalStateException("No WebApplicationContext found: no ContextLoaderListener registered?");
|
||||||
}
|
}
|
||||||
return wac;
|
return wac;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copy of {@link #findWebApplicationContext(ServletContext)} for compatibility with spring framework 4.1.x.
|
||||||
|
* @see #findWebApplicationContext(ServletContext)
|
||||||
|
*/
|
||||||
|
private static WebApplicationContext _findWebApplicationContext(ServletContext sc) {
|
||||||
|
WebApplicationContext wac = getWebApplicationContext(sc);
|
||||||
|
if (wac == null) {
|
||||||
|
Enumeration<String> attrNames = sc.getAttributeNames();
|
||||||
|
while (attrNames.hasMoreElements()) {
|
||||||
|
String attrName = attrNames.nextElement();
|
||||||
|
Object attrValue = sc.getAttribute(attrName);
|
||||||
|
if (attrValue instanceof WebApplicationContext) {
|
||||||
|
if (wac != null) {
|
||||||
|
throw new IllegalStateException("No unique WebApplicationContext found: more than one " +
|
||||||
|
"DispatcherServlet registered with publishContext=true?");
|
||||||
|
}
|
||||||
|
wac = (WebApplicationContext) attrValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return wac;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue