gpt4 book ai didi

java - 认证弹窗是怎么来的

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:30:06 24 4
gpt4 key购买 nike

我有一个非常简单的疑问,我知道你们中的大多数人可能会对这个问题投反对票。但由于我对 Web 应用程序还很陌生,所以我不知道它是怎么出现的。

问题:每当我登录某个 Web 应用程序时,我都会收到一个弹出窗口,要求进行身份验证。一些类似的东西,

Warning: This server is requesting that your username and password be sent in an insecure manner (basic authentication without a secure connection).

为此设置在哪里?我正在尝试为我的 Hello World 应用程序做类似的事情。请帮帮我。

最佳答案

这是 Servlet 技术支持的 Basic Authentication。这就是您在 web.xml 中为 Web 资源定义基本身份验证的方式。

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

请在此处找到完整示例:

<?xml version='1.0' encoding='UTF-8'?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<web-app>
<welcome-file-list>
<welcome-file>welcome.jsp</welcome-file>
</welcome-file-list>

<security-constraint>
<web-resource-collection>
<web-resource-name>Success</web-resource-name>
<url-pattern>/secured/*</url-pattern>
<http-method>GET</http-method>
<http-method>POST</http-method>
</web-resource-collection>
<auth-constraint>
<role-name>secured</role-name>
</auth-constraint>
</security-constraint>

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

<security-role>
<role-name>secured</role-name>
</security-role>
</web-app>

请阅读以下链接,了解Servlet技术支持的几种认证机制:

Standard form authentification Java servlets

关于java - 认证弹窗是怎么来的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15401838/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com