I have a webapp running开发者_如何学C on tomcat using a JndiRealm and form authentication. I would like to add a "remember me" checkbox to that form. What is the best way to do this?
That's pretty a lot of work if you'd like to keep using container managed authentication since this facility isn't provided by the standard Java EE API. Spring Security has already done most of the work for you. Check the Remember-Me Authentication documentation. I'd recommend it instead of homegrowing.
I just added this feature. I built a new valve by extending FormAuthenticator and overriding the authenticate method. It took quite a bit of tinkering with the original code to get the feature to work and it uses a 2nd database table to store the auto-logon information.
According to what I've heard, Tomcat 8 will do away with valves and use filters instead. It would probably be easier to wait and try to implement it via filters.
精彩评论