閑話不多說,直接上代碼吧:
第一:如何更改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,沒改源碼也能正常使用了,有點因禍得福的感覺。
天蒼蒼,野茫茫,風吹草底見牛羊