1. 明点软件
  2. Untitled project
  3. Grails Spring Security Taobao

Commits

Liang Yong Rui  committed 757f571

删除TaobaoUserFirstTimeLoginHandler机制

  • Participants
  • Parent commits 36ab992
  • Branches default

Comments (0)

Files changed (4)

File SpringSecurityTaobaoGrailsPlugin.groovy

View file
  • Ignore whitespace
 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 ->

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

View file
  • Ignore whitespace
 
 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)

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

  • Ignore whitespace
-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);
-}

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

  • Ignore whitespace
-package com.mingidea.security.taobao
-
-class NullLocalTaobaoAccountNotFoundHandler implements LocalTaobaoAccountNotFoundHandler {
-
-    /**
-     * always return null.
-     */
-    @Override
-    public Object handle(String taobaoNick, String session) {
-        return null;
-    }
-}