Announcement Announcement Module
Collapse
No announcement yet.
plugins Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • plugins

    Is it possible to reference the application's config? What I'd like to be able to do is use config parms in my plugin that should be defined in the application. Simple example would be an application name.

    Specifically what I'd like to be able to do is reference config.groovy settings of the application in the doWithSpring closure.

    I tried the following:

    def doWithSpring = {
    def conf = ConfigurationHolder.config
    def securityConf = SpringSecurityUtils.securityConfig

    oracleDataSource(DataSourceForOracleAndSpring) {
    dataSource = ref("dataSource")
    applicationName = conf.application.name
    moduleName = conf.application.module
    }
    }

    I thought this would work after looking at how the core security plugin did it but this gives me the following error:

    Cannot convert value of type [groovy.util.ConfigObject] to required type [java.lang.String] for property 'moduleName': no matching editors or conversion strategy found

    which I believe is caused by the fact that the property value is not there.

    Another question. when creating the plugin project it created a config.groovy. Do both config.groovy files get merged? Does the plugin only have access to its own.

    I've been reading the plugin developer docs but have not found specific answers to these questions (as of yet).

    thx, Claude

  • #2
    If a value isn't available in the config then it'll create a ConfigObject. Since ConfigObject implements Map and starts out empty, you can use "Groovy Truth" to provide default values, e.g.

    Code:
    def doWithSpring = {
       def conf = ConfigurationHolder.config
       def securityConf = SpringSecurityUtils.securityConfig
    
       oracleDataSource(DataSourceForOracleAndSpring) {
          dataSource = ref("dataSource")
          applicationName = conf.application.name
          moduleName = conf.application.module ?: ''
       }
    }
    or if there's no default and you don't want to set any value:

    Code:
    def doWithSpring = {
       def conf = ConfigurationHolder.config
       def securityConf = SpringSecurityUtils.securityConfig
    
       oracleDataSource(DataSourceForOracleAndSpring) {
          dataSource = ref("dataSource")
          applicationName = conf.application.name
          if (conf.application.module) {
             moduleName = conf.application.module
          }
       }
    }
    The plugin uses Config.groovy to manage its settings. This makes it easy to be environment-aware and support external configs since that's already supported in Config.groovy. It's not really documented since the config isn't typically used outside of the plugin. Basically what happens is DefaultSecurityConfig.groovy is loaded, then the values from Config.groovy are merged in to let the user specify missing values and override defaults.

    All values start with grails.plugins.springsecurity, so as a convenience SpringSecurityUtils.securityConfig returns the security sub-config. So for example SpringSecurityUtils.securityConfig.userLookup.user DomainClassName and ConfigurationHolder.config.grails.plugins.springse curity.userLookup.userDomainClassName are the same values.

    Comment


    • #3
      Thanks Burt!

      I resolved the issue with modulename - silly me I'm thinking I'm setting properties in a props file or xml and not enclosing my string in quotes in the groovy script!

      Still not able to achieve what I'd like though. I am using a plugin project to modularise our group's code - create a 'shared code' plugin - that apps can plug into to instantly have security amongst other things preconfigured for our needs so no need to reinvent the wheel (or copy it) in each app.

      When I try to place the sping security config I require into the plugin projects config.groovy it does not work.

      Here's the setup:
      - plugin project which has spring security installed
      - application project with inplace reference to plugin project in STS

      Scenario A:
      Security plugin config I require in config.groovy of PLUGIN project - FAILS

      Scenario B:
      Security plugin config in config.groovy of APP project - SUCCESS.

      Should scenario A work? Perhaps this is an STS issue.

      thanks for any help or suggestions,
      Claude

      Comment

      Working...
      X