feat: 完善框架

This commit is contained in:
wangyu 2021-07-11 22:01:34 +08:00
parent 2b7a89fbf8
commit 6fb90d7630
3 changed files with 15 additions and 3 deletions

View File

@ -15,7 +15,7 @@ import java.util.Map;
@Getter
public enum UserType implements NamedEnum {
SUPER_ADMIN("超级管理员"), ADMIN("管理员"), VIP("会员"), USER("非会员");
SUPER_ADMIN("超级管理员"), ADMIN("管理员"), VIP("会员"), USER("非会员"), OTHER("其他用户");
private static final Map<String, UserType> aliasMap;

View File

@ -39,7 +39,7 @@ import java.util.function.Supplier;
public class MongoUserDetailsServiceImpl implements MongoUserDetailsService {
// 存储用户校验规则的map
private static final Map<Function<User, Boolean>, Supplier<AuthenticationException>> checkMap;
private static final Map<Function<IUser, Boolean>, Supplier<AuthenticationException>> checkMap;
static {
checkMap = new HashMap<>();
@ -79,7 +79,7 @@ public class MongoUserDetailsServiceImpl implements MongoUserDetailsService {
.switchIfEmpty(Mono.defer(() -> Mono.error(new UsernameNotFoundException("用户不存在!"))));
}
private UserDetails mapToUserDetails(User user) {
private UserDetails mapToUserDetails(IUser user) {
AdminUserDetails userDetail = new AdminUserDetails();
CopyUtils.copyProps(user, userDetail);
return userDetail;

View File

@ -82,6 +82,12 @@ public class TokenProvider implements InitializingBean {
return Optional.empty();
}
/**
* 添加token逻辑
*
* @param exchange 交换报文
* @param authentication 认证信息
*/
public void addToken(ServerWebExchange exchange, Authentication authentication) {
IUser user = (IUser) authentication.getPrincipal();
String token = createToken(authentication, remember);
@ -122,6 +128,12 @@ public class TokenProvider implements InitializingBean {
.compact();
}
/**
* token解析第一步获取认证此处通过claims就能知道token是哪个端的
*
* @param token token
* @return 结果
*/
public Authentication getAuthentication(String token) {
Claims claims = Jwts.parserBuilder()
.setSigningKey(key)