(Quick Reference)

5 Customization - Reference Documentation

Authors: Igor Artamonov (igor@artamonov.ru)

Version: 0.17

Table of Contents

5 Customization

5.1 Using FacebookAuthService

How it works

If you need to add some specific logic to default plugin behaviour you have to create your own service called `FacebookAuthService`. Plugin will check for know methods of this service, and if they're exist - use them instead of own.

It's some kind of extending an abstract class. You don't need to create all methods, just what you need.

Used objects:

  • <FacebookUser> - domain class for your facebook user. It's your own class, can have other name, it's just a example
  • <Person> - general user, used by Spring Security. It's your own class, can have other name, it's just a example
  • FacebookAuthToken - token provided by plugin

<FacebookUser> and <Person> can be same object, or can be two different object (with a relation), depends on your architecture.

Take a look at sources

Please, take a look at sources of DefaultFacebookAuthDao to understand how it works, and which methods you can use for customization

List of possible methods:

void onCreate(<FacebookUser> user, FacebookAuthToken token)

Called after user was created by plugin, just before saving into database. You can fill user object with some extra values.

Not called if you have implemented method create(..)

Where:

  • user - your domain for Facebook User
  • token - com.the6hours.grails.springsecurity.facebook.FacebookAuthToken

void afterCreate(<FacebookUser> user, FacebookAuthToken token)

Called after user was created by plugin, and when it's already saved into database.

Not called if you have implemented method create(..)

Where:

  • user - your domain for Facebook User
  • token - com.the6hours.grails.springsecurity.facebook.FacebookAuthToken

<FacebookUser> findUser(long uid)

Called when facebook user is authenticated (on every request), must return existing instance for specified facebook uid, if exits. If doesn't - return null

Where:

  • uid - facebook user id

<FacebookUser> create(FacebookAuthToken token)

Called when we have a new facebook user, called on first login to create all required data structures.

Where:

  • token - com.the6hours.grails.springsecurity.facebook.FacebookAuthToken

Notice, that if you have such method, all other method for user creation will no be called:

  • createAppUser
  • prepopulateAppUser
  • onCreate
  • afterCreate
  • createRoles

<Person> createAppUser(<FacebookUser> user, FacebookAuthToken token)

Called when we have a new facebook user, called on first login to create main app User domain (when we store Facebook User details in different domain).

Not called if you have implemented method create(..)

Where:

  • user - your domain for Facebook User
  • token - com.the6hours.grails.springsecurity.facebook.FacebookAuthToken

void createRoles(<FacebookUser> user)

Called when we have a new facebook user, called on first login to create roles list for new user

Where:

  • user - your domain for Facebook User

def getPrincipal(<FacebookUser> user)

Must return object to store in security context for specified facebook user (can return itself)

Where:

  • user - your domain for Facebook User

<FacebookUser> getFacebookUser(<Person> person)

Must return instance of your domain object for facebook user for specified person (if it's not a same object)

Where:

  • person - your domain for <Person>

Collection<GrantedAuthority> getRoles(<Person> user)

Must return roles list for specified user

Where:

  • user - your domain for Facebook User

void prepopulateAppUser(<Person> person, FacebookAuthToken token)

Must return roles list for specified facebook user

Where:

  • person - your domain for <Person>
  • token - com.the6hours.grails.springsecurity.facebook.FacebookAuthToken

How to use