How to maintain user sessions in DropWizard?

血红的双手。 提交于 2019-12-19 00:19:29

问题


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?


回答1:


With dropwizard>0.7

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

And then use @Session annotation in your resource classes.




回答2:


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.




回答3:


REST is by definition stateless so no sessions should be used at all. The same URI should always return the same results regardless of the session state.



来源:https://stackoverflow.com/questions/19970591/how-to-maintain-user-sessions-in-dropwizard

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!