当rejectIfNoRule = true时,Grails,无限循环

时间:2012-12-30 19:44:37

标签: grails

rejectIfNoRule = true时Grails应用中的无限循环问题 我尝试打开主页'/',我被重定向到'/ login / auth'并出现错误

  

错误310(net :: ERR_TOO_MANY_REDIRECTS):太多了   重定向。

似乎问题的根源位于org.codehaus.groovy.grails.plugins.springsecurity.RequestmapFilterInvocationDefinition.java中的initialize方法中,其中以下异常被静音。

Exception initializing; this is ok if it's at startup and due to GORM not being initialized yet since the first web request will re-initialize. Error message is "Cannot load Requestmaps, \"requestMap.className\" property is not set

不幸的是,第一个请求是带有无限循环的请求,那么如何初始化GORM的Requestmap?

环境:

  • Groovy版本:2.0.6
  • Grails 2.2.0
  • JVM:1.7.0_07供应商:Oracle Corporation
  • 操作系统:Linux
  • 弹簧安全核:1.2.7.3
  • 弹簧安全的UI:0.2

我的Config.groovy:

  • grails.plugins.springsecurity.securityConfigType =“Requestmap”
  • grails.plugins.springsecurity.rejectIfNoRule = true

Requestmaps:

new Requestmap(url: '/js/**', configAttribute: 'IS_AUTHENTICATED_ANONYMOUSLY').save()
new Requestmap(url: '/css/**', configAttribute: 'IS_AUTHENTICATED_ANONYMOUSLY').save()
new Requestmap(url: '/images/**', configAttribute: 'IS_AUTHENTICATED_ANONYMOUSLY').save()
new Requestmap(url: '/login/**', configAttribute: 'IS_AUTHENTICATED_ANONYMOUSLY').save()
new Requestmap(url: '/logout/**', configAttribute: 'IS_AUTHENTICATED_ANONYMOUSLY').save()
new Requestmap(url: '/', configAttribute: 'IS_AUTHENTICATED_ANONYMOUSLY').save()

1 个答案:

答案 0 :(得分:3)

  

错误消息是“无法加载请求图”,“requestMap.className \”属性未设置

这就是您的错误的原因 - 当您在数据库中存储请求映射时,您需要Config.groovy中的条目告诉spring安全插件Requestmap域类的名称

grails {
  plugins {
    springsecurity {
      securityConfigType = SecurityConfigType.Requestmap

      // fully qualified class name of the Requestmap class
      requestMap.className = 'com.example.Requestmap'

      // these next two are the defaults but good to make them explicit anyway
      requestMap.urlField = 'url'
      requestMap.configAttributeField = 'configAttribute'
    }
  }
}