title: override method of Grails plugin bean
body: <p>The Spring Security plugin provides a bean named 'springSecurityService' of type <code>grails.plugins.springsecurity.SpringSecurityService</code>. I need to override the <code>getCurrentUser</code> method of this service.</p>
  
  <p>I first tried to do it using extension</p>
  
  <pre><code>class CustomSecurityService extends SpringSecurityService {
  
      @Override
      Object getCurrentUser() {
          // my implementation uses methods from the parent class
      }
  }
  </code></pre>
  
  <p>To replace the bean defined by the plugin with an instance of the class above I added the following to <code>resources.groovy</code></p>
  
  <pre><code>springSecurityService(CustomSpringSecurityService)
  </code></pre>
  
  <p>But this didn't work because none of the dependencies of <code>SpringSecurityService</code> (the class I'm extending) are set so I get NullPointerExceptions. The reason these dependencies are not set is because there's no longer a spring bean of type <code>SpringSecurityService</code></p>
  
  <p>So, I then turned to delegation:</p>
  
  <pre><code>import grails.plugins.springsecurity.SpringSecurityService as PluginSpringSecurityService
  
  class CustomSpringSecurityService {
  
      @Autowired @Delegate
      PluginSpringSecurityService pluginSpringSecurityService
  
      Object getCurrentUser() {
          // my implementation uses methods from pluginSpringSecurityService
      }
  }
  </code></pre>
  
  <p>I then defined two beans in <code>resources.groovy</code></p>
  
  <pre><code>springSecurityService(CustomSpringSecurityService)
  pluginSpringSecurityService(grails.plugins.springsecurity.SpringSecurityService)
  </code></pre>
  
  <p>In this second attempt, I again want the bean named 'springSecurityService' to refer to <code>CustomSpringSecurityService</code>, but I also need a bean of type <code>grails.plugins.springsecurity.SpringSecurityService</code>, because my implememtation of <code>getCurrentUser</code> use some other methods of that bean.</p>
  
  <p>However, I again found that the dependencies of <code>pluginSpringSecurityService</code> are not being set. Is there an easier way to override a method of a bean provided by a plugin in a context that is subject to dependency injection?</p>