feat: 完善框架
This commit is contained in:
parent
2b7a89fbf8
commit
6fb90d7630
@ -15,7 +15,7 @@ import java.util.Map;
|
|||||||
@Getter
|
@Getter
|
||||||
public enum UserType implements NamedEnum {
|
public enum UserType implements NamedEnum {
|
||||||
|
|
||||||
SUPER_ADMIN("超级管理员"), ADMIN("管理员"), VIP("会员"), USER("非会员");
|
SUPER_ADMIN("超级管理员"), ADMIN("管理员"), VIP("会员"), USER("非会员"), OTHER("其他用户");
|
||||||
|
|
||||||
private static final Map<String, UserType> aliasMap;
|
private static final Map<String, UserType> aliasMap;
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ import java.util.function.Supplier;
|
|||||||
public class MongoUserDetailsServiceImpl implements MongoUserDetailsService {
|
public class MongoUserDetailsServiceImpl implements MongoUserDetailsService {
|
||||||
|
|
||||||
// 存储用户校验规则的map
|
// 存储用户校验规则的map
|
||||||
private static final Map<Function<User, Boolean>, Supplier<AuthenticationException>> checkMap;
|
private static final Map<Function<IUser, Boolean>, Supplier<AuthenticationException>> checkMap;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
checkMap = new HashMap<>();
|
checkMap = new HashMap<>();
|
||||||
@ -79,7 +79,7 @@ public class MongoUserDetailsServiceImpl implements MongoUserDetailsService {
|
|||||||
.switchIfEmpty(Mono.defer(() -> Mono.error(new UsernameNotFoundException("用户不存在!"))));
|
.switchIfEmpty(Mono.defer(() -> Mono.error(new UsernameNotFoundException("用户不存在!"))));
|
||||||
}
|
}
|
||||||
|
|
||||||
private UserDetails mapToUserDetails(User user) {
|
private UserDetails mapToUserDetails(IUser user) {
|
||||||
AdminUserDetails userDetail = new AdminUserDetails();
|
AdminUserDetails userDetail = new AdminUserDetails();
|
||||||
CopyUtils.copyProps(user, userDetail);
|
CopyUtils.copyProps(user, userDetail);
|
||||||
return userDetail;
|
return userDetail;
|
||||||
|
@ -82,6 +82,12 @@ public class TokenProvider implements InitializingBean {
|
|||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加token逻辑
|
||||||
|
*
|
||||||
|
* @param exchange 交换报文
|
||||||
|
* @param authentication 认证信息
|
||||||
|
*/
|
||||||
public void addToken(ServerWebExchange exchange, Authentication authentication) {
|
public void addToken(ServerWebExchange exchange, Authentication authentication) {
|
||||||
IUser user = (IUser) authentication.getPrincipal();
|
IUser user = (IUser) authentication.getPrincipal();
|
||||||
String token = createToken(authentication, remember);
|
String token = createToken(authentication, remember);
|
||||||
@ -122,6 +128,12 @@ public class TokenProvider implements InitializingBean {
|
|||||||
.compact();
|
.compact();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* token解析第一步,获取认证。此处通过claims就能知道token是哪个端的
|
||||||
|
*
|
||||||
|
* @param token token
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
public Authentication getAuthentication(String token) {
|
public Authentication getAuthentication(String token) {
|
||||||
Claims claims = Jwts.parserBuilder()
|
Claims claims = Jwts.parserBuilder()
|
||||||
.setSigningKey(key)
|
.setSigningKey(key)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user