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

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

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

    asdtiang的博客 感謝blogjava提供的博客交流平臺

    grails acegi 登錄驗證碼的實現(xiàn)

    Posted on 2010-07-09 11:57 asdtiang 閱讀(929) 評論(0)  編輯  收藏
    閑話不多說,直接上代碼吧:
    第一:如何更改acegi的源碼:在STS 中工程視圖改為project explorer ,在工程上點擊右擊,有個grails tools,里面刷新下依賴,在工程下就應該出現(xiàn)所有插件的源碼了,這樣就可以改了。
    找到了下類:

    改為如何下代碼:我也記不清怎么改的了:

    /* Copyright 2006-2009 the original author or authors.
     *
     * Licensed under the Apache License, Version 2.0 (the "License");
     * you may not use this file except in compliance with the License.
     * You may obtain a copy of the License at
     *
     *      
    http://www.apache.org/licenses/LICENSE-2.0
     *
     * Unless required by applicable law or agreed to in writing, software
     * distributed under the License is distributed on an "AS IS" BASIS,
     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     * See the License for the specific language governing permissions and
     * limitations under the License.
     
    */
    package org.codehaus.groovy.grails.plugins.springsecurity;

    import java.io.IOException;

    import javax.servlet.FilterChain;
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import javax.servlet.http.HttpSession;

    import org.springframework.security.Authentication;
    import org.springframework.security.AuthenticationException;
    import org.springframework.security.providers.UsernamePasswordAuthenticationToken;
    import org.springframework.security.ui.webapp.AuthenticationProcessingFilter;
    import org.springframework.security.util.TextUtils;
    import org.springframework.util.StringUtils;

    /**
     * Extends the default {
    @link AuthenticationProcessingFilter} to override the
     * <code>sendRedirect()</code> logic and always send absolute redirects.
     * 
     * 
    @author Tsuyoshi Yamamoto
     
    */
    public class GrailsAuthenticationProcessingFilter extends
            AuthenticationProcessingFilter {

        
    private String _ajaxAuthenticationFailureUrl;

        
    /**
         * {
    @inheritDoc}
         * 
         * 
    @see org.springframework.security.ui.AbstractProcessingFilter#doFilterHttp(javax.servlet.http.HttpServletRequest,
         *      javax.servlet.http.HttpServletResponse, javax.servlet.FilterChain)
         
    */
        @Override
        
    public void doFilterHttp(final HttpServletRequest request,
                
    final HttpServletResponse response, final FilterChain chain)
                
    throws IOException, ServletException {
            SecurityRequestHolder.set(request, response);
            
    try {
                
    super.doFilterHttp(request, response, chain);
            } 
    finally {
                SecurityRequestHolder.reset();
            }
        }

        
    /**
         * {
    @inheritDoc}
         * 
         * 
    @see org.springframework.security.ui.AbstractProcessingFilter#sendRedirect(javax.servlet.http.HttpServletRequest,
         *      javax.servlet.http.HttpServletResponse, java.lang.String)
         
    */
        @Override
        
    protected void sendRedirect(final HttpServletRequest request,
                
    final HttpServletResponse response, final String url)
                
    throws IOException {
            RedirectUtils.sendRedirect(request, response, url);
        }

        
    /**
         * {
    @inheritDoc}
         * 
         * 
    @see org.springframework.security.ui.AbstractProcessingFilter#determineFailureUrl(javax.servlet.http.HttpServletRequest,
         *      org.springframework.security.AuthenticationException)
         
    */
        @Override
        
    protected String determineFailureUrl(final HttpServletRequest request,
                
    final AuthenticationException failed) {
            String url 
    = super.determineFailureUrl(request, failed);
            
    if (getAuthenticationFailureUrl().equals(url)
                    
    && AuthorizeTools.isAjax(request)) {
                url 
    = StringUtils.hasLength(_ajaxAuthenticationFailureUrl) ? _ajaxAuthenticationFailureUrl
                        : getAuthenticationFailureUrl();
            }
            
    return url;
        }

        
    /**
         * Dependency injection for the Ajax auth fail url.
         * 
         * 
    @param url
         *            the url
         
    */
        
    public void setAjaxAuthenticationFailureUrl(final String url) {
            _ajaxAuthenticationFailureUrl 
    = url;
        }

        
    public Authentication attemptAuthentication(HttpServletRequest request)
                
    throws AuthenticationException {
            String inputValidationCode 
    = request.getParameter( "captcha" );
            
    //從Session中取出驗證碼
            String ssnValidationCode = (String)request.getSession().getAttribute( "captcha" );

            
    if( ssnValidationCode != null && !ssnValidationCode.equals( inputValidationCode.toUpperCase() ) ){
                
    //用戶輸入的值與看到的不一致,拋出異常
                throw new ValidationCodeException( "驗證碼輸入錯誤!");
            } 
            String username 
    = obtainUsername(request);
            String password 
    = obtainPassword(request);
            System.out.println(
    "testestesetsetestest:"+inputValidationCode);
            
    if (username == null) {
                username 
    = "";
            }

            
    if (password == null) {
                password 
    = "";
            }

            username 
    = username.trim();

            UsernamePasswordAuthenticationToken authRequest 
    = new UsernamePasswordAuthenticationToken(
                    username, password);

            
    // Place the last username attempted into HttpSession for views
            HttpSession session = request.getSession(false);

            
    if (session != null || getAllowSessionCreation()) {
                request.getSession().setAttribute(
                        SPRING_SECURITY_LAST_USERNAME_KEY,
                        TextUtils.escapeEntities(username));
            }

            
    // Allow subclasses to set the "details" property
            setDetails(request, authRequest);

            
    return this.getAuthenticationManager().authenticate(authRequest);
        }
    }

    然后再在這外包下面加一個類,其實就是拋出的一個異常類
    package org.codehaus.groovy.grails.plugins.springsecurity;
    import org.springframework.security.AuthenticationException;
    /**
    *
    */
    public class ValidationCodeException extends AuthenticationException {
        
    public ValidationCodeException(String s) {
            
    super(s);
        }
    }
    這樣就可以了,前臺加上代碼就行了。
    不過,這樣還不算玩,如果重做系統(tǒng)之類的,還得改,因為改的代碼保存是在C盤。這也讓我郁悶啊。這幾天換機子,機子壞,改了好幾遍了。
    記得FCKeditor有上傳圖片顯示不能顯示的問題,今天重先發(fā)布工程時,網(wǎng)上下載的fckeditor,沒改源碼也能正常使用了,有點因禍得福的感覺。

    天蒼蒼,野茫茫,風吹草底見牛羊

    只有注冊用戶登錄后才能發(fā)表評論。


    網(wǎng)站導航:
     

    posts - 80, comments - 24, trackbacks - 0, articles - 32

    Copyright © asdtiang

    asdtiang的博客 PaidMailz
    點擊廣告網(wǎng)賺A(每天4個廣告,每個0.0025美元,一個搜索廣告0.03美元)
    主站蜘蛛池模板: 亚洲AV美女一区二区三区| 亚洲乱码精品久久久久..| 成人爽A毛片免费看| 免费的一级片网站| 亚洲v国产v天堂a无码久久| 亚洲综合激情另类专区| 亚洲视频日韩视频| 亚洲国产精品ⅴa在线观看| A级毛片成人网站免费看| 最近中文字幕完整免费视频ww| 在线观看免费精品国产| 久久亚洲精品无码AV红樱桃| 人成电影网在线观看免费| 最好看的中文字幕2019免费| 亚洲精品国产第1页| 国产精品视频全国免费观看| 毛片免费vip会员在线看| 亚洲第一精品福利| 91久久成人免费| 亚洲性猛交XXXX| 边摸边吃奶边做爽免费视频99 | 亚洲午夜久久久精品影院| 日日摸日日碰夜夜爽亚洲| 24小时免费看片| 午夜亚洲AV日韩AV无码大全| 最近免费中文字幕mv在线电影| 亚洲一线产区二线产区精华| 日日摸夜夜添夜夜免费视频| 亚洲欧洲日产国码无码久久99| 麻豆成人久久精品二区三区免费| 亚洲精品线路一在线观看| 亚洲av无码一区二区三区天堂| 在线看片韩国免费人成视频| 亚洲国产精品成人精品无码区 | 日日夜夜精品免费视频| 国产免费播放一区二区| 亚洲国产精品成人综合久久久| 99爱在线观看免费完整版| 亚洲另类自拍丝袜第五页| 午夜一级免费视频| 野花香高清视频在线观看免费|