【问题标题】:WebSphere Liberty Profile - how to add security constraints when deploying the Spring Boot uber JARWebSphere Liberty Profile - 如何在部署 Spring Boot uber JAR 时添加安全约束
【发布时间】:2019-07-21 07:44:51
【问题描述】:

我很高兴看到 WebSphere Liberty Profile 在版本 18.0.0.2 中支持直接部署 Spring Boot 支持 JAR。

在我的 server.xml 我有:

<application id="x" name="x"
             type="spring"
             location="${server.config.dir}/apps/spring-boot-uber.jar">
        <application-bnd>
            <security-role name="Authenticated">
                <special-subject type="ALL_AUTHENTICATED_USERS"/>
            </security-role>
            <security-role name="SUPER_USERS">
                <group name="My_Admins"/>
            </security-role>
        </application-bnd>
    </application>

注意安全角色绑定。

在 web.xml (WAR) 或 ibm-ws-bnd.xml (EAR) 中我想我需要这样做:

<?xml version="1.0" encoding="UTF-8"?>
<webservices-bnd xmlns="http://websphere.ibm.com/xml/ns/javaee"
                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                 xsi:schemaLocation="http://websphere.ibm.com/xml/ns/javaee http://websphere.ibm.com/xml/ns/javaee/ibm-ws-bnd_1_0.xsd"
                 version="1.0">
    <http-publishing>
        <webservice-security>

            <security-constraint>
                <web-resource-collection>
                    <web-resource-name>all</web-resource-name>
                    <url-pattern>/*</url-pattern>
                    <http-method>GET</http-method>
                    <http-method>PUT</http-method>
                    <http-method>HEAD</http-method>
                    <http-method>TRACE</http-method>
                    <http-method>POST</http-method>
                    <http-method>DELETE</http-method>
                    <http-method>OPTIONS</http-method>
                </web-resource-collection>
                <auth-constraint>
                    <role-name>Authenticated</role-name>
                </auth-constraint>
            </security-constraint>

            <security-role>
                <description>All authenticated users</description>
                <role-name>Authenticated</role-name>
            </security-role>
            <security-role>
                <description>Super users</description>
                <role-name>SUPER_USERS</role-name>
            </security-role>

        </webservice-security>
    </http-publishing>
</webservices-bnd>

为了在 http 请求中设置身份验证信息(用户主体)。

如何在 Spring Boot 应用程序中使用它,我既没有 EAR 也没有 WAR(所以我没有 web.xml 文件)。

我尝试将 ibm-ws-bnd.xml 添加到 spring boot uber jar 的 META-INF 文件夹中,但似乎没有任何反应。

更新:

我什至不确定 WLP 在部署 Spring Boot uber JAR 时是否支持 application-bnd,但是我根本不知道如何将角色绑定到它。

【问题讨论】:

    标签: java spring-boot websphere-liberty


    【解决方案1】:

    您可能需要考虑使用 Spring Security https://spring.io/guides/gs/securing-web/ 在 Spring Boot 应用程序中提供用户详细信息和安全角色。截至目前,liberty 不支持在 application-bnd 中定义授权角色的 Spring Boot 应用程序 JAR。

    或者您可以将 JAR 文件转换为 WAR 并将您的 web.xml 文件放在 src/main/webapp/WEB-INF 文件夹中,并在 server.xml 中提供应用程序类型为“war”

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-06-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-03
      • 1970-01-01
      相关资源
      最近更新 更多