【问题标题】:Wildfly Form Auth fails when using special characters使用特殊字符时 Wildfly Form Auth 失败
【发布时间】:2026-02-18 17:40:01
【问题描述】:

我们正在将 GWT 应用程序部署到 Wildly 8.1.0 服务器,并使用表单身份验证来确保安全。我们的问题是,每次我们的客户在其用户名或密码中包含特殊字符(æøåäëö 等)时,他们都无法登录。

我看到其他人有同样的问题:

https://developer.jboss.org/thread/42859?tstart=0

UTF-8 encoded j_security_check username incorrectly decoded as Latin-1 in Tomcat realm

Spring security: Form login special characters

但他们使用的是 Tomcat/Apache/Spring 等,所以我很难找到适合我们设置的解决方案。

Wildly/Undertow 是否有任何配置参数,以便我们在用户登录时确保 UTF-8 编码?

我们的 web.xml:

<login-config>
    <auth-method>FORM</auth-method>
    <realm-name>project-security-policy</realm-name>
    <form-login-config>
        <form-login-page>/login.html</form-login-page>
        <form-error-page>/error.html</form-error-page>
    </form-login-config>
</login-config>

登录表单:

<form name="loginform" method="post" autocomplete="on" action="j_security_check" accept-charset="UTF-8 ISO-8859-1" onsubmit="return validate_login_form();">
    <input id="usernameInput" name="j_username" class="form-input" type="text" placeholder="Username" autofocus="">
    <input id="passwordInput" name="j_password" class="form-input" type="password" placeholder="Password">
    <input id="submitButton" type="submit" value="Login">
</form>

【问题讨论】:

    标签: jakarta-ee ejb wildfly wildfly-8 form-authentication


    【解决方案1】:

    我找到了解决方案。在独立文件中,我在 undertow 子系统中编辑了servlet-container 参数,并添加了default-encoding 属性。现在我的用户可以在用户名和密码中包含特殊字符。

    <servlet-container name="default" default-encoding="UTF-8">
    

    整个子系统如下所示:

    <subsystem xmlns="urn:jboss:domain:undertow:1.1">
        <buffer-cache name="default" />
        <server name="default-server">
            <http-listener name="default" socket-binding="http" />
            <host name="default-host" alias="localhost">
                <location name="/" handler="welcome-content" />
                <filter-ref name="server-header" />
                <filter-ref name="x-powered-by-header" />
            </host>
        </server>
        <servlet-container name="default" default-encoding="UTF-8">
            <jsp-config />
        </servlet-container>
        <handlers>
            <file name="welcome-content" path="${jboss.home.dir}/welcome-content" />
        </handlers>
        <filters>
            <response-header name="server-header" header-name="Server" header-value="WildFly/8" />
            <response-header name="x-powered-by-header" header-name="X-Powered-By" header-value="Undertow/1" />
        </filters>
    </subsystem>
    

    【讨论】:

    • 你知道Jboss中相同的效果选项吗?我在 Jboss 中找不到它
    • Wildfly 呢? stanalone.xml 文件在哪里?
    【解决方案2】:

    尝试用这个参数启动wildfly:

    -Dfile.encoding=UTF-8

    【讨论】:

    • 这个没试过,但已经发布了解决方案。