Commits

明点软件 committed da7f11c

改进ExSpringSecurityUtils

  • Participants
  • Parent commits f2c58bf
  • Tags 0.3.9

Comments (0)

Files changed (3)

SpringSecurityTaobaoGrailsPlugin.groovy

 
 class SpringSecurityTaobaoGrailsPlugin {
     // the plugin version
-    def version = "0.3.7"
+    def version = "0.3.9"
     // the version or versions of Grails the plugin is designed for
     def grailsVersion = "1.3.7 > *"
     // the other plugins this plugin depends on
-<plugin name='spring-security-taobao' version='0.3.7' grailsVersion='1.3.7 &gt; *'>
+<plugin name='spring-security-taobao' version='0.3.9' grailsVersion='1.3.7 &gt; *'>
   <author>Simon Leung</author>
   <authorEmail>simon.leung@mingidea.com</authorEmail>
   <title>Taobao open authentication support for the Spring Security plugin.</title>

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

 import org.codehaus.groovy.grails.commons.ApplicationHolder
 import org.springframework.context.ApplicationContext
 import org.springframework.security.core.session.SessionRegistry
+import org.springframework.security.core.userdetails.User
 
 /**
  * 扩展SpringSecurityUtils的功能
         return getSessionRegistry().getAllPrincipals()
     }
     
-    /**
-     * 
-     * @return 用户或Session不存在返回false,销毁session成功返回true
-     */
-    static boolean expireSession(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, false)
-        sessions.each{
-            it.expireNow()
-        }
-        return sessions.size() > 0
-    }
+	static boolean expireSessionByUsername(String userName) { 
+		List allPrincipals = getAllPrincipals()
+		
+		def principal = allPrincipals.find{it.username == username}
+		if(!principal) {
+			return false
+		}
+		
+		return expireSessionByPrincipal(principal)
+	}
+	
+	static boolean expireSessionByPrincipal(principal) {
+		List sessions = sessionRegistry.getAllSessions(principal, false)
+		sessions.each{
+			it.expireNow()
+		}
+		return sessions.size() > 0
+	}
     
     private static SessionRegistry getSessionRegistry() {
         ApplicationContext applicationContext = ApplicationHolder.application.mainContext