Liang Yong Rui avatar Liang Yong Rui committed 757f571

删除TaobaoUserFirstTimeLoginHandler机制

Comments (0)

Files changed (4)

SpringSecurityTaobaoGrailsPlugin.groovy

 import org.codehaus.groovy.grails.plugins.springsecurity.SecurityFilterPosition
 import org.codehaus.groovy.grails.plugins.springsecurity.SpringSecurityUtils
 
-import com.mingidea.security.taobao.NullLocalTaobaoAccountNotFoundHandler
 import com.mingidea.security.taobao.TaobaoAuthenticationProcessingFilter
 import com.mingidea.security.taobao.TaobaoAuthenticationProvider
 import com.mingidea.security.taobao.TaobaoAuthenticationUserDetailsService
 
         taobaoAuthenticationUserDetailsService(TaobaoAuthenticationUserDetailsService) {
             grailsApplication = ref('grailsApplication')
-            localTaobaoAccountNotFoundHandler = ref('localTaobaoAccountNotFoundHandler')
         }
-        
-        //always return null
-        localTaobaoAccountNotFoundHandler(NullLocalTaobaoAccountNotFoundHandler)
     }
 
     def doWithApplicationContext = { applicationContext ->

src/groovy/com/mingidea/security/taobao/TaobaoAuthenticationUserDetailsService.groovy

 
 class TaobaoAuthenticationUserDetailsService extends GormUserDetailsService implements AuthenticationUserDetailsService {
     GrailsApplication grailsApplication
-    LocalTaobaoAccountNotFoundHandler localTaobaoAccountNotFoundHandler
+
     @Override
     public UserDetails loadUserDetails(Authentication auth) throws UsernameNotFoundException {
         def conf = SpringSecurityUtils.securityConfig
         TaobaoAccount.withTransaction { status ->
             def nickPropertyName = conf.taobao.accountLookup.nickPropertyName
             def taobaoAccount = TaobaoAccount.findWhere((nickPropertyName) : taobaoNick)
-            def user
-            if(taobaoAccount) {
-                def accountOwnerPropertyName = conf.taobao.accountLookup.accountOwnerPropertyName
-                user = taobaoAccount."$accountOwnerPropertyName"
-            } else {
-                if(localTaobaoAccountNotFoundHandler) {
-                    log.debug "The local taobao account not found: $taobaoNick,try LocalTaobaoAccountNotFoundHandler"
-                    user = localTaobaoAccountNotFoundHandler.handle(taobaoNick, auth.credentials.session)
-                }
-            }
-
+            if(!taobaoAccount) {
+                throw new UsernameNotFoundException('Taobao user not found: ' + taobaoNick);  
+            } 
+            
+            def accountOwnerPropertyName = conf.taobao.accountLookup.accountOwnerPropertyName
+            def user = taobaoAccount."$accountOwnerPropertyName"
+            
             if(!user) {
                 log.warn "Taobao account not found: $taobaoNick"
                 throw new UsernameNotFoundException('Taobao account not found', taobaoNick)
             }
             
-
-            
             def usernamePropertyName = conf.userLookup.usernamePropertyName
             Collection<GrantedAuthority> authorities = loadAuthorities(user, user."$usernamePropertyName", true)
             return createUserDetails(user, authorities)

src/java/com/mingidea/security/taobao/LocalTaobaoAccountNotFoundHandler.java

-package com.mingidea.security.taobao;
-
-/**
- * 
- * 主要用于Taobao用户第一次登录,在本地数据库没有数据的情况。
- * @author Simon Leung
- * @since 0.1
- */
-public interface LocalTaobaoAccountNotFoundHandler {
-    /**
-     * 
-     * @param taobaoNick the nickname of taobao user
-     * @param session taobao api session key
-     * @return the user object
-     */
-    public Object handle(String taobaoNick, String session);
-}

src/java/com/mingidea/security/taobao/NullLocalTaobaoAccountNotFoundHandler.groovy

-package com.mingidea.security.taobao
-
-class NullLocalTaobaoAccountNotFoundHandler implements LocalTaobaoAccountNotFoundHandler {
-
-    /**
-     * always return null.
-     */
-    @Override
-    public Object handle(String taobaoNick, String session) {
-        return null;
-    }
-}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.