security - Grails Acegi手动登录

标签 security authentication grails spring-security grails-plugin

有没有一种方法,而无需使用对“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/

相关文章:

authentication - 为什么我在调用 Yahoo 联系人 API 时会收到 HTTP 401 Unauthorized?

grails - 如何正确使用Grails插件

json - Grails 2 - 自动生成 JSON 输出(就像 Spring 3.x 那样)

spring - 如何将 Grails 服务导出到 jar 中,并在其他 java 应用程序中使用该 jar?

javascript - Chrome 扩展中的 Chrome.extension.getURL 和 AJAX 安全问题

.net - .Net 上的授权和权利解决方案,就像之前在 AzMan 中一样

ASP.NET -> WCF 服务需要 Windows 身份验证

javascript - Web 应用程序访问用户的文件系统

java - Shiro Security,多个领域,哪些授权信息被获取?

authentication - 用于存储身份验证信息的 Golang 数据库