0

I am developing a web app and I am using the way zentasks sample app uses for user authentication so after login is done, username is stored in session. Now I am trying to do the authorization part with DeadBolt 2 plugin. Basically I have merged the sample DeadBolt 2 app into my own application. The only difference is that I am using 2.sql to bootstrap the default data instead of Global.java(and with different role names than foo & bar). Now after login when I try to access a controller method annotated by @SubjectPresent, I get NullPointerException with the following stacktrace:

[error] play - Cannot invoke the action, eventually got an error: java.lang.NullPointerException
[error] application - 

! @6h2pm8ji7 - Internal server error, for (GET) [/upload] ->

play.api.Application$$anon$1: Execution exception[[NullPointerException: null]]
at play.api.Application$class.handleError(Application.scala:293) ~[play_2.10.jar:2.2.0]
at play.api.DefaultApplication.handleError(Application.scala:399) ~[play_2.10.jar:2.2.0]
at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$2$$anonfun$applyOrElse$3.apply(PlayDefaultUpstreamHandler.scala:261) ~[play_2.10.jar:2.2.0]
at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$2$$anonfun$applyOrElse$3.apply(PlayDefaultUpstreamHandler.scala:261) ~[play_2.10.jar:2.2.0]
at scala.Option.map(Option.scala:145) ~[scala-library.jar:na]
at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$2.applyOrElse(PlayDefaultUpstreamHandler.scala:261) ~[play_2.10.jar:2.2.0]
Caused by: java.lang.NullPointerException: null
at be.objectify.deadbolt.java.actions.SubjectPresentAction.execute(SubjectPresentAction.java:56) ~[deadbolt-java_2.10-2.2-RC3.jar:2.2-RC3]
at be.objectify.deadbolt.java.actions.AbstractDeadboltAction.call(AbstractDeadboltAction.java:97) ~[deadbolt-java_2.10-2.2-RC3.jar:2.2-RC3]
at play.core.j.JavaAction$$anon$3.apply(JavaAction.scala:91) ~[play_2.10.jar:2.2.0]
at play.core.j.JavaAction$$anon$3.apply(JavaAction.scala:90) ~[play_2.10.jar:2.2.0]
at play.core.j.FPromiseHelper$$anonfun$flatMap$1.apply(FPromiseHelper.scala:82) ~[play_2.10.jar:2.2.0]
at play.core.j.FPromiseHelper$$anonfun$flatMap$1.apply(FPromiseHelper.scala:82) ~[play_2.10.jar:2.2.0]

Any ideas on where it has gone wrong?

EDIT: I switched to RC4 and this time I got this error using @Restrict

! @6h4k9lbjh - Internal server error, for (GET) [/editInstallation/1] ->

play.api.Application$$anon$1: Execution exception[[NullPointerException: null]]
at play.api.Application$class.handleError(Application.scala:293) ~[play_2.10.jar:2.2.0]
at play.api.DefaultApplication.handleError(Application.scala:399) [play_2.10.jar:2.2.0]
at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$2$$anonfun$applyOrElse$3.apply(PlayDefaultUpstreamHandler.scala:261) [play_2.10.jar:2.2.0]
at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$2$$anonfun$applyOrElse$3.apply(PlayDefaultUpstreamHandler.scala:261) [play_2.10.jar:2.2.0]
at scala.Option.map(Option.scala:145) [scala-library.jar:na]
at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$2.applyOrElse(PlayDefaultUpstreamHandler.scala:261) [play_2.10.jar:2.2.0]

    Caused by: java.lang.NullPointerException: null
at be.objectify.deadbolt.java.actions.AbstractRestrictiveAction.execute(AbstractRestrictiveAction.java:47) ~[deadbolt-java_2.10-2.2-RC4.jar:2.2-RC4]
at be.objectify.deadbolt.java.actions.AbstractDeadboltAction.call(AbstractDeadboltAction.java:119) ~[deadbolt-java_2.10-2.2-RC4.jar:2.2-RC4]
at play.core.j.JavaAction$$anon$3.apply(JavaAction.scala:91) ~[play_2.10.jar:2.2.0]
at play.core.j.JavaAction$$anon$3.apply(JavaAction.scala:90) ~[play_2.10.jar:2.2.0]
at play.core.j.FPromiseHelper$$anonfun$flatMap$1.apply(FPromiseHelper.scala:82) ~[play_2.10.jar:2.2.0]
at play.core.j.FPromiseHelper$$anonfun$flatMap$1.apply(FPromiseHelper.scala:82) ~[play_2.10.jar:2.2.0]

2.2-RC1 still working pretty fine and I've had no problem with it using play 2.2.0.

jrook
  • 3,459
  • 1
  • 16
  • 33
  • There seems to be a bug in deadbolt-2-java-2.2-RC3. I solved this issue by using 2.1 version. It seems that the author has addressed this issue and posted the update on github. Is is possible for me to "manually" apply the fix to that code in my project or I should wait for the next version and change Build.sbt file? – jrook Jan 23 '14 at 06:32

1 Answers1

2

I've fixed this and released a new version - switch to version 2.2-RC4 and you should be fine.

"be.objectify" %% "deadbolt-java" % "2.2-RC4"
Steve Chaloner
  • 8,162
  • 1
  • 22
  • 38
  • I still got errors. I have edited the original question with the new stacktrace. – jrook Jan 29 '14 at 07:43
  • 4
    Can you post your DeadboltHandler implementation? It could be your beforeAuthCheck method is returning null instead of F.Promise.pure(null). – Steve Chaloner Jan 29 '14 at 09:36
  • This will no longer be a problem in 2.2-RC5 – Steve Chaloner Feb 03 '14 at 08:47
  • @Steve, that was exactly my problem as well. Thanks! – Ledivin Mar 03 '14 at 19:18
  • @SteveChaloner for some reason I still have NPE in deadbolt-java_2.10-2.3.3.jar when returning `null` from `beforeAuthCheck`. Not a problem though, since returning `F.Promise.pure(null)` fixes it. – Leo Apr 30 '15 at 14:43