简体   繁体   中英

Identity for anonymous user in Spring MVC application

I would like to be able to identify unique anonymous users so I may store some information in the database for that user. Something like a guest shopping cart.

I don't particularly want to use session, because I like the easy fail-over between servers if I keep building with a no-session-data approach.

Is there any way in either spring security or generic spring to get an identity token that I can use to identify particular anonymous users (primary key)?

Actually i don't know alternative way in Spring Security or Spring in general but why you just get SessionId from session.getId()

Returns a string containing the unique identifier assigned to this session. The identifier is assigned by the servlet container and is implementation dependent.Returns:a string specifying the identifier assigned to this session

and save this sessionId to db. This way you not fail between server, you already save it to database.

我已经在spring security 4中解决了这个问题。解决方案是在这里注入到过滤器对应的服务中以查找用户的信息。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM