Issue Details (XML | Word | Printable)

Key: GRAILSPLUGINS-387
Type: New Feature New Feature
Status: Open Open
Priority: Major Major
Assignee: Graham Bakay
Reporter: Nick Pellow
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Grails Plugins

Provide a callback on successful login

Created: 27/May/08 06:24 AM   Updated: 04/Sep/08 11:51 PM
Component/s: Grails-Crowd
Affects Version/s: Grails-Crowd 0.3
Fix Version/s: None

Time Tracking:
Not Specified


 Description  « Hide
It would be great to be able to register a "Crowd Event Listener" which can receive notification of successful and unsuccessful login attempts.

For example, I would really like to create and save User object when that user has been successfully authenticated by Crowd.



 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
Graham Bakay added a comment - 19/Aug/08 10:58 AM
Ooo. That would be pretty cool. I'll see if I can't figure out the Grails event lifecycle (I imagine it's Spring-like) so we could add something like this. If you have any ideas (or code) Nick, please let me know.

Kate Ellingburg added a comment - 04/Sep/08 11:51 PM
Nick, you could possibly achieve this using a filter (ie without requiring changes to the plugin). Create a class called ApplicationFilters in grails-app\conf:
import org.codehaus.grails.plugins.crowd.util.CrowdAuthUtils

class ApplicationFilters {

    def dependsOn = [crowd:0.3]
    
    def filters = {
        saveUser(controller:'*', action:'*') {
            after = {
                if (CrowdAuthUtils.isAuthenticated(request)) {
                    if (!session.usersaved) {
                        println 'saving user'
                        session.usersaved = true
                    }
                }
            }
        }    
    }
}

Of course, I'm thinking you'll be doing something other than println 'saving user'

There still might be a more elegant solution to this problem – using a session variable to track whether the user has been saved or not may be a little uncool, plus, I'm not loving having to put the version of the crowd plugin in dependsOn.