acegi的驗證問題1 ---中文用戶名登錄,及md5加密密碼方式
在框架中使用了acegi,但是割接了一個微軟的系統,系統中出現了中文用戶名登錄,這就造成了問題。因為之前acegi都是另一個同事負責,現在同事不在,只能自己解決,找到acegi中取得用戶名的地方
org.acegisecurity.ui.webapp.AuthenticationProcessingFilter 中的這段代碼
1
public Authentication attemptAuthentication(HttpServletRequest request)
2
throws AuthenticationException {
3
String username = obtainUsername(request);
4
String password = obtainPassword(request);
5
6
if (username == null) {
7
username = "";
8
}
9
10
if (password == null) {
11
password = "";
12
}
13
14
UsernamePasswordAuthenticationToken authRequest = new UsernamePasswordAuthenticationToken(username, password);
15
16
// Place the last username attempted into HttpSession for views
17
request.getSession().setAttribute(ACEGI_SECURITY_LAST_USERNAME_KEY, username);
18
19
// Allow subclasses to set the "details" property
20
setDetails(request, authRequest);
21
22
return this.getAuthenticationManager().authenticate(authRequest);
23
}
24

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

取出username后發現是亂碼,如果解決這個問題呢?第一個想到的是轉碼


spring的filter是解決編碼問題的,但是因為acegi的filter在spring之前,所以編碼沒有轉碼。又不能把acegi的filter挪到spring filter之后,這樣就有安全問題了。
那就增加一個filter,只過濾登錄鏈接,然后設置一下代替spring的encodingfilter設置一下編碼,解決問題
















但是另一個問題來了,密碼是非明文的md5加密的,需要加密,同樣不想更改acegi。
那好吧繼續使用filter,看看能否getParameter后再set回去















posted on 2008-09-19 21:29 dreamstone 閱讀(3722) 評論(0) 編輯 收藏 所屬分類: 其它開源框架