1
有沒有辦法做到這一點,而不使用POST請求「j_spring_security_check」?Grails Acegi手動登錄
有沒有辦法做到這一點,而不使用POST請求「j_spring_security_check」?Grails Acegi手動登錄
我需要同樣的事情(在我的情況,我想登錄的用戶,他們創造了一個新的帳戶之後),所以我在生成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
構造函數將您的任何我們作爲您的用戶名/密碼。
我如何使用哈希密碼? – Lucas
我不知道你如何做到這一點。我的第一個想法是嘗試和子類'UsernamePasswordAuthenticationToken',但我不知道多遠會讓你。什麼是用例?也許有另一種方式來做到這一點? –
如果您使用我在郵件列表中發佈的內容,它將使用哈希密碼,因爲它不需要調用authenticate()。 –