Migration guide from 1.0 -> 2.0

90 views
Skip to first unread message

Jeff Bowman

unread,
Oct 10, 2015, 2:54:19 PM10/10/15
to Silhouette
Is there a migration guide for moving from Silhouette version 1.0 to version 2.0? I started using 1.0 before 2.0 was released and it works great, but now I'm looking at upgrading my version of play, so I need to upgrade my version of Silhouette also. I'm doing this in small stages so I can break less, and the first step is to get to version 2.0 before following the migration guide for 3.0.

Thanks!
Jeff

Christian Kaps

unread,
Oct 10, 2015, 4:57:40 PM10/10/15
to Silhouette
Hi,

Sorry, there is no migration guide. You can have a look at the release announcement to see what has changed.

Best regards,
Christian

Jeff Bowman

unread,
Oct 11, 2015, 12:54:12 AM10/11/15
to Silhouette
Migrating from 1.0 to 2.0 has been fairly painful, but I now have my app compiling. I still need some help though because I don't understand why I'm getting this error at runtime:


application - 
! @6nm419d0e - Internal server error, for (GET) [/] ->
play.api.Configuration$$anon$1: Configuration error[Cannot initialize the custom Global object (app.Global) (perhaps it's a wrong reference?)]
at play.api.Configuration$.play$api$Configuration$$configError(Configuration.scala:94) ~[play_2.11-2.3.10.jar:2.3.10]
at play.api.Configuration.reportError(Configuration.scala:743) ~[play_2.11-2.3.10.jar:2.3.10]
at play.api.WithDefaultGlobal$class.play$api$WithDefaultGlobal$$scalaGlobal(Application.scala:42) ~[play_2.11-2.3.10.jar:2.3.10]
at play.api.DefaultApplication.play$api$WithDefaultGlobal$$scalaGlobal$lzycompute(Application.scala:402) ~[play_2.11-2.3.10.jar:2.3.10]
at play.api.DefaultApplication.play$api$WithDefaultGlobal$$scalaGlobal(Application.scala:402) ~[play_2.11-2.3.10.jar:2.3.10]
Caused by: java.lang.ExceptionInInitializerError: null
at sun.misc.Unsafe.ensureClassInitialized(Native Method) ~[na:1.8.0_60]
at sun.reflect.UnsafeFieldAccessorFactory.newFieldAccessor(UnsafeFieldAccessorFactory.java:43) ~[na:1.8.0_60]
at sun.reflect.ReflectionFactory.newFieldAccessor(ReflectionFactory.java:142) ~[na:1.8.0_60]
at java.lang.reflect.Field.acquireFieldAccessor(Field.java:1088) ~[na:1.8.0_60]
at java.lang.reflect.Field.getFieldAccessor(Field.java:1069) ~[na:1.8.0_60]
Caused by: com.google.inject.CreationException: Unable to create injector, see the following errors:
1) Could not find a suitable constructor in play.api.Configuration. Classes must have either one (and only one) constructor annotated with @Inject or a zero-argument constructor that is not private.
  at play.api.Configuration.class(Configuration.scala:113)
  at utils.di.SilhouetteModule.provideAuthenticatorService(SilhouetteModule.scala:91)
2) No implementation for com.mohiva.play.silhouette.api.util.FingerprintGenerator was bound.
  at utils.di.SilhouetteModule.provideAuthenticatorService(SilhouetteModule.scala:91)
3) No implementation for com.mohiva.play.silhouette.api.util.Clock was bound.
  at utils.di.SilhouetteModule.provideAuthenticatorService(SilhouetteModule.scala:91)
3 errors
at com.google.inject.internal.Errors.throwCreationExceptionIfErrorsExist(Errors.java:448) ~[guice-4.0-beta5.jar:na]
at com.google.inject.internal.InternalInjectorCreator.initializeStatically(InternalInjectorCreator.java:155) ~[guice-4.0-beta5.jar:na]
at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:107) ~[guice-4.0-beta5.jar:na]
at com.google.inject.Guice.createInjector(Guice.java:96) ~[guice-4.0-beta5.jar:na]
at com.google.inject.Guice.createInjector(Guice.java:73) ~[guice-4.0-beta5.jar:na]
play - No application found at invoker init

I have not changed my conf/application.conf, it still contains this line: 

application.global=app.Global

My Application.scala still has this (only thing that changed was using CookieAuthenticator rather than CachedCookieAuthenticator)
class Application @Inject() (implicit val env: Environment[User, CookieAuthenticator])
    extends Silhouette[User, CookieAuthenticator] {

and I cut-n-paste the Global.scala file directly from the seed (by looking at github and selecting the 2.0 tag), only change was the name ApplicationController -> Application

How do I get past this?

Thanks for any help,

Jeff

Christian Kaps

unread,
Oct 11, 2015, 2:14:02 AM10/11/15
to Silhouette
Hi,

this is a Guice binding error. Please see:

1) Could not find a suitable constructor in play.api.Configuration. Classes must have either one (and only one) constructor annotated with @Inject or a zero-argument constructor that is not private.
 at play.api.Configuration.class(Configuration.scala:113)
 at utils.di.SilhouetteModule.provideAuthenticatorService(SilhouetteModule.scala:91)
2) No implementation for com.mohiva.play.silhouette.api.util.FingerprintGenerator was bound.
 at utils.di.SilhouetteModule.provideAuthenticatorService(SilhouetteModule.scala:91)
3) No implementation for com.mohiva.play.silhouette.api.util.Clock was bound.
 at utils.di.SilhouetteModule.provideAuthenticatorService(SilhouetteModule.scala:91)

Do you have updated your SilhouetteModule?

Best regards,
Christian

Jeff Bowman

unread,
Oct 11, 2015, 11:07:43 AM10/11/15
to Silhouette
Hi Christian!

Yes, or, at least, I believe I did. Here is the pastebin: http://pastebin.com/bsbxs3pk

The differences in this from the 1.0 version (aside from imports) is the addition of the AuthenticatorDAO[CookieAuthenticator] binding which I implemented to use a HashMap (let me know if you need me to post that as well) and the provideAuthenticatorService is different, albeit only slightly to accomodate the CoockieAuthenticatorService requirements (fingerprint and the authenticator dao). The rest is what I was using before, but clearly I've missed something.

I appreciate the assistance!

Christian Kaps

unread,
Oct 11, 2015, 12:08:38 PM10/11/15
to Silhouette
Hi Jeff,

Please could you post your complete module code with the exception so that I can inspect the code for the line numbers from your exception.

Cheers,
Christian

Jeff Bowman

unread,
Oct 11, 2015, 3:16:37 PM10/11/15
to Silhouette
Hi Christian,

The code is on the silhouette-2.0 branch at https://bitbucket.org/jeffbowman/sawshop. You'll need a mongodb instance to connect to to run it. 

Thanks,
Jeff

Christian Kaps

unread,
Oct 11, 2015, 4:10:53 PM10/11/15
to Silhouette
Hi Jeff,

for me it wasn't really clear that your code works now. At least for me it compiles without an error.

Beast regards,
Christian

Jeff Bowman

unread,
Oct 11, 2015, 7:26:02 PM10/11/15
to Silhouette
Found it. It turns out that I had this line in my silhouette.conf file:
authenticator.secureCookie=Play.isProd

which (of course) is a String and not a Boolean. I guess I thought the statement would be evaluated, but it wasn't. I had to change the signature of the provideAuthenticatorService to remove the configuration: Configuration parameter to get the error to show up. Changing the value to false allowed me to get past the runtime error mentioned here.

Thanks for your time!

Best,
Jeff
Reply all
Reply to author
Forward
0 new messages