Andrey Yaskulsky
Andrey Yaskulsky

Reputation: 2516

grails spring security post authentication

I use spring security core plugin. I want to put an object in session just after user has logged in. What I've discovered so far is that there is grails.plugin.springsecurity.LoginController in the plugin. And it has method which is called ajaxSuccess which seems to be invoked just after successfull authentication. So I decided to create another LoginController which extends default one and overrides this method:

@Secured('permitAll')
class LoginController extends grails.plugin.springsecurity.LoginController {


    def ajaxSuccess() {
        session['somevproperty'] = someValue 
        super.ajaxSuccess()
    }

}

but debugging shows that this method is never invoked. What is going wrong? May there is another way to do what I want? Thank you!

Upvotes: 3

Views: 816

Answers (1)

Lalit Agarwal
Lalit Agarwal

Reputation: 2354

Spring security has it own event listeners. I prefer you use that.

http://grails-plugins.github.io/grails-spring-security-core/guide/events.html

Sample code from above link for success login.

package com.foo.bar

import org.springframework.context.ApplicationListener  
import org.springframework.security.authentication.event. AuthenticationSuccessEvent

class MySecurityEventListener implements ApplicationListener<AuthenticationSuccessEvent> {

      void onApplicationEvent(AuthenticationSuccessEvent event) { 
      // handle the event
      } 
}

Upvotes: 6

Related Questions