4

我的网络应用程序(使用 struts2 创建,包含 2 页

  • 1)提出请求
  • 2)批准请求

) 部署在 websphere 7 中。我需要为此应用程序启用基于角色的安全性。我有两个角色

1)用户(可以提出请求的人)

2)审批人

两者都有不同的凭据。我没有使用任何后端进行身份验证。如何使用 web.xml 的 websphere 安全功能和映射用户来做到这一点。

4

1 回答 1

1

我邀请您阅读JavaEE 6 教程章节“Getting Started Securing Web Applications”,特别是提供的示例。

您的应用程序必须声明两个安全角色userapprover并且web.xml必须保护 servlet 路径,这要归功于security-constraints.

这是一个作为起点的设置:

<security-constraint>
    <display-name>Raise Request</display-name>
    <web-resource-collection>
        <web-resource-name>raiserequestservlet</web-resource-name>
        <description/>
        <url-pattern>/raiserequest</url-pattern>
    </web-resource-collection>
    <auth-constraint>
        <description/>
        <role-name>user</role-name>
    </auth-constraint>
</security-constraint>
<security-constraint>
    <display-name>Approve Request</display-name>
    <web-resource-collection>
        <web-resource-name>approverequestservlet</web-resource-name>
        <description/>
        <url-pattern>/approverequest</url-pattern>
    </web-resource-collection>
    <auth-constraint>
        <description/>
        <role-name>approver</role-name>
    </auth-constraint>
</security-constraint>

<login-config>
    <auth-method>BASIC</auth-method>
    <realm-name>WebSphere</realm-name>
</login-config>

<security-role>
    <description>Security Role required to raise a request</description>
    <role-name>user</role-name>
</security-role>
<security-role>
    <description>Security Role required to approve a request</description>
    <role-name>approver</role-name>
</security-role>

对于第一次测试,我选择了基本身份验证,但还有其他选项。

然后,在将 WAR 包部署到 WebSphere 时,向导将允许您将两个应用程序角色映射到 LDAP 组,只要您使用 LDAP 作为后端进行身份验证和权限,这是强烈推荐的。

运行应用程序的服务器实例默认配置为使用全局安全性,但您可以为服务器/应用程序对创建专用安全域以使用专用后端。这是网络部署参考文档安全部分,可在这些方面为您提供指导。

于 2012-07-31T13:10:41.373 回答