All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.houbbbbb.sso.cons.SSOCON Maven / Gradle / Ivy

package com.github.houbbbbb.sso.cons;

import com.github.houbbbbb.sso.util.GsonUtil;
import com.github.houbbbbb.sso.util.SecretUtil;
import com.google.gson.JsonObject;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author : hbw
 * @desctiption :
 * @date : 2020-05-15 13:53
 */
public class SSOCON {
    private static final Map userCacheMap = new ConcurrentHashMap();
    public static final String SSO_UTF_8 = "UTF-8";
    public static final String SSO_SESSION = "SSO_LOCAL_SESSION";
    public static void putUserCache(String key, JsonObject value){
        if(null!=key) {
            try {
                String userId = value.get("id").getAsString();
                String userInfo = value.get("userInfo").getAsString();
//                System.out.println("userId --- "+userId);
//                System.out.println("userInfo --- "+userInfo);
                userInfo = SecretUtil.decodeMix(userInfo, userId);
                value = GsonUtil.toObj(userInfo, JsonObject.class);
                userCacheMap.put(key, value);
            }catch (Exception e){
                e.printStackTrace();
            }
        }
    }
    public static JsonObject getUserCache(String key){
        if(null!=key) {
            return userCacheMap.get(key);
        }else{
            return null;
        }
    }
    public static boolean containsUserCache(String key){
        if(null!=key) {
            return userCacheMap.containsKey(key);
        }else{
            return false;
        }
    }
    public static int userCacheSize(){
        return userCacheMap.size();
    }
    public static void removeUserCache(String key){
        if(null!=key) {
            userCacheMap.remove(key);
        }
    }
    public static void removeUserCacheAll(){
        userCacheMap.clear();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy