2016-06-08 91 views
1

我們正在將我們的GWT應用程序部署到Wildly 8.1.0服務器,並使用表單驗證進行安全性驗證。我們的問題是,每當我們的客戶在其用戶名或密碼中有特殊字符(æøåäëö等)時,他們都無法登錄。使用特殊字符時Wild Form表單驗證失敗

我已經看到有同樣的問題其他人:

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的/彈簧等等,讓我有無法找到適合我們設置的解決方案。

是否有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> 

回答

4

我找到了解決方案。在獨立文件中,我編輯了在子系統中的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> 
+1

此解決方案適用於Wildfly10 – vanduc1102

+0

您是否知道Jboss中的相同效果選項?我在Jboss找不到它 – vanduc1102

-1

嘗試使用這個參數wildfly開始:

-Dfile.encoding = UTF-8

+0

沒有嘗試這一點,但已發佈的解決方案。 –