我目前正在Grails应用程序上工作,并将Spring Security框架与Core和UI插件一起使用。

几乎所有功能都可以正常工作:用户创建,编辑,删除等。唯一的问题是requestmap,它不能正常工作。当我调用requestmap / create时,出现以下错误:

URI /xxx/requestmap/create
Class java.lang.NullPointerException
Message Cannot get property 'clazz' on null object

Around line 81 of grails-app/controllers/grails/plugins/springsecurity/ui/AbstractS2UiController.groovy
78: }
79:
80: protected Class<?> lookupRequestmapClass() {
81:     grailsApplication.getDomainClass(lookupRequestmapClassName()).clazz
82: }
83:}

我在Config.groovy中配置了Spring Security,如下所示:
grails.plugins.springsecurity.userLookup.userDomainClassName = 'xxx.User'
grails.plugins.springsecurity.userLookup.authorityJoinClassName = 'xxx.UserRole'
grails.plugins.springsecurity.authority.className = 'xxx.Role'
grails.plugins.springsecurity.requestMap.className = 'Requestmap'
grails.plugins.springsecurity.securityConfigType = grails.plugins.springsecurity.SecurityConfigType.Requestmap

我还在BuildConfig.groovy中使用以下插件:
plugins {
    runtime ":hibernate:$grailsVersion"
    runtime ":resources:1.1.6"

    // Uncomment these (or add new ones) to enable additional resources capabilities
    //runtime ":zipped-resources:1.0"
    //runtime ":cached-resources:1.0"
    //runtime ":yui-minify-resources:0.1.4"

    build ":tomcat:$grailsVersion"
    runtime ":database-migration:1.1"
    compile ':cache:1.0.0'

    // Spring Security Core
    compile ":spring-security-core:1.2.7.3"

    // Spring Security UI (+ Dependencies)
    compile ":spring-security-ui:0.2"
    compile ":mail:1.0"
    runtime ":jquery:1.7.2"
    compile ":jquery-ui:1.8.15"
    compile ":famfamfam:1.0.1"

    // Twitter Bootstrap
    // exlude is workaround for svn issue with bootstrap and grails 2.1.x
    compile (":twitter-bootstrap:2.0.2.25") { excludes 'svn' }
    runtime ':fields:1.3'
}

出现requestmap搜索表单,但搜索时引发异常:
URI /xxx/requestmap/requestmapSearch
Class org.hibernate.hql.ast.QuerySyntaxException
Message xxx.Requestmap is not mapped [SELECT COUNT(DISTINCT r) FROM xxx.Requestmap r WHERE 1=1 ]
Around line 46 of grails-app/controllers/grails/plugins/springsecurity/ui/RequestmapController.groovy
43:         }
44:     }
45:
46:     int totalCount = lookupUserClass().executeQuery("SELECT COUNT(DISTINCT r) $hql", queryParams)[0]
47:
48:     Integer max = params.int('max')
49:     Integer offset = params.int('offset')

我正在处理此错误一段时间,做了我在文档中找到的所有内容。与其他插件结合使用时,这是Spring Security中的错误吗?没有requestmaps,Spring Security UI插件对我来说毫无意义。我需要工作。

最佳答案

在config.groovy中:

import grails.plugins.springsecurity.SecurityConfigType

grails.plugins.springsecurity.securityConfigType = SecurityConfigType.Requestmap
grails.plugins.springsecurity.requestMap.className = "sa.Requestmap"

在上面的"sa.Requestmap"中,sa是程序包名称,Requestmap是域类,如下所示:
package sa

class Requestmap {
  String url
  String configAttribute

  static mapping = {
    cache true
  }

  static constraints = {
    url blank : false, unique : true
    configAttribute blank : false
  }
}

10-08 12:56