Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/352.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Glassfish只允许GET和POST方法_Java_Methods_Glassfish - Fatal编程技术网

Java Glassfish只允许GET和POST方法

Java Glassfish只允许GET和POST方法,java,methods,glassfish,Java,Methods,Glassfish,在部署ear后,我需要在glassfish 4.1.1中隐藏应用程序的方法,因此在web.xml中我添加了以下内容: <security-constraint> <display-name>Constraint1</display-name> <web-resource-collection> <web-resource-name>https</web-resource-na

在部署ear后,我需要在glassfish 4.1.1中隐藏应用程序的方法,因此在web.xml中我添加了以下内容:

<security-constraint>
        <display-name>Constraint1</display-name>
        <web-resource-collection>
            <web-resource-name>https</web-resource-name>
            <description/>
                <url-pattern>/*</url-pattern>
                         <http-method>GET</http-method>
                         <http-method>POST</http-method>
            </web-resource-collection>
        <user-data-constraint>
            <description/>
            <transport-guarantee>CONFIDENTIAL</transport-guarantee>
        </user-data-constraint>
    </security-constraint>
Allow: GET, HEAD, POST, PUT, DELETE, TRACE, OPTIONS
我得到以下信息:

<security-constraint>
        <display-name>Constraint1</display-name>
        <web-resource-collection>
            <web-resource-name>https</web-resource-name>
            <description/>
                <url-pattern>/*</url-pattern>
                         <http-method>GET</http-method>
                         <http-method>POST</http-method>
            </web-resource-collection>
        <user-data-constraint>
            <description/>
            <transport-guarantee>CONFIDENTIAL</transport-guarantee>
        </user-data-constraint>
    </security-constraint>
Allow: GET, HEAD, POST, PUT, DELETE, TRACE, OPTIONS

您所做的不会禁用未列出的方法(例如,PUT、DELETE),而是在使用这些方法时强制进行身份验证。如果您不想支持特定的HTTP方法,可以构建一个不支持该特定方法的webapp

例如,如果您部署的应用程序公开了某个REST端点以获取和发布,而不是PUT,那么很可能有人试图使用PUT访问它,他们已经获得了某种不支持的方法错误。您还可以更进一步,实际为PUT定义该端点,但随后抛出异常、返回自定义错误消息等


阅读了解更多信息。

@Time Biegeleisen,感谢您的回复,所以现在除了构建Web应用程序之外,我没有其他解决方案了?@Boukandourhamed我想说的是,如果您希望在部署的应用程序中阻止某些方法(例如PUT),那么请在应用程序层处理它。