我目前正在使用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'
}
出现请求映射搜索表单,但在搜索时抛出异常:
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中的一个错误还是会发生什么?没有请求图,Spring Security UI插件对我来说毫无意义。我需要这个工作。
答案 0 :(得分:1)
在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
}
}
答案 1 :(得分:0)
您在grails.plugins.springsecurity.userLookup.userDomainClassName
和中指定了一个包(替换为xxx)
grails.plugins.springsecurity.userLookup.authorityJoinClassName
但不在grails.plugins.springsecurity.requestMap.className
中,只是'Requestmap'
- 这是一个错字吗?
另一个错误是不同的(GORM问题但不是UI插件配置问题) - “xxx.Requestmap未映射”。这表明域类是错误的。是在Grails-app / domain中的User和Role类吗?它是否在其包装的正确文件夹中?我的猜测是它在默认包中,但你把它移到xxx包但没有添加包语句。