2012-03-30 106 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

相关问题