GWT中 SS3内部认证。

 GWT中 通过RPC方式,post提交 j_username,j_password。

String url = GWT.getHostPageBaseURL()+"j_spring_security_check";
RequestBuilder rb = new RequestBuilder(RequestBuilder.POST, URL.encode(url));
rb.setTimeoutMillis(50000);  
rb.setHeader("Content-Type", "application/x-www-form-urlencoded");   
String form = "j_username="+userName.getValue()+"&j_password="+password.getValue();   
try {
Request request = rb.sendRequest(form, new RequestCallback() {

public void onError(Request req, Throwable exception) {
GWT.log("认证加载失败");
MessageBox.alert(
i18N.loginError(),
i18N.serviceError() + " : "
null);

						}
@Override
public void onResponseReceived(Request request,Response response) {
			
if (response.getStatusCode() == Response.SC_UNAUTHORIZED) {
GWT.log("认证失败"+response.getStatusText());								
MessageBox.alert(i18N.loginFailed(),i18N.nameOrPWDError(), null);
} else if (response.getStatusCode() == Response.SC_OK) {
GWT.log("认证成功"+response.getStatusText());
response.getStatusText();
LoginDialog.this.fireEvent(loginCheck);
} else {GWT.log("非认证信息"+response.getStatusText());
}
}
});
} catch (RequestException e) {}

 重写认证成功,失败接口。GWTAuthenticationFailureHandler implements AuthenticationFailureHandler 

logger.debug("Authentication Failed: " + "认证失败");
response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Authentication Failed: " + exception.getMessage());

GWTAuthenticationSuccessHandler implements  AuthenticationSuccessHandler

logger.debug("Authentication successful");   
response.sendError(HttpServletResponse.SC_OK,authentication.getName());

 UsernamePasswordAuthenticationFilter

配置applicationContext-security.xml文件。

配置成功认证,失败认证处理类。

GWTAuthenticationSuccessHandler

GWTAuthenticationFailureHandler

自定义filter  ValidateCodeUsernamePasswordAuthenticationFilter

<custom-filter ref="validateCodeAuthenticationFilter"   position="FORM_LOGIN_FILTER" />

相关推荐