Grails的Acegi的手动登录 [英] Grails Acegi manual login
本文介绍了Grails的Acegi的手动登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法做到这一点不使用POST请求j_spring_security_check?
Is there a way to do that without using a POST request to "j_spring_security_check"?
推荐答案
我需要同样的事情(在我的情况,我想登录用户,他们创造了一个新的帐户后),所以我在生成的RegistrationService挖四周,发现这是它是如何做的:
I needed the same thing (in my case I wanted to log in a user after they created a new account), so I dug around in the generated RegistrationService and found this is how it is done:
import org.springframework.security.providers.UsernamePasswordAuthenticationToken as AuthToken
import org.springframework.security.context.SecurityContextHolder as SCH
class UserService {
/** The authentication provider. */
def daoAuthenticationProvider
def doLogin(user) {
// note: must use the unhashed password here
def token = new AuthToken(user.email, user.password)
def auth = daoAuthenticationProvider.authenticate(token)
// log the user in
SCH.context.authentication = auth
}
}
希望有所帮助。
请注意:在我的例子中,我使用的电子邮件/密码登录。在的authToken
构造函数无论你我们作为您的用户名/密码。
Note: In my example, I use the email/password to login. The AuthToken
constructor takes whatever you us as your username/password.
这篇关于Grails的Acegi的手动登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文