title: Grails 2 can't login with spring security when using multiple databases
body: <p>On Grails 2.0.3, I installed Spring Security Core and created the User, UserRole and Role objects as per the tutorial: <a href="http://blog.springsource.org/2010/08/11/simplified-spring-security-with-grails/" rel="nofollow">http://blog.springsource.org/2010/08/11/simplified-spring-security-with-grails/</a></p>
  
  <p>All went fine until I decided to add a second datasource in preparation for accessing objects from a different database.  DataSource.groovy looks like this:</p>
  
  <pre><code>test {
      dataSource_product {
          dbCreate = "update"
          url = "jdbc:mysql://localhost/products"
          pooled = true
          driverClassName = "com.mysql.jdbc.Driver"
          username = "blah"
          password = "blah"
          loggingSql = true
          dialect = 'org.hibernate.dialect.MySQL5InnoDBDialect'
      }
      dataSource {
          dbCreate = "update"
          url = "jdbc:mysql://localhost/core"
          pooled = true
          driverClassName = "com.mysql.jdbc.Driver"
          username = "blah"
          password = "blah"
          loggingSql = true
          dialect = 'org.hibernate.dialect.MySQL5InnoDBDialect'
      }
  }
  </code></pre>
  
  <p>Now I can't log in - even though all I have done is add datasource_product. If I comment this out and recreating the users (in Bootstrap.groovy) then I can log in again. Bootstrap.groovy contains:</p>
  
  <pre><code>def init =
  { servletContext -&gt;
  
      // Add in roles
      Role.withTransaction { 
          def adminRole = Role.findByAuthority ( Role.ROLE_ADMIN ) ?: new Role ( authority: Role.ROLE_ADMIN ).save ( failOnError: true )
  
          def adminUser = User.findByUsername ( 'admin' ) ?: new User (
                  username: 'blah',
                  password: 'blah',
                  enabled: true ).save ( failOnError: true )
          if ( !adminUser.authorities.contains ( adminRole ) ) UserRole.create ( adminUser, adminRole )
  }
  </code></pre>
  
  <p>Any ideas?</p>