有没有一种方法,而无需使用对“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构造函数将您的身份用作用户名/密码。


评论关闭
IT序号网

微信公众号号:IT虾米 (左侧二维码扫一扫)欢迎添加!