0

My app architecture is like so:

MainWebApp 
  -> CustSecPlugin
    -> Spring-Security-Core

So I have a plugin that I wrap around the spring-security plugins to provide extra implementation that is common across a number of web apps. One of the things I do is use a custom UserDetailsService.

I have follow the guides for this and can get my custom security plugin running in standalone when the beans for the custom user details are defined in grails-app/conf/spring/resources.groovy

This file doesn't get read since its a plugin so I moved the beans into the doWithSpring {} closure. This still works when ran standalone.

However what I am now finding is that when run with the webapp, my custom details service is ignored, and the Principal is now a standard GrailsUser

If i take my bean definitions and move them into the web-app's grails-app/conf/spring/resources.groovy then it works. However I don't want to have to define these beans in every app that uses this plugin

I'm not sure what is happening. Why would the userDetailsService() bean be ignored when its ran as a plugin in a web app? I can see other beans are being set properly (printed out all bean names and made myself a dummy bean). Its almost like its getting set back again.

Is there any where I could define this bean to make it definitely work?

How is the best way to get around this?

Benoit Wickramarachi
  • 6,096
  • 5
  • 36
  • 46
DJOodle
  • 323
  • 2
  • 16

1 Answers1

1

This is probably the load order of the plugins. You can change it in your plugin descriptor with:

def loadAfter = ["springSecurityCore"]

This will enforce that your beans will be loaded after the core plugin.

  • The only issue i have is my inner plugin sets up the configuration parrams for the security-core plugin. And what I'm finding is if my wrapper plugin loads after core, the configuration doesn't get set properly and the plugin fails to load. Is there any other place in my plugin I could declare the beans? – DJOodle Nov 29 '13 at 09:25
  • For configurations normally I use the plugin [Platform Core](http://grails.org/plugin/platform-core). It have a closure `doWithConfig` to declare configurations that will be merged with the application. –  Nov 29 '13 at 10:05
  • Ah a combination of platform core and the loadAfter solved my problem, hadn't seen this plugin before. Cheers – DJOodle Dec 10 '13 at 09:16