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" />

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值