开发者

NPE in Spring Security OpenID Plugin bootstrap

I'm attempting to use the Spring Security OpenID plugin in grails. I used the supplied scripts to generate the various classes and I have the following in my Config.groovy:

grails.plugins.springsecurity.userLookup.userDomainClassName = 'net.example.manager.User'
grails.plugins.springsecurity.userLookup.authorityJoinClassName = 'net.example.manager.UserRole'
grails.plugins.springsecurity.authority.className = 'net.example.manager.Role'
grails.plugins.springsecurity.openid.domainClass = 'net.example.manager.OpenID'

When I run grails run-app I get the following error:

[main] ERROR context.GrailsContextLoader  - Error executing bootstraps: Cannot invoke method newInstance() on null object
java.lang.NullPointerException: Cannot invoke method newInstance() on null object
at SpringSecurityOpenidGrailsPlugin$_closure2.doCall(SpringSecurityOpenidGrailsPlugin.groovy:140)
at org.grails.tomcat.TomcatServer.start(TomcatServer.groovy:212)
at grails.web.container.EmbeddableServer$start.call(Unknown Source)
at _GrailsRun_groovy$_run_closure5_closure12.doCall(_GrailsRun_groovy:158)
at _GrailsRun_groovy$_run_closure5_closure12.doCall(_GrailsRun_groovy)
at _GrailsSettings_groovy$_run_closure10.doCall(_GrailsSettings_groovy:2开发者_如何学Python80)
at _GrailsSettings_groovy$_run_closure10.call(_GrailsSettings_groovy)
at _GrailsRun_groovy$_run_closure5.doCall(_GrailsRun_groovy:149)
at _GrailsRun_groovy$_run_closure5.call(_GrailsRun_groovy)
at _GrailsRun_groovy.runInline(_GrailsRun_groovy:116)
at _GrailsRun_groovy.this$4$runInline(_GrailsRun_groovy)
at _GrailsRun_groovy$_run_closure1.doCall(_GrailsRun_groovy:59)
at RunApp$_run_closure1.doCall(RunApp.groovy:33)
at gant.Gant$_dispatch_closure5.doCall(Gant.groovy:381)
at gant.Gant$_dispatch_closure7.doCall(Gant.groovy:415)
at gant.Gant$_dispatch_closure7.doCall(Gant.groovy)
at gant.Gant.withBuildListeners(Gant.groovy:427)
at gant.Gant.this$2$withBuildListeners(Gant.groovy)
at gant.Gant$this$2$withBuildListeners.callCurrent(Unknown Source)
at gant.Gant.dispatch(Gant.groovy:415)
at gant.Gant.this$2$dispatch(Gant.groovy)
at gant.Gant.invokeMethod(Gant.groovy)
at gant.Gant.executeTargets(Gant.groovy:590)
at gant.Gant.executeTargets(Gant.groovy:589)

I tracked down the error to this area in the OpenID plugin's source (The error occurs in the last line):

String userClassName = conf.userLookup.userDomainClassName
def userClass = ctx.grailsApplication.getClassForName(userClassName)
String openIdsPropertyName = conf.openid.userLookup.openIdsPropertyName
if (openIdsPropertyName && !userClass.newInstance().hasProperty(openIdsPropertyName))

My domain class exists, but for some reason grails can't get the class and I have no idea why.


I had the same problem, though I had a much shorter error message. For whatever reason the call to 'conf.userLookup.userDomainClassName' returned the class name correctly, and it matches the class perfectly, but 'ctx.grailsApplication.getClassForName(userClassName)' returned null. For me this only happened when running locally. When I pushed to my remote branch and ran it there I had no problems.

I fixed this by avoiding the call to 'getForClassName'. I added the following line to my Config.groovy file:

grails.plugins.springsecurity.userLookup.userDomainClass = mypackage.User;

and made the following change in my SpringSecurityOpenidGrailsPlugin.groovy file:

// The old way this was done was breaking when run locally for some reason.
//String userClassName = conf.userLookup.userDomainClassName
//def userClass = ctx.grailsApplication.getClassForName(userClassName)
//
// So I replaced it with this:
Class userClass = conf.userLookup.userDomainClass;

Now it runs fine.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜