Security Grails Acegi手动登录
有没有一种不使用POST请求“j_spring_security_check”的方法可以做到这一点 我也需要同样的东西(在我的例子中,我想在用户创建新帐户后登录),所以我在生成的RegistrationService中翻了翻,发现是这样做的:Security Grails Acegi手动登录,security,authentication,grails,spring-security,grails-plugin,Security,Authentication,Grails,Spring Security,Grails Plugin,有没有一种不使用POST请求“j_spring_security_check”的方法可以做到这一点 我也需要同样的东西(在我的例子中,我想在用户创建新帐户后登录),所以我在生成的RegistrationService中翻了翻,发现是这样做的: import org.springframework.security.providers.UsernamePasswordAuthenticationToken as AuthToken import org.springframework.securi
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
构造函数将您使用的任何东西作为用户名/密码。我如何使用哈希密码?我不确定您如何使用。我的第一个想法是尝试将UsernamePasswordAuthenticationToken
子类化,但我不确定这会让您走多远。用例是什么?也许还有另一种方法?如果您使用我在邮件列表上发布的内容,它将使用哈希密码,因为它不需要调用authenticate()。