Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to maintain user sessions in DropWizard?

I am looking for a persistent session manager which saves the session on file system (like PHP) that can be used with DropWizard. I see there is one Environment.getSessionHandler(), but I see no documentation on it.

I could write my own but I am hoping for a cooked meal. Will the above SessionHandler is what I am looking for? And how to use that?

like image 652
AppleGrew Avatar asked Nov 14 '13 05:11

AppleGrew


Video Answer


2 Answers

With dropwizard>0.7

environment.jersey().register(HttpSessionProvider.class);
environment.servlets().setSessionHandler(new SessionHandler());

And then use @Session annotation in your resource classes.

like image 170
Toilal Avatar answered Nov 15 '22 16:11

Toilal


DropWizard does not support sessions out of the box and based on posts by the author in google groups, they aren't planning on supporting it in the future either.

The only way currently would be for you to implement org.eclipse.jetty.server.session.SessionHandler yourself or look for something that already exists and then call environment.setSessionHandler(...)

And in case you need this info, DW 0.6.2 uses Jetty 8.1.10

You can also checkout http://cosmo-opticon.net/blog/2013/1/23/session-based-security-in-dropwizard and see if you can reuse some of that.

like image 38
Madhan Dennis Avatar answered Nov 15 '22 16:11

Madhan Dennis