(Quick Reference)

2 Configuration - Reference Documentation

Authors: David Estes

Version: 0.6.1

2 Configuration

The Security-Bridge is kept relatively simple so as to not overcreep on scope. All that needs to be done is to define a security bridge and register this as a spring bean.

The interface is as follows:

package org.grails.plugin.securitybridge

interface SecurityBridge {

/** * Returns the current user object if they are logged in * @return the implementation's user object or null if nobody is logged in */ def getCurrentUser()

/** * Get the user Identifier. * @return the user identity or null if nobody is logged in */ def getUserIdentity()

/** * Returns the current account object of the logged in user * @return the implementation's account (for basic auth can just be the user object) object or null if nobody is logged in */ def getCurrentAccount()

/** * Returns the current users account identity. (Useful if multiple users are tied to one account) * @return the account name or identity, null if nobody is logged in. */ def getAccountIdentity()

/** * Return the current users display name. */ def getCurrentUserDisplayName()

/** * Check if the user is currently logged in. */ boolean isLoggedIn()

/** * Check if the currently logged in user is authorized to perform an action on the passed object * @param object The object with which we are dealing with. * @param action The action you would like to perform */ boolean isAuthorized(object, action)

/** * Check if the currently logged in user has the specified role * @param role */ boolean hasRole(role)

/** * Check if the currently logged in user has the specified permission * in any of his/her assigned roles. * @param permission the name of the permission to check * @param opts depending on then permissions model, this can be used to add * configurability to permission. */ boolean hasPermission(permission, opts)

/** * Check if the currently logged in user has the specified permission * in any of his/her assigned roles. * @param permission the name of the permission to check */ boolean hasPermission(permission)

/** * Store the request location for the security service to redirect to upon login success * @param request The request object */ def storeLocation(request)

/** * Execute code masquerading as the specified user, for the duration of the Closure block * @return Whatever the closure returns */ def withUser(identity, Closure code)

/** * Create a link to the specified security action * @param action One of "login", "logout", "signup" * @return Must return a Map of arguments to pass to g:link to create the link */ Map createLink(String action) }

It is best to create a security bridge that extends the AbstractSecurityBridge class which default implements some of these methods so you do not necessarily have to implement all of them.

Simply implementing a class that defines all these methods will create a legitimate securityBridge. Next we need to register this bridge with spring. This can be done in your application's resources.groovy file or in a plugins doWithSpring method.

sharedSecurityBridge(com.mycompany.MySecurityBridge) {
  //Add any other spring injected references you may need
  springSecurityService = ref('springSecurityService')
}