当前位置: 首页>>代码示例>>Java>>正文


Java PrivilegedCarbonContext.getThreadLocalCarbonContext方法代码示例

本文整理汇总了Java中org.wso2.carbon.context.PrivilegedCarbonContext.getThreadLocalCarbonContext方法的典型用法代码示例。如果您正苦于以下问题:Java PrivilegedCarbonContext.getThreadLocalCarbonContext方法的具体用法?Java PrivilegedCarbonContext.getThreadLocalCarbonContext怎么用?Java PrivilegedCarbonContext.getThreadLocalCarbonContext使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.wso2.carbon.context.PrivilegedCarbonContext的用法示例。


在下文中一共展示了PrivilegedCarbonContext.getThreadLocalCarbonContext方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: startTenantFlow

import org.wso2.carbon.context.PrivilegedCarbonContext; //导入方法依赖的package包/类
/**
 * Starts the tenant flow for the given tenant domain
 *
 * @param tenantDomain tenant domain
 */
public static void startTenantFlow(String tenantDomain) {
    String tenantDomainParam = tenantDomain;
    int tenantId = MultitenantConstants.SUPER_TENANT_ID;

    if (tenantDomainParam != null && !tenantDomainParam.trim().isEmpty()) {
        try {
            tenantId = FrameworkServiceComponent.getRealmService().getTenantManager()
                    .getTenantId(tenantDomain);
        } catch (UserStoreException e) {
            log.error("Error while getting tenantId from tenantDomain query param", e);
        }
    } else {
        tenantDomainParam = MultitenantConstants.SUPER_TENANT_DOMAIN_NAME;
    }

    PrivilegedCarbonContext.startTenantFlow();
    PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext
            .getThreadLocalCarbonContext();
    carbonContext.setTenantId(tenantId);
    carbonContext.setTenantDomain(tenantDomainParam);
}
 
开发者ID:wso2,项目名称:carbon-identity-framework,代码行数:27,代码来源:FrameworkUtils.java

示例2: get

import org.wso2.carbon.context.PrivilegedCarbonContext; //导入方法依赖的package包/类
public EntitlementEngine get(int key) {
    try {
        PrivilegedCarbonContext.startTenantFlow();
        PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
        carbonContext.setTenantId(MultitenantConstants.SUPER_TENANT_ID);
        carbonContext.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
        EntitlementEngine entitlementEngine = getEntitlementCache().get(key);
        if (entitlementEngine != null) {
            if (log.isDebugEnabled()) {
                log.debug("Cache : " + ENTITLEMENT_ENGINE_CACHE + "  is HIT " +
                        "for tenantId : " + key);
            }
        } else {
            if (log.isDebugEnabled()) {
                log.debug("Cache : " + ENTITLEMENT_ENGINE_CACHE + "  is MISSED " +
                        "for tenantId : " + key);
            }
        }
        return entitlementEngine;
    } finally {
        PrivilegedCarbonContext.endTenantFlow();
    }
}
 
开发者ID:wso2,项目名称:carbon-identity-framework,代码行数:24,代码来源:EntitlementEngineCache.java

示例3: contains

import org.wso2.carbon.context.PrivilegedCarbonContext; //导入方法依赖的package包/类
public boolean contains(int key) {
    try {
        PrivilegedCarbonContext.startTenantFlow();
        PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
        carbonContext.setTenantId(MultitenantConstants.SUPER_TENANT_ID);
        carbonContext.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
        boolean contain = getEntitlementCache().containsKey(key);
        if (contain) {
            if (log.isDebugEnabled()) {
                log.debug("Cache : " + ENTITLEMENT_ENGINE_CACHE + "  is HIT " +
                        "for tenantId : " + key);
            }
        } else {
            if (log.isDebugEnabled()) {
                log.debug("Cache : " + ENTITLEMENT_ENGINE_CACHE + "  is MISSED " +
                        "for tenantId : " + key);
            }
        }
        return contain;
    } finally {
        PrivilegedCarbonContext.endTenantFlow();
    }
}
 
开发者ID:wso2,项目名称:carbon-identity-framework,代码行数:24,代码来源:EntitlementEngineCache.java

示例4: addToCache

import org.wso2.carbon.context.PrivilegedCarbonContext; //导入方法依赖的package包/类
/**
 * Add a cache entry.
 *
 * @param key   Key which cache entry is indexed.
 * @param entry Actual object where cache entry is placed.
 */
public void addToCache(K key, V entry) {
    if (!isEnabled()) {
        return;
    }

    try {
        PrivilegedCarbonContext.startTenantFlow();
        PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext
                .getThreadLocalCarbonContext();
        carbonContext.setTenantId(MultitenantConstants.SUPER_TENANT_ID);
        carbonContext.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
        // Element already in the cache. Remove it first
        Cache<K, V> cache = getBaseCache();
        if (cache != null) {
            cache.put(key, entry);
        }
    } finally {
        PrivilegedCarbonContext.endTenantFlow();
    }
}
 
开发者ID:wso2,项目名称:carbon-identity-framework,代码行数:27,代码来源:BaseCache.java

示例5: getValueFromCache

import org.wso2.carbon.context.PrivilegedCarbonContext; //导入方法依赖的package包/类
/**
 * Retrieves a cache entry.
 *
 * @param key CacheKey
 * @return Cached entry.
 */
public V getValueFromCache(K key) {
    if (!isEnabled()) {
        return null;
    }

    if(key == null) {
        return null;
    }

    try {
        PrivilegedCarbonContext.startTenantFlow();
        PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext
                .getThreadLocalCarbonContext();
        carbonContext.setTenantId(MultitenantConstants.SUPER_TENANT_ID);
        carbonContext.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
        Cache<K, V> cache = getBaseCache();
        if (cache != null && cache.get(key) != null) {
            return (V) cache.get(key);
        }
        return null;
    } finally {
        PrivilegedCarbonContext.endTenantFlow();
    }
}
 
开发者ID:wso2,项目名称:carbon-identity-framework,代码行数:31,代码来源:BaseCache.java

示例6: clearCacheEntry

import org.wso2.carbon.context.PrivilegedCarbonContext; //导入方法依赖的package包/类
/**
 * Clears a cache entry.
 *
 * @param key Key to clear cache.
 */
public void clearCacheEntry(K key) {
    if (!isEnabled()) {
        return;
    }

    try {
        PrivilegedCarbonContext.startTenantFlow();
        PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext
                .getThreadLocalCarbonContext();
        carbonContext.setTenantId(MultitenantConstants.SUPER_TENANT_ID);
        carbonContext.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
        Cache<K, V> cache = getBaseCache();
        if (cache != null) {
            cache.remove(key);
        }
    } finally {
        PrivilegedCarbonContext.endTenantFlow();
    }
}
 
开发者ID:wso2,项目名称:carbon-identity-framework,代码行数:25,代码来源:BaseCache.java

示例7: clear

import org.wso2.carbon.context.PrivilegedCarbonContext; //导入方法依赖的package包/类
/**
 * Remove everything in the cache.
 */
public void clear() {
    if (!isEnabled()) {
        return;
    }

    try {
        PrivilegedCarbonContext.startTenantFlow();
        PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext
                .getThreadLocalCarbonContext();
        carbonContext.setTenantId(MultitenantConstants.SUPER_TENANT_ID);
        carbonContext.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
        Cache<K, V> cache = getBaseCache();
        if (cache != null) {
            cache.removeAll();
        }
    } finally {
        PrivilegedCarbonContext.endTenantFlow();
    }
}
 
开发者ID:wso2,项目名称:carbon-identity-framework,代码行数:23,代码来源:BaseCache.java

示例8: bundleChanged

import org.wso2.carbon.context.PrivilegedCarbonContext; //导入方法依赖的package包/类
@Override
public void bundleChanged(BundleEvent event) {
    Bundle bundle = event.getBundle();
    try {
        PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
        carbonContext.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
        carbonContext.setTenantId(MultitenantConstants.SUPER_TENANT_ID);

        if (event.getType() == BundleEvent.STARTED) {
            addUIPermissionFromBundle(bundle);
        }
    } catch (Exception e) {
        log.error("Error occured when processing component xml in bundle " +
                bundle.getSymbolicName(), e);
    }
}
 
开发者ID:wso2,项目名称:carbon-identity-framework,代码行数:17,代码来源:ManagementPermissionsAdder.java

示例9: getModel

import org.wso2.carbon.context.PrivilegedCarbonContext; //导入方法依赖的package包/类
/**
 * Get the model data
 *
 * @param modelName Name of the model
 * @return JSON of {@link MLModelData} object
 */
@GET
@Path("/{modelName}")
@Produces("application/json")
public Response getModel(@PathParam("modelName") String modelName) {
    PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
    int tenantId = carbonContext.getTenantId();
    String userName = carbonContext.getUsername();
    try {
        MLModelData model = mlModelHandler.getModel(tenantId, userName, modelName);
        if (model == null) {
            return Response.status(Response.Status.NOT_FOUND).build();
        }
        return Response.ok(model).build();
    } catch (MLModelHandlerException e) {
        String msg = MLUtils.getErrorMsg(String.format(
                "Error occurred while retrieving a model [name] %s of tenant [id] %s and [user] %s .", modelName,
                tenantId, userName), e);
        logger.error(msg, e);
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(new MLErrorBean(e.getMessage()))
                .build();
    }
}
 
开发者ID:wso2-attic,项目名称:carbon-ml,代码行数:29,代码来源:ModelApiV11.java

示例10: getfilteredFeatures

import org.wso2.carbon.context.PrivilegedCarbonContext; //导入方法依赖的package包/类
/**
 * Get filtered feature names of an analysis.
 * @param analysisId Unique id of the analysis
 * @param featureType Feature type need to retrieve (Categorical or Numerical)
 * @return JSON array of feature names
 */
@GET
@Path("/{analysisId}/filteredFeatures")
@Produces("application/json")
public Response getfilteredFeatures(@PathParam("analysisId") String analysisId,
        @QueryParam("featureType") String featureType) {
    PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
    int tenantId = carbonContext.getTenantId();
    String userName = carbonContext.getUsername();
    try {

        List<String> features = mlAnalysisHandler.getFeatureNames(analysisId, featureType);
        return Response.ok(features).build();
    } catch (MLAnalysisHandlerException e) {
        String msg = MLUtils
                .getErrorMsg(
                        String.format(
                                "Error occurred while retrieving filtered feature names for the analysis [id] %s of tenant [id] %s and [user] %s .",
                                analysisId, tenantId, userName), e);
        logger.error(msg, e);
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(new MLErrorBean(e.getMessage()))
                .build();
    }
}
 
开发者ID:wso2-attic,项目名称:carbon-ml,代码行数:30,代码来源:AnalysisApiV11.java

示例11: logout

import org.wso2.carbon.context.PrivilegedCarbonContext; //导入方法依赖的package包/类
/**
 * Logout.
 */
@POST
@Path("/logout")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public Response logout() {
    HttpSession session = httpServletRequest.getSession();
    PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
    String username = carbonContext.getUsername();
    String tenantDomain = carbonContext.getTenantDomain();
    int tenantId = carbonContext.getTenantId();
    if (session != null) {
        session.invalidate();
    }
    auditLog.info(String.format(
            "User [name] %s of tenant [id] %s [domain] %s is logged-out from WSO2 Machine Learner. "
                    + "Granted session id is %s", username, tenantId, tenantDomain, session == null ? null
                    : session.getId()));
    return Response.status(Response.Status.OK).entity("User logged out: " + carbonContext.getUsername()).build();
}
 
开发者ID:wso2-attic,项目名称:carbon-ml,代码行数:23,代码来源:LoginLogoutApiV10.java

示例12: getRecommendations

import org.wso2.carbon.context.PrivilegedCarbonContext; //导入方法依赖的package包/类
/**
 * Get the model data
 * @param modelName Name of the model
 * @return JSON of {@link org.wso2.carbon.ml.commons.domain.MLModelData} object
 */
@GET
@Path("/{modelId}/getRecommendations/{userId}/{noOfProducts}")
@Produces("application/json")
public Response getRecommendations(@PathParam("modelId") long modelId,
                                   @PathParam("userId") int userId,
                                   @PathParam("noOfProducts") int noOfProducts) {

    PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
    int tenantId = carbonContext.getTenantId();
    String userName = carbonContext.getUsername();
    try {
        List<?> recommendations =
                mlModelHandler.getProductRecommendations(tenantId, userName, modelId, userId, noOfProducts);
        return Response.ok(recommendations).build();
    } catch (MLModelHandlerException e) {
        String msg = MLUtils.getErrorMsg(String.format("Error occurred while getting recommendations from model [id] %s of tenant [id] %s and [user] %s.",
                                                 modelId, tenantId, userName), e);
        logger.error(msg, e);
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(new MLErrorBean(e.getMessage()))
                       .build();
    }
}
 
开发者ID:wso2-attic,项目名称:carbon-ml,代码行数:28,代码来源:ModelApiV10.java

示例13: getProductVariable

import org.wso2.carbon.context.PrivilegedCarbonContext; //导入方法依赖的package包/类
/**
 * get the product variable of an analysis.
 */
@GET
@Path("/{analysisId}/productVariable")
@Produces("application/json")
@Consumes("application/json")
public Response getProductVariable(@PathParam("analysisId") long analysisId) {
    PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
    int tenantId = carbonContext.getTenantId();
    String userName = carbonContext.getUsername();
    try {
        String productVariable = mlAnalysisHandler.getProductVariable(analysisId);
        return Response.ok(productVariable).build();
    } catch (MLAnalysisHandlerException e) {
        String msg = MLUtils
                .getErrorMsg(
                        String.format(
                                "Error occurred while retrieving product variable for the analysis [id] %s of tenant [id] %s and [user] %s .",
                                analysisId, tenantId, userName), e);
        logger.error(msg, e);
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(new MLErrorBean(e.getMessage()))
                       .build();
    }
}
 
开发者ID:wso2-attic,项目名称:carbon-ml,代码行数:26,代码来源:AnalysisApiV11.java

示例14: getObservationList

import org.wso2.carbon.context.PrivilegedCarbonContext; //导入方法依赖的package包/类
/**
 * get the observation list fraction of an analysis.
 */
@GET
@Path("/{analysisId}/observationList")
@Produces("application/json")
@Consumes("application/json")
public Response getObservationList(@PathParam("analysisId") long analysisId) {
	PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
	int tenantId = carbonContext.getTenantId();
	String userName = carbonContext.getUsername();
	try {
		String observations = mlAnalysisHandler.getObservations(analysisId);
		return Response.ok(observations).build();
	} catch (MLAnalysisHandlerException e) {
		String msg = MLUtils
				.getErrorMsg(
						String.format(
								"Error occurred while retrieving observations for the analysis [id] %s of tenant [id] %s and [user] %s .",
								analysisId, tenantId, userName), e);
		logger.error(msg, e);
		return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(new MLErrorBean(e.getMessage()))
		               .build();
	}
}
 
开发者ID:wso2-attic,项目名称:carbon-ml,代码行数:26,代码来源:AnalysisApiV11.java

示例15: getProject

import org.wso2.carbon.context.PrivilegedCarbonContext; //导入方法依赖的package包/类
/**
 * Get project by project name
 * @param projectName Name of the project
 * @return JSON of {@link org.wso2.carbon.ml.commons.domain.MLProject} object
 */
@GET
@Path("/{projectName}")
@Produces("application/json")
public Response getProject(@PathParam("projectName") String projectName) {
    PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
    int tenantId = carbonContext.getTenantId();
    String userName = carbonContext.getUsername();
    try {
        MLProject project = mlProjectHandler.getProject(tenantId, userName, projectName);
        if (project == null) {
            return Response.status(Response.Status.NOT_FOUND).build();
        }
        return Response.ok(project).build();
    } catch (MLProjectHandlerException e) {
        String msg = MLUtils.getErrorMsg(String.format(
                "Error occurred while retrieving a project [name] %s of tenant [id] %s and [user] %s .",
                projectName, tenantId, userName), e);
        logger.error(msg, e);
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(new MLErrorBean(e.getMessage()))
                .build();
    }
}
 
开发者ID:wso2-attic,项目名称:carbon-ml,代码行数:28,代码来源:ProjectApiV10.java


注:本文中的org.wso2.carbon.context.PrivilegedCarbonContext.getThreadLocalCarbonContext方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。