2013-06-27 3 views
1

Grails 애플리케이션에서 사용자가 성공적으로 등록한 후 처음 로그인 한시기를 알고 싶습니다. 스프링 보안 코어 플러그인을 사용하고 있습니다. 이것을 수행하는 가장 좋은 방법은 무엇입니까?grails에 등록한 후 첫 번째 연결 감지

+0

http://grails.1312388.n4.nabble.com/How-to-configure-Spring-Security-redirect-url-after-login-td3235600.html –

답변

2

등록 후 사용자를 자동으로 로그인하지 않거나 사용자가 등록 직후에 수동으로 로그인한다는 사실을 알지 못하는 경우 각 사용자에게 "lastLoginDate"와 같은 것을 보관해야 할 것입니다. 그런 다음 해당 값이 비어 있는지 (처음 로그인하는 경우) 확인하십시오. 그렇지 않으면 로그인 할 때마다 로그인 날짜를 업데이트하십시오.

성공적인 로그인 후 해고 된 이벤트 중 하나에이 코드를 넣을 수 있습니다.

는 의견

grails.plugins.springsecurity.onInteractiveAuthenticationSuccessEvent = { e, appCtx -> 
    // fired after successful authentication 
    // and AFTER user info provided to SpringSecurityService 

    // to get currentUser, you can use the following 
    def springSecurityService = appCtx.getBean("springSecurityService") 
    def user = springSecurityService.currentUser 
    ... 
} 


or 

grails.plugins.springsecurity.onAuthenticationSuccessEvent = { e, appCtx -> 
    // fired after successful authentication 
    // and BEFORE user info provided to SpringSecurityService 
    // (e.g. springSecurityService.currentUser == null) 
} 

더 많은 정보 이벤트 아래 SpringSecurity documentation에서 찾을 수 있습니다를 기반으로 업데이트되었습니다.

+0

config.groovy에서 서비스를 사용할 수 있습니까? 그래서 springSecurityService.getCurrentUser()를 호출 할 수 있습니까? –

+0

잘 모르겠지만 springSecurityService를 삽입 할 수 있다면 - springSecurityService는 onAuthenticationSuccessEvent의 사용자에 대해 currentUser를 가지지 않을 것임을 주목하십시오. 대신 onInteractiveAuthenticationSuccessEvent를 사용해야합니다. – ikumen

+0

나는 이것을 config.groovy에 넣으려고했으나, 두 가지 방법의 코드를 로그인 할 때 –

관련 문제