Security 如何在战争之间共享安全约束?
我有一个JavaEE应用服务器jboss-eap-4.3和几个.wars,它们组成了一个更大的web应用程序。其思想是,一场战争可以单独进行,也可以与另一场战争联系起来。由于它们都是同一个应用程序的一部分,我们不想提供多个登录 我想配置.wars,使它们共享相同的安全约束和安全角色。基本上web.xml的这一部分:Security 如何在战争之间共享安全约束?,security,jakarta-ee,war,web-inf,Security,Jakarta Ee,War,Web Inf,我有一个JavaEE应用服务器jboss-eap-4.3和几个.wars,它们组成了一个更大的web应用程序。其思想是,一场战争可以单独进行,也可以与另一场战争联系起来。由于它们都是同一个应用程序的一部分,我们不想提供多个登录 我想配置.wars,使它们共享相同的安全约束和安全角色。基本上web.xml的这一部分: <security-constraint> <web-resource-collection> <url-pattern>/*&
<security-constraint>
<web-resource-collection>
<url-pattern>/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>Admin</role-name>
</auth-constraint>
<security-constraint>
<security-role>
<role-name>Admin</role-name>
</security-role>
<login-config>
<auth-method>BASIC</auth-method>
<realm-name>WebApp</realm-name>
</login-config>
我们的角色最近经常变化,我们也定期加入新的战争。此外,我们根据部署环境更改auth方法,这增加了另一个需要调整的原因。理想情况下,我希望找到一种方法来中断web.xml的安全部分,以便其他人可以继承它。我认为realms可能是一个寻找这个的好地方,但我没有发现任何有希望的东西
请注意,此容器中还有其他web应用程序具有完全不同的安全域,因此tomcat的全局设置可能不合适。这不是一个很好的答案,但我最终使用ant Macrodef(如下所示)自动完成了肮脏的工作
<!--
| Take a "plain" web.xml and add security settings to it.
| This will add BASIC authentication with Admin, Operator, and Guest role access
|
-->
<taskdef resource="net/sf/antcontrib/antlib.xml" />
<macrodef name="addSecurityToWeb.xml">
<attribute name="file"/>
<sequential>
<if>
<not>
<isfileselected file="@{file}">
<contains text="login-config" ignorewhitespace="true"/>
</isfileselected>
</not>
<then>
<replace file="@{file}">
<replacetoken><![CDATA[</web-app>]]></replacetoken>
<replacevalue>
<![CDATA[
<security-constraint>
<web-resource-collection>
<web-resource-name>Protected Area</web-resource-name>
<url-pattern>/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>Admin</role-name>
</auth-constraint>
<transport-guarantee>NONE</transport-guarantee>
</security-constraint>
<!-- Security roles referenced by this web application -->
<security-role>
<role-name>Admin</role-name>
</security-role>
<login-config>
<auth-method>BASIC</auth-method>
<realm-name>WebApp</realm-name>
</login-config>
</web-app>
]]>
</replacevalue>
</replace>
</then>
</if>
</sequential>
</macrodef>
我想我想到了单点登录,你也可以看看