¿为什么 Spring 安全配置会在 Websphere Application Server 上生成 cvc-complex-type.2.4.c?
¿Why does Spring Security config produce a cvc-complex-type.2.4.c on Websphere Application Server?
几周来我一直在为这个问题苦苦挣扎。我有一些遗留代码,最近从 4 迁移到 Spring 5。代码在本地主机上运行良好,但当上传到 WebSphere Application Server 时,它严重崩溃。
错误如下所示:
Error Page Exception
SRVE0260E: The server cannot use the error page specified for your application to handle the Original Exception printed below.
Original Exception:
Error Message: javax.servlet.ServletException: Filter [springSecurityFilterChain]: could not be initialized
Error Code: 500
Target Servlet: main
Error Stack:
org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 8 in XML document from file [/opt/IBM/WebSphere/AppServer/profiles/******/installedApps/******/******.ear/******.war/WEB-INF/classes/spring/spring-security.xml] is invalid; nested exception is org.xml.sax.SAXParseException: cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'http'.
at stack stack stack and so on...
我已经研究了一个星期了,我想我已经尝试过所有常见的嫌疑人。
- 我在我的 Maven 依赖项中使用所有 Spring 模块的相同版本 (5.2.0)。
- 我确实有 spring-security-config 作为依赖项。
- 我已经检查了打包的应用程序。我的
.ear
包含我的 .war
,后者又在其 WEB-INF/lib
文件夹中包含 spring-security-config.jar
。
奇怪的是,我已经尝试从我的耳朵中删除 spring-security-config.jar,但错误仍然存在。然后我开始怀疑 spring-beans.xsd 定义。我写了一个简单的脚本来输出我的一级依赖项(没有传递依赖)上的所有打包文件,但只有一个 spring-beans.xsd
和一个 spring-security.xsd
在那里。
由于该问题只存在于 WebSphere Application Server 上,我首先尝试将类加载器配置为使用本地 类,以防 spring 的某些服务器端版本干扰我的软件。这对结果没有任何影响。
这是我的 spring-security.xml
配置文件的样子:
<?xml version="1.0" encoding="UTF-8"?>
<b:beans xmlns="http://www.springframework.org/schema/security"
xmlns:b="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security.xsd">
<http security="none" pattern="/services/**"/>
<http security="none" pattern="/css/**"/>
<http security="none" pattern="/fonts/**"/>
<http security="none" pattern="/images/**"/>
<http security="none" pattern="/js/**"/>
<http security="none" pattern="/error/**"/>
<http security="none" pattern="/api/**"/>
<http>
<intercept-url pattern="/validationCheck" access="permitAll"/>
<intercept-url pattern="/validationCheckStatus/**" access="permitAll"/>
<intercept-url pattern="/ping" access="permitAll"/>
<intercept-url pattern="/login.htm" access="permitAll" requires-channel="https"/>
<intercept-url pattern="/login-error.htm" access="permitAll" requires-channel="https"/>
<intercept-url pattern="/logout" access="hasRole('ROLE_USER')" requires-channel="https"/>
<intercept-url pattern="/**" access="hasRole('ROLE_USER')" requires-channel="https"/>
<logout logout-url="/logout" logout-success-url="/"/>
<form-login login-page="/login.htm" authentication-failure-url="/login-error.htm"
login-processing-url="/login.htm" default-target-url="/index.htm"
always-use-default-target="true"/>
<port-mappings>
<!-- Default ports -->
<port-mapping http="80" https="443"/>
<!-- Websphere default ports -->
<port-mapping http="9080" https="9443"/>
<!-- Websphere DES default ports -->
<port-mapping http="9082" https="9445"/>
<!-- Tomcat default ports -->
<port-mapping http="8080" https="8443"/>
<!-- Jetty custom ports -->
<port-mapping http="7777" https="7443"/>
</port-mappings>
</http>
<authentication-manager>
<authentication-provider ref="customAuthenticationProvider"/>
</authentication-manager>
</b:beans>
如有任何帮助,我们将不胜感激。
在 Spring 安全版本 5.2.0 中,spring-security-config.jar/META-INF/spring.schemas
中描述的 XSD 模式转换现在如下所示:
https\://www.springframework.org/schema/security/spring-security.xsd=org/springframework/security/config/spring-security-5.2.xsd
https\://www.springframework.org/schema/security/spring-security-5.2.xsd=org/springframework/security/config/spring-security-5.2.xsd
http\://www.springframework.org/schema/security/spring-security-5.1.xsd=org/springframework/security/config/spring-security-5.1.xsd
...
新架构和无版本指针现在只能通过 HTTPS 进行寻址。
我的问题的解决方案是将我的所有架构位置设置为这样解析:
http://www.springframework.org/schema/security https://www.springframework.org/schema/security/spring-security.xsd
第二部分指向 https
协议 URL。
这也被描述 here 并在随后的 Spring 安全版本中得到解决,但我花了一个星期才弄清楚这个微妙之处。
几周来我一直在为这个问题苦苦挣扎。我有一些遗留代码,最近从 4 迁移到 Spring 5。代码在本地主机上运行良好,但当上传到 WebSphere Application Server 时,它严重崩溃。
错误如下所示:
Error Page Exception
SRVE0260E: The server cannot use the error page specified for your application to handle the Original Exception printed below.
Original Exception:
Error Message: javax.servlet.ServletException: Filter [springSecurityFilterChain]: could not be initialized
Error Code: 500
Target Servlet: main
Error Stack:
org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 8 in XML document from file [/opt/IBM/WebSphere/AppServer/profiles/******/installedApps/******/******.ear/******.war/WEB-INF/classes/spring/spring-security.xml] is invalid; nested exception is org.xml.sax.SAXParseException: cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'http'.
at stack stack stack and so on...
我已经研究了一个星期了,我想我已经尝试过所有常见的嫌疑人。
- 我在我的 Maven 依赖项中使用所有 Spring 模块的相同版本 (5.2.0)。
- 我确实有 spring-security-config 作为依赖项。
- 我已经检查了打包的应用程序。我的
.ear
包含我的.war
,后者又在其WEB-INF/lib
文件夹中包含spring-security-config.jar
。
奇怪的是,我已经尝试从我的耳朵中删除 spring-security-config.jar,但错误仍然存在。然后我开始怀疑 spring-beans.xsd 定义。我写了一个简单的脚本来输出我的一级依赖项(没有传递依赖)上的所有打包文件,但只有一个 spring-beans.xsd
和一个 spring-security.xsd
在那里。
由于该问题只存在于 WebSphere Application Server 上,我首先尝试将类加载器配置为使用本地 类,以防 spring 的某些服务器端版本干扰我的软件。这对结果没有任何影响。
这是我的 spring-security.xml
配置文件的样子:
<?xml version="1.0" encoding="UTF-8"?>
<b:beans xmlns="http://www.springframework.org/schema/security"
xmlns:b="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security.xsd">
<http security="none" pattern="/services/**"/>
<http security="none" pattern="/css/**"/>
<http security="none" pattern="/fonts/**"/>
<http security="none" pattern="/images/**"/>
<http security="none" pattern="/js/**"/>
<http security="none" pattern="/error/**"/>
<http security="none" pattern="/api/**"/>
<http>
<intercept-url pattern="/validationCheck" access="permitAll"/>
<intercept-url pattern="/validationCheckStatus/**" access="permitAll"/>
<intercept-url pattern="/ping" access="permitAll"/>
<intercept-url pattern="/login.htm" access="permitAll" requires-channel="https"/>
<intercept-url pattern="/login-error.htm" access="permitAll" requires-channel="https"/>
<intercept-url pattern="/logout" access="hasRole('ROLE_USER')" requires-channel="https"/>
<intercept-url pattern="/**" access="hasRole('ROLE_USER')" requires-channel="https"/>
<logout logout-url="/logout" logout-success-url="/"/>
<form-login login-page="/login.htm" authentication-failure-url="/login-error.htm"
login-processing-url="/login.htm" default-target-url="/index.htm"
always-use-default-target="true"/>
<port-mappings>
<!-- Default ports -->
<port-mapping http="80" https="443"/>
<!-- Websphere default ports -->
<port-mapping http="9080" https="9443"/>
<!-- Websphere DES default ports -->
<port-mapping http="9082" https="9445"/>
<!-- Tomcat default ports -->
<port-mapping http="8080" https="8443"/>
<!-- Jetty custom ports -->
<port-mapping http="7777" https="7443"/>
</port-mappings>
</http>
<authentication-manager>
<authentication-provider ref="customAuthenticationProvider"/>
</authentication-manager>
</b:beans>
如有任何帮助,我们将不胜感激。
在 Spring 安全版本 5.2.0 中,spring-security-config.jar/META-INF/spring.schemas
中描述的 XSD 模式转换现在如下所示:
https\://www.springframework.org/schema/security/spring-security.xsd=org/springframework/security/config/spring-security-5.2.xsd
https\://www.springframework.org/schema/security/spring-security-5.2.xsd=org/springframework/security/config/spring-security-5.2.xsd
http\://www.springframework.org/schema/security/spring-security-5.1.xsd=org/springframework/security/config/spring-security-5.1.xsd
...
新架构和无版本指针现在只能通过 HTTPS 进行寻址。
我的问题的解决方案是将我的所有架构位置设置为这样解析:
http://www.springframework.org/schema/security https://www.springframework.org/schema/security/spring-security.xsd
第二部分指向 https
协议 URL。
这也被描述 here 并在随后的 Spring 安全版本中得到解决,但我花了一个星期才弄清楚这个微妙之处。