2009年10月29日木曜日

Grails+Acegi プログラム上でログイン・ログアウトさせる

Grailsのバージョンは1.2-M3
Acegi Security は 0.5.2

忘れないうちにメモ

import org.springframework.security.providers.UsernamePasswordAuthenticationToken as AuthToken
import org.springframework.security.context.SecurityContextHolder as SCH

class NantokaService {
    def daoAuthenticationProvider

    // ログイン処理
    void systemLogin(String username, String password) {
        def auth = new AuthToken(username, password)
        def authtoken = daoAuthenticationProvider.authenticate(auth)
        SCH.context.authentication = authtoken
    }
    // ログアウト処理
    void systemLogout() {
        SCH.context.authentication = null
    }
}

こんな感じ

0 件のコメント:

コメントを投稿

注: コメントを投稿できるのは、このブログのメンバーだけです。