Search in sources :

Example 1 with ConcurrentMap

use of j.util.ConcurrentMap in project JFramework by gugumall.

the class SSOServer method ssologinauto.

/**
 * 登录
 * @param jsession
 * @param session
 * @param request
 * @param response
 * @throws Exception
 */
public void ssologinauto(JSession jsession, HttpSession session, HttpServletRequest request, HttpServletResponse response) throws Exception {
    if (!SSOConfig.isServer()) {
        // 不是sso server端
        jsession.resultString = Constants.SSO_SERVICE_UNAVAILABLE;
        return;
    }
    // 是否SSO Client
    String clientUrlPrefix = SysUtil.getHttpParameter(request, Constants.SSO_CLIENT);
    String loginFromDomain = JUtilString.getHost(clientUrlPrefix);
    Client client = SSOConfig.getSsoClientByIdOrUrl(clientUrlPrefix);
    if (client == null || !client.canLogin()) {
        // 不是sso client
        jsession.resultString = Constants.SSO_BAD_CLIENT;
        return;
    }
    if (clientUrlPrefix.indexOf("http") < 0)
        clientUrlPrefix = client.getUrlDefault();
    try {
        String ssoUserId = request.getParameter(Constants.SSO_USER_ID);
        // 该用户如在别处登录了,先注销
        LoginStatus[] loginStatusOlds = SSOServer.findLoginStatusOfUserId(ssoUserId);
        if (loginStatusOlds != null) {
            for (int i = 0; i < loginStatusOlds.length; i++) {
                if (loginFromDomain.equals(loginStatusOlds[i].getLoginFromDomain())) {
                    logout(client, loginStatusOlds[i]);
                }
            }
        }
        String globalSessionId = JUtilUUID.genUUID();
        LoginStatus loginStatus = new LoginStatus(client.getId(), session, globalSessionId, ssoUserId, JHttp.getRemoteIp(request), SysConfig.getSysId(), SysConfig.getMachineID(), SysConfig.getSysId(), loginFromDomain);
        String infos = SysUtil.getHttpParameter(request, Constants.SSO_LOGIN_INFO);
        if (infos != null) {
            Map messages = (ConcurrentMap) JObject.string2Serializable(infos);
            for (Iterator keys = messages.keySet().iterator(); keys.hasNext(); ) {
                Object key = keys.next();
                Object val = messages.get(key);
                loginStatus.setMessage(key, val);
            }
        }
        users.addOne(globalSessionId, loginStatus);
        String token = JUtilUUID.genUUID();
        SSOContext.addToken(loginStatus.getGlobalSessionId(), token, ssoUserId);
        jsession.resultString = Constants.RESPONSE_OK + ":" + loginStatus.getGlobalSessionId() + ":" + token;
    } catch (Exception e) {
        log.log(e, Logger.LEVEL_ERROR);
        jsession.resultString = Constants.RESPONSE_ERR;
    }
}
Also used : ConcurrentMap(j.util.ConcurrentMap) Iterator(java.util.Iterator) JObject(j.common.JObject) JUtilString(j.util.JUtilString) CachedMap(j.cache.CachedMap) ConcurrentMap(j.util.ConcurrentMap) Map(java.util.Map)

Example 2 with ConcurrentMap

use of j.util.ConcurrentMap in project JFramework by gugumall.

the class JCacheUnitMap method keys.

/*
	 *  (non-Javadoc)
	 * @see j.cache.JCacheUnit#keys(j.cache.JCacheParams)
	 */
public ConcurrentList keys(JCacheParams params) throws Exception {
    checkStatus(false);
    JCacheFilter keyFileter = params == null ? null : params.keyFilter;
    JCacheFilter valueFilter = params == null ? null : params.valueFilter;
    int recordsPerPage = params == null ? 0 : params.recordsPerPage;
    int pageNum = params == null ? 0 : params.pageNum;
    ConcurrentMap mappings = container.snapshot();
    List keys = mappings.listKeys();
    if (keyFileter != null || valueFilter != null) {
        for (int i = 0; i < keys.size(); i++) {
            Object key = keys.get(i);
            Object value = mappings.get(key);
            boolean remove = false;
            if (keyFileter != null && !keyFileter.matches(key)) {
                remove = true;
            } else if (valueFilter != null && !valueFilter.matches(value)) {
                remove = true;
            }
            if (remove) {
                keys.remove(i);
            }
        }
    }
    mappings.clear();
    mappings = null;
    ConcurrentList result = new ConcurrentList();
    result.setTotal(keys.size());
    if (recordsPerPage > 0 && pageNum > 0) {
        // 分页
        int start = recordsPerPage * (pageNum - 1);
        int to = recordsPerPage * pageNum;
        if (start >= 0) {
            if (keys.size() > start) {
                keys = JUtilList.subConcurrentList(keys, start, to > keys.size() ? keys.size() : to);
            } else {
                keys.clear();
            }
        }
    }
    result.addAll(keys);
    return result;
}
Also used : ConcurrentList(j.util.ConcurrentList) ConcurrentMap(j.util.ConcurrentMap) List(java.util.List) ConcurrentList(j.util.ConcurrentList) JUtilList(j.util.JUtilList)

Example 3 with ConcurrentMap

use of j.util.ConcurrentMap in project JFramework by gugumall.

the class JCacheUnitMap method sub.

/*
	 *  (non-Javadoc)
	 * @see j.cache.JCacheUnit#sub(j.cache.JCacheParams)
	 */
public Object sub(JCacheParams params) throws Exception {
    checkStatus(false);
    JCacheFilter keyFileter = params == null ? null : params.keyFilter;
    JCacheFilter valueFilter = params == null ? null : params.valueFilter;
    ConcurrentMap mappings = container.snapshot();
    if (keyFileter == null && valueFilter == null)
        return mappings;
    List keys = mappings.listKeys();
    for (int i = 0; i < keys.size(); i++) {
        Object key = keys.get(i);
        Object value = mappings.get(key);
        boolean matches = true;
        if (keyFileter != null && !keyFileter.matches(key)) {
            matches = false;
        } else if (valueFilter != null && !valueFilter.matches(value)) {
            matches = false;
        }
        if (!matches)
            mappings.remove(key);
    }
    keys.clear();
    keys = null;
    mappings.setTotal(mappings.size());
    if (params.recordsPerPage > 0 && params.pageNum > 0) {
        // 分页
        int start = params.recordsPerPage * (params.pageNum - 1);
        int to = params.recordsPerPage * params.pageNum;
        if (start >= 0) {
            if (mappings.size() > start) {
                mappings = JUtilMap.subConcurrentMap(mappings, start, to > mappings.size() ? mappings.size() : to);
            } else {
                mappings.clear();
            }
        }
    }
    return mappings;
}
Also used : ConcurrentMap(j.util.ConcurrentMap) List(java.util.List) ConcurrentList(j.util.ConcurrentList) JUtilList(j.util.JUtilList)

Example 4 with ConcurrentMap

use of j.util.ConcurrentMap in project JFramework by gugumall.

the class JCacheUnitMap method values.

/*
	 *  (non-Javadoc)
	 * @see j.cache.JCacheUnit#values(j.cache.JCacheParams)
	 */
public ConcurrentList values(JCacheParams params) throws Exception {
    checkStatus(false);
    JCacheFilter keyFileter = params == null ? null : params.keyFilter;
    JCacheFilter valueFilter = params == null ? null : params.valueFilter;
    JUtilSorter sorter = params == null ? null : params.sorter;
    String sortType = params == null ? null : params.sortType;
    int recordsPerPage = params == null ? 0 : params.recordsPerPage;
    int pageNum = params == null ? 0 : params.pageNum;
    ConcurrentMap mappings = container.snapshot();
    List values = null;
    if (keyFileter != null || valueFilter != null) {
        values = new ConcurrentList();
        List keys = mappings.listKeys();
        for (int i = 0; i < keys.size(); i++) {
            Object key = keys.get(i);
            Object value = mappings.get(key);
            boolean remove = false;
            if (keyFileter != null && !keyFileter.matches(key)) {
                remove = true;
            } else if (valueFilter != null && !valueFilter.matches(value)) {
                remove = true;
            }
            if (!remove) {
                values.add(value);
            }
        }
        keys.clear();
        keys = null;
    } else {
        values = mappings.listValues();
    }
    mappings.clear();
    mappings = null;
    if (sorter != null) {
        // 排序
        values = sorter.mergeSort(values, sortType);
    }
    ConcurrentList result = new ConcurrentList();
    result.setTotal(values.size());
    if (recordsPerPage > 0 && pageNum > 0) {
        // 分页
        int start = recordsPerPage * (pageNum - 1);
        int to = recordsPerPage * pageNum;
        if (start >= 0) {
            if (values.size() > start) {
                values = JUtilList.subConcurrentList(values, start, to > values.size() ? values.size() : to);
            } else {
                values.clear();
            }
        }
    }
    result.addAll(values);
    return result;
}
Also used : ConcurrentList(j.util.ConcurrentList) JUtilSorter(j.util.JUtilSorter) ConcurrentMap(j.util.ConcurrentMap) List(java.util.List) ConcurrentList(j.util.ConcurrentList) JUtilList(j.util.JUtilList)

Example 5 with ConcurrentMap

use of j.util.ConcurrentMap in project JFramework by gugumall.

the class JRouterImpl method unregister.

/*
	 *  (non-Javadoc)
	 * @see j.service.router.RouterInterface#unregister(java.lang.String, java.lang.String, java.lang.String, java.lang.String)
	 */
public String unregister(String clientUuid, String clusterCode, String uuid, String md54Routing) throws RemoteException {
    if (Constants.PRIVICY_PUBLIC.equalsIgnoreCase(routerConfig.getPrivacy())) {
    // is public, nothing to do
    } else if (Constants.PRIVICY_MD5.equalsIgnoreCase(routerConfig.getPrivacy())) {
        Client client = routerConfig.getClient(clientUuid);
        if (client == null) {
            log.log("client " + clientUuid + " is not exists.", Logger.LEVEL_DEBUG);
            return Constants.AUTH_FAILED;
        }
        String md5 = "";
        md5 += clientUuid;
        md5 += clusterCode;
        md5 += uuid;
        md5 += client.getKey();
        md5 = JUtilMD5.MD5EncodeToHex(md5);
        if (!md5.equalsIgnoreCase(md54Routing)) {
            return Constants.AUTH_FAILED;
        }
    } else {
        // 未实现的隐私策略
        return Constants.AUTH_FAILED;
    }
    ConcurrentList clusterNodes = (ConcurrentList) serviceNodesOfClusters.get(clusterCode);
    ConcurrentMap servantsOfCluster = (ConcurrentMap) servantsOfClusters.get(clusterCode);
    ConcurrentMap httpsOfCluster = (ConcurrentMap) httpsOfClusters.get(clusterCode);
    if (clusterNodes != null) {
        for (int i = 0; i < clusterNodes.size(); i++) {
            Service node = (Service) clusterNodes.get(i);
            if (node.uuid.equals(uuid)) {
                if (nodeInfoList.contains(node.toString()))
                    nodeInfoList.remove(node.toString());
                clusterNodes.remove(i);
                if (servantsOfCluster != null)
                    servantsOfCluster.remove(node.uuid);
                if (httpsOfCluster != null)
                    httpsOfCluster.remove(node.uuid);
                update = SysUtil.getNow();
                break;
            }
        }
    }
    if (clusterNodes == null || clusterNodes.isEmpty()) {
        serviceNodesOfClusters.remove(clusterCode);
        servantsOfClusters.remove(clusterCode);
        httpsOfClusters.remove(clusterCode);
        clusterCodes.remove(clusterCode);
    }
    return Constants.INVOKING_DONE;
}
Also used : ConcurrentList(j.util.ConcurrentList) ConcurrentMap(j.util.ConcurrentMap) Client(j.service.Client) HttpClient(org.apache.http.client.HttpClient)

Aggregations

ConcurrentMap (j.util.ConcurrentMap)16 ConcurrentList (j.util.ConcurrentList)8 List (java.util.List)7 HttpClient (org.apache.http.client.HttpClient)7 Client (j.service.Client)5 JUtilString (j.util.JUtilString)5 RemoteException (java.rmi.RemoteException)4 JHttpContext (j.http.JHttpContext)3 ServiceBase (j.service.server.ServiceBase)3 JUtilList (j.util.JUtilList)3 Map (java.util.Map)3 HashMap (java.util.HashMap)2 CachedMap (j.cache.CachedMap)1 JObject (j.common.JObject)1 JUtilSorter (j.util.JUtilSorter)1 Iterator (java.util.Iterator)1 Properties (java.util.Properties)1 Context (javax.naming.Context)1 InitialContext (javax.naming.InitialContext)1