首页 > 解决方案 > 如何发布基于表单的身份验证

问题描述

我正在尝试使基于表单的身份验证正常工作,并且在网络上仅发现 1 个引用表明 url 是 j_security_check 并且参数是 j_username 和 j_password。在任何 quarkus 文档中都没有提到这一点。

我是否遗漏了某些内容,或者文档是否缺少此关键信息?

谢谢

杰夫

标签: quarkus

解决方案


是的,您完全正确地认为缺乏这方面的文档,尽管如此,我还是整合了一些信息。

进行身份验证

创建一个执行 POST 的 HTML 表单/j_security_check

登录.html

<form action="j_security_check" method="post">
    <div class="container">
        <label for="j_username"><b>Username</b></label>
        <input type="text" placeholder="Enter Username" name="j_username" required>

        <label for="j_password"><b>Password</b></label>
        <input type="password" placeholder="Enter Password" name="j_password" required>

        <button type="submit">Login</button>

    </div>
</form>

卷曲示例

$ curl -i -X POST http://localhost:8080/j_security_check -d 'j_username=admin&j_password=admin'
HTTP/1.1 302 Found
location: http://localhost:8080/index.html
content-length: 0
set-cookie: quarkus-credential=DPeFtSios6kIpWpJw6BpCfId3+MT151H3yPOc5VzfYdrdO6oRcE+dy18IL0KMeFx; Path=/

登录机制参考

我没有找到任何其他解释登录步骤的文档,但我在 quarkus 源代码上做了一些 greps,发现这个文件似乎可以处理/j_security_check端点,看起来还没有办法自定义这个路径或参数名称。此文件存在于依赖项上quarkus-vertx-http-1.10.5.Final.jar

public class FormAuthenticationMechanism implements HttpAuthenticationMechanism {

    private static final Logger log = Logger.getLogger(FormAuthenticationMechanism.class);

    public static final String DEFAULT_POST_LOCATION = "/j_security_check";

一个有趣的事实是,在undertow project也可以找到一个同名但具有更高级代码的文件,可以在那里自定义路径。


推荐阅读