2012-03-30 46 views

回答

19

事情是這樣的:

Authentication authentication = new UsernamePasswordAuthenticationToken(person, null, person.getAuthorities()); 
log.debug("Logging in with {}", authentication.getPrincipal()); 
SecurityContextHolder.getContext().setAuthentication(authentication); 

哪裏person是你UserDetailsBean對象。

+0

非常感謝!這很好。 – 2012-03-30 20:18:07

+1

請注意,只有當您的登錄路徑使用以下類型'''的安全映射時,這纔有效。在更新版本的spring security中,一種更好,更快速的跳過安全措施的方式。 ''s:http security =「none」pattern =「/ assets/**」/>'使用新格式,給定的解決方案將不起作用,因爲在後面的場景中沒有創建SecurityContextHolder。 – 2012-11-11 18:59:38

+0

@vaccum將用於http基本身份驗證 – 2016-08-18 06:02:32

相關問題