如何以编程方式使用Spring Security 3.1登录用户 [英] How to programmatically log user in with Spring Security 3.1

查看:143
本文介绍了如何以编程方式使用Spring Security 3.1登录用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Spring和Spring Security 3.1中以特定的用户名以编程方式登录Web访问者的正确方法是什么?在2.5以下的情况下,我的处理方式似乎发生了一些变化.我敢肯定,现在有一种更好的方法.

What's the proper way to programmatically log a web visitor in under a particular username in Spring and Spring Security 3.1? It seems the way I was doing it under 2.5 has changed a little. I'm sure there's a much better way of doing this now.

基本上,当我创建一个新用户时,我还需要同时登录它们.

Basically, when I create a new user, I need to also log them in at the same time.

推荐答案

创建一个Authentication(通常是UsernamePasswordAuthenticationToken),然后调用

Create an Authentication (usually a UsernamePasswordAuthenticationToken) and then call

SecurityContextHolder.getContext().setAuthentication(authentication)

这篇关于如何以编程方式使用Spring Security 3.1登录用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆