2015-01-08 51 views
0

我有一個使用Spring Security進行身份驗證的Spring MVC web應用程序。我有一個註冊頁面,並且在用戶成功輸入所有的細節後,我希望他們能夠使用剛輸入的信息自動登錄。我怎樣才能做到這一點?從服務器端驗證Spring Security

回答

1

這可以通過在處理用戶詳細信息時手動設置Authentication對象來完成。下面是代碼:

List<GrantedAuthority> grantedAuths = new ArrayList<GrantedAuthority>(); 
Authentication a = new UsernamePasswordAuthenticationToken(newUsername, newPassword, grantedAuths); 
SecurityContextHolder.getContext().setAuthentication(a);` 

其中新用戶和新密碼是兩個字符串,註冊用戶的憑據