Shiro enables single-user logon. A single user can only log on to one location at a time. shiro users log on

Source: Internet
Author: User
Tags ldap

Shiro enables single-user logon. A single user can only log on to one location at a time. shiro users log on

Here, shiro does not integrate springMVC and uses the ini configuration file directly.

Shiro. ini

[Main] # Objects and their properties are defined here, # Such as the securityManager, Realms and anything # else needed to build the SecurityManagerauthc. loginUrl =/login. jspauthc. successUrl =/web/index. jsp # cache managerbuiltInCacheManager = org. apache. shiro. cache. memoryConstrainedCacheManagersecurityManager = org. apache. shiro. web. mgt. defaultWebSecurityManagersecurityManager. cacheManager = $ builtInCacheManagersecurityManager. sessionManager = $ sessionManager # the session must be configured. During forced exit, sessionManager = org is implemented by removing the session. apache. shiro. web. session. mgt. defaultWebSessionManagersessionManager. sessionDAO = $ sessionDAOsessionDAO = org. apache. shiro. session. mgt. eis. memorySessionDAO # Create ldap realmldapRealm = org. apache. shiro. realm. ldap. jndiLdapRealm #...... # Configure JDBC realm performancedatasource = org. postgresql. ds. PGPoolingDataSource #....... # Create JDBC realm. jdbcRealm. permissionsLookupEnabled = truejdbcRealm = org. apache. shiro. realm. jdbc. jdbcRealmjdbcRealm. userRolesQuery = ...... jdbcRealm. permissionsQuery = ...... jdbcRealm. dataSource = $ dataSource # self realmlocalAuthorizingRealm = com. redbudtek. shiro. localAuthorizingRealmsecurityManager. realms = $ ldapRealm, $ localAuthorizingRealm

 

In LocalAuthorizingRealm, remove other sessions of the user before Logon:

@ Override protected AuthenticationInfo doGetAuthenticationInfo (AuthenticationToken authenticationToken) throws AuthenticationException {String userName = (String) authenticationToken. getPrincipal (); // process session DefaultWebSecurityManager securityManager = (DefaultWebSecurityManager) SecurityUtils. getSecurityManager (); DefaultWebSessionManager sessionManager = (DefaultWebSessionManager) securityManager. getSessionManager (); Collection <Session> sessions = sessionManager. getSessionDAO (). getActiveSessions (); // obtain the list of currently logged-on user sessions for (session Session: sessions) {// clear the session (userName. equals (String. valueOf (session. getAttribute (defasubsubjectcontext. PRINCIPALS_SESSION_KEY) {sessionManager. getSessionDAO (). delete (session) ;}} String pwd = null; return new SimpleAuthenticationInfo (userName, pwd, getName ());}

 

After a session is deleted, shiro can perform authentication and judgment only when the client interacts with the server. When interacting with the server, the subject information is as follows:

At this time, the login user authentication has expired and the client can respond.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.