浏览代码

userTokenManager.touch

zhou-hao 5 年之前
父节点
当前提交
1839728a6a

+ 11 - 2
hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/token/UserTokenReactiveAuthenticationSupplier.java

@@ -3,6 +3,7 @@ package org.hswebframework.web.authorization.token;
 import org.hswebframework.web.authorization.Authentication;
 import org.hswebframework.web.authorization.ReactiveAuthenticationManager;
 import org.hswebframework.web.authorization.ReactiveAuthenticationSupplier;
+import org.hswebframework.web.authorization.exception.UnAuthorizedException;
 import org.hswebframework.web.context.ContextKey;
 import org.hswebframework.web.context.ContextUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -25,7 +26,7 @@ public class UserTokenReactiveAuthenticationSupplier implements ReactiveAuthenti
 
     public UserTokenReactiveAuthenticationSupplier(UserTokenManager userTokenManager, ReactiveAuthenticationManager defaultAuthenticationManager) {
         this.defaultAuthenticationManager = defaultAuthenticationManager;
-        this.userTokenManager=userTokenManager;
+        this.userTokenManager = userTokenManager;
     }
 
     @Autowired(required = false)
@@ -68,8 +69,16 @@ public class UserTokenReactiveAuthenticationSupplier implements ReactiveAuthenti
         return ContextUtils.reactiveContext()
                 .flatMap(context ->
                         context.get(ContextKey.of(ParsedToken.class))
-                                .map(t -> userTokenManager.getByToken(t.getToken()))
+                                .map(t -> userTokenManager
+                                        .getByToken(t.getToken())
+                                        .map(token -> {
+                                            if (!token.isNormal()) {
+                                                throw new UnAuthorizedException(token.getState());
+                                            }
+                                            return token;
+                                        }))
                                 .map(tokenMono -> tokenMono
+                                        .doOnNext(token->userTokenManager.touch(token.getToken()))
                                         .flatMap(token -> get(thirdPartAuthenticationManager.get(token.getType()), token.getUserId())))
                                 .orElseGet(Mono::empty));