Grails easyb plugin and injecting services

6 views
Skip to first unread message

Darran

unread,
Oct 22, 2009, 9:22:57 AM10/22/09
to Easyb Users
Is there a way of injecting services into the easyb scripts for the
Grails plugin?
For example I`m using the spring security plugin so I`d like to do
something like.

def authenticateService


before "create data model",{
def role = new Role(authority:'ROLE_ADMIN',description:'Admin
role').save();
def encodedPass = authenticateService.encodePassword('password')
def newUser = new User(username:'TEST',
userRealName:'real name test',
passwd:encodedPass,
enabled:true,
email:'te...@test.com',
emailShow:true)

newUser.addToAuthorities(role)
newUser.save()
}

Andy

unread,
Oct 22, 2009, 4:53:56 PM10/22/09
to Easyb Users
Yes -- the easyb plug-in model supports this behavior -- you can
create a plug-in that hooks into the before aspect of a story or a
scenario that can then execute that code. See this wiki page:
http://code.google.com/p/easyb/wiki/PluginAPI

On Oct 22, 9:22 am, Darran <darran.m.wh...@googlemail.com> wrote:
> Is there a way of injecting services into the easyb scripts for the
> Grails plugin?
> For example I`m using the spring security plugin so I`d like to do
> something like.
>
> def authenticateService
>
> before "create data model",{
>     def role = new Role(authority:'ROLE_ADMIN',description:'Admin
> role').save();
>         def encodedPass =  authenticateService.encodePassword('password')
>         def newUser = new User(username:'TEST',
>                         userRealName:'real name test',
>                         passwd:encodedPass,
>                         enabled:true,
>                         email:'t...@test.com',
>                         emailShow:true)
>
>         newUser.addToAuthorities(role)
>         newUser.save()
>
> }

Darran

unread,
Oct 23, 2009, 11:22:05 AM10/23/09
to Easyb Users
I was thinking it might be quite good if the grails plugin took care
of this for you.
It could inject ,via a easyb plugin, the GrailsApplication so you
could access the Grails runtime like you do when creating Grails
plugins.
That way you should be able to get services if you needed them by
accessing application context. It would also expose other
functionality as defined in the Grails JDocs for GrailsApplication.

After installing the grails easyb plugin you could maybe get the
application context via GrailsApplication to get any service you
wanted.
e.g

before "create data model",{
def authenticateService = application.getMainContext().getBean
("AuthenticateService")
.....
}

Not sure if its possible or how easy it is to do.
Ideally some form of dependency injection would be better but I`m not
sure if you could do this into the easyb script
Reply all
Reply to author
Forward
0 new messages