Shiro control concurrent login limit and login kick out implementation code

We often find it useful that when user a logs in in Beijing, and then user a logs in again in Tianjin, it is necessary to kick out of the login status in Beijing. If the user logs in again in Beijing, he will kick out the users in Tianjin again and again.

This ensures that an account can only be used by one person at the same time. Now let's explain how Shiro implements this function. Now redis cache is used. We can also use other caches. If it is a single point, you can directly use a static map < string, Object > or ehcache.

XML configuration.

Static injection is used here. If you don't understand, please see this article: Spring static injection explanation (method invoking actor bean)

Filter interception sequence added to Shiro

Java code, let's look at the filter code.

Front page (login page) code.

OK, so the effect comes out. (renderings)

summary

The above is the implementation code of Shiro controlling concurrent login limit and login kick out introduced by Xiaobian. I hope it will be helpful to you. If you have any questions, please leave me a message and Xiaobian will reply to you in time. Thank you very much for your support for the programming tips website!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>