<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    DANCE WITH JAVA

    開發出高質量的系統

    常用鏈接

    統計

    積分與排名

    好友之家

    最新評論

    acegi的驗證問題1 ---中文用戶名登錄,及md5加密密碼方式

        在框架中使用了acegi,但是割接了一個微軟的系統,系統中出現了中文用戶名登錄,這就造成了問題。
    因為之前acegi都是另一個同事負責,現在同事不在,只能自己解決,找到acegi中取得用戶名的地方
    org.acegisecurity.ui.webapp.AuthenticationProcessingFilter 中的這段代碼
     1public 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

    取出username后發現是亂碼,如果解決這個問題呢?第一個想到的是轉碼
    username=new String(username.getBytes("ISO8859-1"),"UTF-8");
    解決問題,但是這段代碼要嵌入到acegi中必須重新編譯acegi
    上邊的辦法改動太大,再想辦法,想到既然問題是來自編碼,看看web.xml的filter發現原因在這
    spring的filter是解決編碼問題的,但是因為acegi的filter在spring之前,所以編碼沒有轉碼。又不能把acegi的filter挪到spring filter之后,這樣就有安全問題了。

    那就增加一個filter,只過濾登錄鏈接,然后設置一下代替spring的encodingfilter設置一下編碼,解決問題
    public class EncodeChnUsernameFilter implements Filter{
        
    private static final String ACEGI_SECURITY_FORM_USERNAME_KEY ="j_username";
        
    private static final String ACEGI_SECURITY_FORM_PASSWORD_KEY = "j_password";
        
    public void destroy() {
            
        }


        
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
            request.setCharacterEncoding(
    "UTF-8");
            chain.doFilter(request, response);
        }


        
    public void init(FilterConfig arg0) throws ServletException {
            
        }

    }
    中文用戶名登錄問題解決了。

    但是另一個問題來了,密碼是非明文的md5加密的,需要加密,同樣不想更改acegi。
    那好吧繼續使用filter,看看能否getParameter后再set回去
    String password= request.getParameter("j_password");
    //這里是個md5加密函數
    password = md5(password);
    //怎么set進去呢?
    request.getParameterMap().put("j_password",password);
    //啟動試一下,異常報錯,map不能put,看一下異常,發現這個不是普通的map,是org.apache.catalina.util.ParameterMap,這個map中有個標志位lock,tomcat不讓更改http接收到的值。
    //基于不服輸的精神,一定要搞定它,呵呵
    ParameterMap map = (ParameterMap)request.getParameterMap();
    map.setLock(
    false);
    map.put(
    "j_password",password);
    map.setLock(
    true);
    //搞定?不對,編譯不通過,發現org.apache.catalina.util.ParameterMap的jar包是catalina.jar。
    把這個包放到lib下編譯,通過,運行出向下轉型錯誤,仔細看一下發現request.getParameterMap()出來的ParameterMap.getClass()的id是300多,而接受轉型
    的ParameterMap.class.getClass()是6000多,不是一個類啊。想想也對,lib下和tomcat的server/lib下各有一個catalina.jar這個就是兩個類了。

    eclipse add 外部jar包,直接add上tomcat中的catalina.jar,編譯運行,還是有問題,這次是報的classNotFound異常,為什么會這樣呢,命名Server
    /lib下有這個jar包,后來想了下明白了。tomcat一定是限定了catalina.jar不能被普通的用戶類所直接引用。處于安全性考慮吧。這條路走不通了,回到acegi才發現acegi的配置文件中是可以隨意配置autheticationfilter的,自己寫一個autheticationfilter,配置進去,不用系統的,解決問題,filter里邊怎么寫都沒問題,愛怎么處理怎么處理,呵呵

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

    主站蜘蛛池模板: 中文字幕影片免费在线观看| 亚洲国产欧美国产综合一区| 国产日韩久久免费影院| 四虎成人精品在永久免费| 亚洲精品天堂成人片AV在线播放| 美女视频黄的全免费视频| 亚洲理论片在线中文字幕| 91久久成人免费| 亚洲日本久久久午夜精品| 最近免费中文字幕大全视频| 亚洲色大成网站www久久九| 日本免费v片一二三区| 青青免费在线视频| 亚洲人成网站色在线入口| 久久精品成人免费观看97| 亚洲国产精品一区二区成人片国内 | 成全高清在线观看免费| 亚洲va在线va天堂va888www| 最近2019年免费中文字幕高清| 亚洲日韩国产精品乱-久| 免费在线精品视频| a级黄色毛片免费播放视频| 亚洲天堂在线播放| 国产又黄又爽又猛免费app| 爱爱帝国亚洲一区二区三区| 久久久精品国产亚洲成人满18免费网站| 久久www免费人成精品香蕉| 久久久久亚洲Av片无码v| 日韩版码免费福利视频| 在线观看免费亚洲| 久久青青草原亚洲AV无码麻豆 | 国产做国产爱免费视频| 亚洲码一区二区三区| 日韩黄色免费观看| 拍拍拍无挡免费视频网站| 亚洲免费人成视频观看| 亚洲а∨天堂久久精品| 亚洲视频在线免费看| 激情吃奶吻胸免费视频xxxx| 亚洲高清在线视频| 四虎国产精品免费视|