2010-11-01 108 views
3

我正在使用Spring MVC框架從ASP.NET中轉換我的Web應用程序(儘管通過以下方法學習它的好方法:))我需要在我的應用程序中實現身份驗證:請告訴我如果我的方法是好的和足夠專業,如果不是最好的做法是:Spring MVC 3.0基本身份驗證實現

首先,我寫的用戶類,其中包含有關當前用戶名/姓/電子郵件/ ID /等所有信息。 ...

class User implements Serializable{ 
private String firstName; 
private String lastName; 
private Long id; 
private String email; 

///Settters and Getters 

} 

我正在實施類名爲DlSession並在sesison級別上實現它。

<bean id="MySession" class="DlSession" scope="session"> 
<aop:scoped-proxy/> 

class DlSession implements Serializable{ 
private User currentUser; 

public DlSession(){} 

// getters and setters: 
} 

當用戶提交他的用戶名/密碼,我驗證憑據,如果用戶存在檢索所有的用戶數據的用戶類的實例。然後我設置currentUser在會話B I檢索的用戶:

mySesison.setCurrentUser(user); 

爲了驗證認證我需要檢查:

if (mySession.getcurrentUser() == null) 
//return unauthenticated 
else 
//return authenticated 

要註銷從系統用戶我只是在做:

mySession.setcurrentUser(null); 

這種方法是否正確?任何建議都更受歡迎。如果您已經使用用SpringMVC,你爲什麼不也用:)

回答