<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 閱讀(3722) 評論(0)  編輯  收藏 所屬分類: 其它開源框架

    主站蜘蛛池模板: 亚洲精品第一国产综合境外资源 | 久久亚洲AV成人无码| 免费看一级做a爰片久久| 国产精品视频免费观看| 成人久久免费网站| yellow视频免费看| 国产亚洲蜜芽精品久久| 亚洲人成www在线播放| 亚洲天堂中文字幕| 亚洲成AV人片在线播放无码| 亚洲福利中文字幕在线网址| 日本不卡在线观看免费v| 免费A级毛片无码免费视| 免费观看黄色的网站| 91精品免费观看| 久久ww精品w免费人成| 美女视频黄a视频全免费网站色窝| 一级做a爰全过程免费视频毛片| 人人狠狠综合久久亚洲| 在线亚洲高清揄拍自拍一品区| 亚洲色成人网一二三区| 亚洲精品成人av在线| 久久亚洲国产成人亚| 亚洲AV无码专区在线播放中文| 亚洲乱亚洲乱妇无码麻豆| 国产国拍亚洲精品福利| 全部免费毛片在线播放| 你是我的城池营垒免费看| 精品女同一区二区三区免费播放| 亚洲永久网址在线观看| 亚洲性色AV日韩在线观看| 亚洲人AV在线无码影院观看| 亚洲综合色丁香婷婷六月图片| 中文字幕无码精品亚洲资源网久久 | 国产三级电影免费观看| 国产人妖ts在线观看免费视频| 国产一区二区三区免费在线观看| 国产麻豆剧传媒精品国产免费| 国产免费131美女视频| 亚洲国产综合精品一区在线播放| 亚洲情a成黄在线观看|