package com.nova.sankuai.infra.utils;
|
|
import com.nova.sankuai.security.UserDetail;
|
import org.apache.commons.lang.StringUtils;
|
|
import java.util.*;
|
|
/**
|
* @author weikangdi
|
* @create 2021/11/1
|
*/
|
public class UserUtil {
|
public static Map<String, UserDetail> USER_LIST = new HashMap<>();
|
|
public static UserDetail getUser(String token) {
|
return USER_LIST.get(token);
|
}
|
|
public static void setUser(String token, UserDetail userDetail) {
|
USER_LIST.putIfAbsent(token, userDetail);
|
}
|
|
public static void removeUserByPhone(String phone) {
|
Set<String> keys = new HashSet<>();
|
USER_LIST.forEach((token, authInfo) -> {
|
if (authInfo != null && StringUtils.isNotBlank(phone) && phone.equals(authInfo.getPhone())) {
|
keys.add(token);
|
}
|
});
|
for (String key : keys) {
|
USER_LIST.remove(key);
|
}
|
}
|
|
public static void removeUserByToken(String token) {
|
USER_LIST.remove(token);
|
}
|
}
|