Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 742
Andrey Yaskulsky Avatar asked Jul 03 '26 21:07

Andrey Yaskulsky


1 Answers

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
      } 
}
like image 98
Lalit Agarwal Avatar answered Jul 05 '26 11:07

Lalit Agarwal



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!