Commits

明点软件 committed 763b451

增加removeSession()方法

Comments (0)

Files changed (1)

src/groovy/com/mingidea/security/taobao/util/ExSpringSecurityUtils.groovy

      * @return
      */
     static List getAllPrincipals() {
-        ApplicationContext appContext = ApplicationHolder.application.mainContext
-        SessionRegistry sessionRegistry = appContext.getBean('sessionRegistry')
-        return sessionRegistry.getAllPrincipals()
+        return getSessionRegistry().getAllPrincipals()
+    }
+    
+    static boolean removeSession(Object userId) {
+        SessionRegistry sessionRegistry = getSessionRegistry()
+        List allPrincipals = sessionRegistry.getAllPrincipals()
+        
+        def user = allPrincipals.find{it.id == userId}
+        if(!user) {
+            return false
+        }
+        List sessions = sessionRegistry.getAllSessions(user, true)
+        sessions.each{
+            sessionRegistry.removeSessionInformation(it.sessionId)
+        }
+    }
+    
+    private static SessionRegistry getSessionRegistry() {
+        ApplicationContext applicationContext = ApplicationHolder.application.mainContext
+        return applicationContext.getBean('sessionRegistry')
     }
 }