开发者

How can I logout/login as a different user from a servlet on gwt/gae

I'm testing my Java/GWT/GAE based servlets. One of my servlets accesses the datastore (CRUD type methods) that would normally be called from the client over RPC.

The flow works like this: I launch testServlet1. If I'm not logged in, it generates the login url and returns this to the user. I click it. (now I'm logged in.)

testServlet1 runs, testing my DAO, and verifies the final database state.

testServlet2 now wants to add objects to the datastore using a different logged in user to ensure that there is no interference between user1 and user2.

My q开发者_如何学Cuestion is: how can I programmatically 'switch' logged in users from within a servlet without manually clicking the logout/login links, or automating this on the client side?

There doesn't seem to be an api for this.

Anyone doing this?

Thanks Rob


Every request should do its own authentication. You can achieve this nicely with filters. Basically, they intercept every request and can do arbitrary computation before passing the request along to the eventually-intended servlet. You could make a filter say "if the user is not logged in, return login screen; else, go to the servlet as intended, with the logged in user as a parameter."


Given that there does not seem to be an api specifically for this, I simply invoke the login and logout urls gae provides directly from my servlet.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜