feat:仓库初始化问题修复
This commit is contained in:
parent
e5ae9766df
commit
b5884b4b86
@ -1,6 +1,7 @@
|
||||
package com.flyfish.framework.service;
|
||||
|
||||
import com.flyfish.framework.config.constants.UserCacheKeys;
|
||||
import com.flyfish.framework.configuration.jwt.TokenProvider;
|
||||
import com.flyfish.framework.domain.base.IUser;
|
||||
import com.flyfish.framework.domain.po.User;
|
||||
import com.flyfish.framework.enums.UserStatus;
|
||||
@ -17,7 +18,6 @@ import org.springframework.security.core.context.SecurityContextImpl;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
||||
import org.springframework.security.crypto.password.NoOpPasswordEncoder;
|
||||
import org.springframework.security.web.server.context.ServerSecurityContextRepository;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.server.ServerWebExchange;
|
||||
import reactor.core.publisher.Mono;
|
||||
@ -54,7 +54,7 @@ public class MongoUserDetailsServiceImpl implements MongoUserDetailsService {
|
||||
private final UserDetailsConverter userDetailsConverter;
|
||||
|
||||
@Resource
|
||||
private ServerSecurityContextRepository contextRepository;
|
||||
private TokenProvider tokenProvider;
|
||||
@Resource
|
||||
private ReactiveRedisOperations reactiveRedisOperations;
|
||||
|
||||
@ -111,7 +111,11 @@ public class MongoUserDetailsServiceImpl implements MongoUserDetailsService {
|
||||
@Override
|
||||
public Mono<Authentication> authenticate(UserDetails user, ServerWebExchange exchange) {
|
||||
return loadContext(user)
|
||||
.flatMap(securityContext -> contextRepository.save(exchange, securityContext)
|
||||
.flatMap(securityContext -> Mono.fromCallable(() -> {
|
||||
// 添加jwtToken
|
||||
tokenProvider.addToken(exchange, securityContext.getAuthentication());
|
||||
return Mono.empty();
|
||||
})
|
||||
.contextWrite(ReactiveSecurityContextHolder.withSecurityContext(
|
||||
Mono.just(securityContext)))
|
||||
.then(Mono.just(securityContext)))
|
||||
@ -146,10 +150,7 @@ public class MongoUserDetailsServiceImpl implements MongoUserDetailsService {
|
||||
*/
|
||||
@Override
|
||||
public Mono<Void> logout(ServerWebExchange exchange) {
|
||||
return ReactiveSecurityContextHolder.getContext()
|
||||
.switchIfEmpty(contextRepository.load(exchange))
|
||||
.flatMap(context -> contextRepository.save(exchange, context));
|
||||
|
||||
return tokenProvider.removeToken(exchange);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user