有没有一种方法,而无需使用对“j_spring_security_check”的POST请求?
最佳答案
我需要做同样的事情(在我的情况下,我想在用户创建新帐户后登录用户),因此我在生成的RegistrationService中进行了挖掘,发现这样做是这样的:
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
构造函数将您的身份用作用户名/密码。
关于security - Grails Acegi手动登录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2268266/