WebSphere Liberty Profile - 如何在部署Spring Boot uber JAR时添加安全性约束

问题描述 投票:0回答:1

我很高兴看到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文件夹中,但似乎没有任何事情发生。

更新:

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

java spring-boot websphere-liberty
1个回答
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”

© www.soinside.com 2019 - 2024. All rights reserved.