jakarta-ee - 在 Websphere7 中启用基于角色的安全性

标签 jakarta-ee struts2 websphere-7 security-roles

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

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

  • ) 部署在 websphere 7.我需要为此应用程序启用基于角色的安全性。我有两个角色
    1)用户(可以提出请求的人)
    2)审批人
    两者都有不同的凭据。我没有使用任何后端进行身份验证。如何通过 web.xml 和映射用户使用 websphere 安全功能来做到这一点。

    最佳答案

    诚邀您阅读JavaEE 6 Tutorial chapter "Getting Started Securing Web Applications"并特别提供了示例。

    您的应用程序必须声明两个安全角色 userapproverweb.xml由于 security-constraints,必须保护 servlet 路径.

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

    <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 作为身份验证和权限的后端,这是强烈推荐的。

    默认情况下,运行应用程序的服务器实例配置为使用全局安全性,但您可以为服务器/应用程序组合创建专用安全域以使用专用后端。这是network deployment reference documentation security section指导你的那些方面。

    关于jakarta-ee - 在 Websphere7 中启用基于角色的安全性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11546443/

    相关文章:

    java - 控制 Java EE 项目的范围

    java - 在 Struts2 中访问 Map 键值

    java - 从数据库自动填充 struts2 复选框

    java - session 无效无法使用基于 LTPA 的安全性

    java.lang.NoClassDefFoundError : javax. servlet.ServletInputStream 在 websphere 上部署时出错

    eclipse - 如何为 Web 动态项目 Java EE 创建安装文件

    java - 时间同步

    java - 将复杂类实例传递给 REST Web 服务的最佳做法是什么?

    javascript - 如何将新值附加到输入