Grails Acegi 手动登录

发布于 2024-08-21 19:38:28 字数 60 浏览 2 评论 0原文

有没有办法在不使用“j_spring_security_check”的 POST 请求的情况下做到这一点?

Is there a way to do that without using a POST request to "j_spring_security_check"?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无悔心 2024-08-28 19:38:28

我需要同样的东西(在我的例子中,我想在用户创建新帐户后登录用户),所以我在生成的 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 构造函数将您使用的任何内容作为您的用户名/密码。

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
    }
}

Hope that helps.

Note: In my example, I use the email/password to login. The AuthToken constructor takes whatever you us as your username/password.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文