【发布时间】:2015-02-13 13:18:16
【问题描述】:
我正在调查在登录表单中引入带有 Latin-1 字符的用户名的问题。 用户名包含字符á。 我调查了我拥有的服务器部分:
public class MyRealm 扩展 RealmBase 实现 Realm { 公共主体身份验证(字符串用户名,字符串密码){ ... 此处实现的实际身份验证 } }
如果我打印出字节:username.getBytes() 我看到字符 á 有:C3 83 C2 A1 通常 UTF8 编码中的字符 á 应该有:C3 A1。 如果我再次用 UTF8 编码,我会得到:C3 83 C2 A1 我的软件打印出来的内容。
我在网络捕获中检查了用户名是通过 C3 A1 正确发送的。 登录页面表单源代码为:
<form name="loginForm" action="j_security_check" method="post" enctype="application/x-www-form-urlencoded">
<table>
<tr>
<td colspan="2" align="right">Secure connection:
<input type="checkbox" name="checkbox" class="style5" onclick="javascript:httpHttps();"></td>
</tr>
<tr>
<td class="style5">Login:</td>
<td><input type="text" name="j_username" autocomplete="off" style="width:150px" /></td>
</tr>
所以我认为客户端没有问题(2 次 UTF8 转换)。 如果我在 authenticate() 函数中将用户名从 UTF8 解码两次,则身份验证工作正常, 但我害怕将此解决方案应用于我的问题
我应该在 Realm 的 authenticate(String username, String password) 函数中的哪里查找用户名的这种编码? 服务器端在带有 httpd-2.2.15 和 tomcat6-6.0.24 的 linux (RedHat) 上运行。
【问题讨论】:
标签: tomcat utf-8 character-encoding j-security-check