|
@@ -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));
|
|
|
|