本文整理汇总了Java中org.wso2.carbon.context.PrivilegedCarbonContext.startTenantFlow方法的典型用法代码示例。如果您正苦于以下问题:Java PrivilegedCarbonContext.startTenantFlow方法的具体用法?Java PrivilegedCarbonContext.startTenantFlow怎么用?Java PrivilegedCarbonContext.startTenantFlow使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.wso2.carbon.context.PrivilegedCarbonContext
的用法示例。
在下文中一共展示了PrivilegedCarbonContext.startTenantFlow方法的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);
}
示例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();
}
}
示例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();
}
}
示例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();
}
}
示例5: getOperationsPaginatedRequest
import org.wso2.carbon.context.PrivilegedCarbonContext; //导入方法依赖的package包/类
@Test(description = "Get operations with paginated request",
expectedExceptions = OperationManagementException.class)
public void getOperationsPaginatedRequest() throws OperationManagementException {
PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(MultitenantConstants.SUPER_TENANT_ID, true);
PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(ADMIN_USER);
PaginationRequest request = new PaginationRequest(1, 2);
request.setDeviceType(DEVICE_TYPE);
request.setOwner(ADMIN_USER);
this.dataSource.setThrowException(true);
try {
this.operationMgtService.getOperations(this.deviceIds.get(0), request);
} finally {
PrivilegedCarbonContext.endTenantFlow();
this.dataSource.reset();
}
}
示例6: getPaginatedRequestAsAdmin
import org.wso2.carbon.context.PrivilegedCarbonContext; //导入方法依赖的package包/类
@Test(dependsOnMethods = "getPendingOperations")
public void getPaginatedRequestAsAdmin() throws OperationManagementException {
PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(MultitenantConstants.SUPER_TENANT_ID, true);
PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(ADMIN_USER);
PaginationRequest request = new PaginationRequest(1, 2);
request.setDeviceType(DEVICE_TYPE);
request.setOwner(ADMIN_USER);
for (DeviceIdentifier deviceIdentifier : deviceIds) {
PaginationResult result = this.operationMgtService.getOperations(deviceIdentifier, request);
Assert.assertEquals(result.getRecordsFiltered(), 4);
Assert.assertEquals(result.getData().size(), 2);
Assert.assertEquals(result.getRecordsTotal(), 4);
}
PrivilegedCarbonContext.endTenantFlow();
}
示例7: getPaginatedOperationDeviceForInvalidDevice
import org.wso2.carbon.context.PrivilegedCarbonContext; //导入方法依赖的package包/类
@Test(dependsOnMethods = "getOperationForInactiveDevice", expectedExceptions = OperationManagementException.class)
public void getPaginatedOperationDeviceForInvalidDevice() throws DeviceManagementException,
OperationManagementException {
PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(MultitenantConstants.SUPER_TENANT_ID, true);
PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(ADMIN_USER);
try {
PaginationRequest request = new PaginationRequest(1, 2);
request.setDeviceType(DEVICE_TYPE);
request.setOwner(ADMIN_USER);
PaginationResult result = this.operationMgtService.getOperations
(new DeviceIdentifier(INVALID_DEVICE, DEVICE_TYPE), request);
Assert.assertEquals(result.getRecordsFiltered(), 4);
Assert.assertEquals(result.getData().size(), 2);
Assert.assertEquals(result.getRecordsTotal(), 4);
} finally {
PrivilegedCarbonContext.endTenantFlow();
}
}
示例8: getConfigRegistryResourceContent
import org.wso2.carbon.context.PrivilegedCarbonContext; //导入方法依赖的package包/类
/**
* Get the jwt details from the registry for tenants.
*
* @param tenantId for identify tenant space.
* @param registryLocation retrive the config file from tenant space.
* @return the config for tenant
* @throws RegistryException
*/
public static Resource getConfigRegistryResourceContent(int tenantId, final String registryLocation)
throws RegistryException {
try {
Resource resource = null;
PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(tenantId, true);
RegistryService registryService = JWTClientExtensionDataHolder.getInstance().getRegistryService();
if (registryService != null) {
Registry registry = registryService.getConfigSystemRegistry(tenantId);
JWTClientUtil.loadTenantRegistry(tenantId);
if (registry.resourceExists(registryLocation)) {
resource = registry.get(registryLocation);
}
}
return resource;
} finally {
PrivilegedCarbonContext.endTenantFlow();
}
}
示例9: addJWTConfigResourceToRegistry
import org.wso2.carbon.context.PrivilegedCarbonContext; //导入方法依赖的package包/类
/**
* Get the jwt details from the registry for tenants.
*
* @param tenantId for accesing tenant space.
* @return the config for tenant
* @throws RegistryException
*/
public static void addJWTConfigResourceToRegistry(int tenantId, String content)
throws RegistryException {
try {
PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(tenantId, true);
RegistryService registryService = JWTClientExtensionDataHolder.getInstance().getRegistryService();
if (registryService != null) {
Registry registry = registryService.getConfigSystemRegistry(tenantId);
JWTClientUtil.loadTenantRegistry(tenantId);
if (!registry.resourceExists(TENANT_JWT_CONFIG_LOCATION)) {
Resource resource = registry.newResource();
resource.setContent(content.getBytes());
registry.put(TENANT_JWT_CONFIG_LOCATION, resource);
}
}
} finally {
PrivilegedCarbonContext.endTenantFlow();
}
}
示例10: register
import org.wso2.carbon.context.PrivilegedCarbonContext; //导入方法依赖的package包/类
@POST
@Override
public Response register(RegistrationProfile profile) {
try {
PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(
MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(MultitenantConstants.SUPER_TENANT_ID);
OAuthApplicationInfo info = this.registerApplication(profile);
return Response.status(Response.Status.ACCEPTED).entity(info.toString()).build();
} catch (APIManagementException e) {
String msg = "Error occurred while registering client '" + profile.getClientName() + "'";
log.error(msg, e);
return Response.serverError().entity(msg).build();
} finally {
PrivilegedCarbonContext.endTenantFlow();
}
}
示例11: setupMqttOutputAdapter
import org.wso2.carbon.context.PrivilegedCarbonContext; //导入方法依赖的package包/类
public static void setupMqttOutputAdapter() throws IOException {
OutputEventAdapterConfiguration outputEventAdapterConfiguration =
createMqttOutputEventAdapterConfiguration(DeviceTypeConstants.MQTT_ADAPTER_NAME,
DeviceTypeConstants.MQTT_ADAPTER_TYPE, MessageType.TEXT);
try {
PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(
DeviceTypeConstants.DEVICE_TYPE_PROVIDER_DOMAIN, true);
DeviceTypeManagementDataHolder.getInstance().getOutputEventAdapterService()
.create(outputEventAdapterConfiguration);
} catch (OutputEventAdapterException e) {
log.error("Unable to create Output Event Adapter : " + DeviceTypeConstants.MQTT_ADAPTER_NAME, e);
} finally {
PrivilegedCarbonContext.endTenantFlow();
}
}
示例12: createRealmService
import org.wso2.carbon.context.PrivilegedCarbonContext; //导入方法依赖的package包/类
private void createRealmService(WithRealmService withRealmService) {
try {
int tenantId = withRealmService.tenantId();
String tenantDomain = withRealmService.tenantDomain();
PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(tenantId);
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain);
RealmService realmService = new InMemoryRealmService(tenantId);
UserStoreManager userStoreManager = realmService.getTenantUserRealm(tenantId).getUserStoreManager();
((MockUserStoreManager) userStoreManager)
.addSecondaryUserStoreManager("PRIMARY", (MockUserStoreManager) userStoreManager);
IdentityTenantUtil.setRealmService(realmService);
RegistryDataHolder.getInstance().setRealmService(realmService);
Class[] singletonClasses = withRealmService.injectToSingletons();
for (Class singletonClass : singletonClasses) {
Object instance = getSingletonInstance(singletonClass);
if (instance != null) {
setInstanceValue(realmService, RealmService.class, singletonClass, instance);
} else {
setInstanceValue(realmService, RealmService.class, singletonClass, null);
}
}
} catch (UserStoreException e) {
log.error("Error setting the realm.", e);
} finally {
PrivilegedCarbonContext.endTenantFlow();
}
}
示例13: initPrivilegedCarbonContext
import org.wso2.carbon.context.PrivilegedCarbonContext; //导入方法依赖的package包/类
public static void initPrivilegedCarbonContext() throws Exception {
System.setProperty(
CarbonBaseConstants.CARBON_HOME,
Paths.get(System.getProperty("user.dir"), "src", "test", "resources").toString()
);
PrivilegedCarbonContext.startTenantFlow();
}
示例14: run
import org.wso2.carbon.context.PrivilegedCarbonContext; //导入方法依赖的package包/类
public void run() {
PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext context = PrivilegedCarbonContext.getThreadLocalCarbonContext();
context.setTenantDomain(tenantDomain);
context.setTenantId(tenantId);
context.setUsername(userName);
try {
publish();
} finally {
PrivilegedCarbonContext.endTenantFlow();
}
}
示例15: put
import org.wso2.carbon.context.PrivilegedCarbonContext; //导入方法依赖的package包/类
public void put(int key, EntitlementEngine engine) {
try {
PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
carbonContext.setTenantId(MultitenantConstants.SUPER_TENANT_ID);
carbonContext.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
getEntitlementCache().put(key, engine);
if (log.isDebugEnabled()) {
log.debug("Cache : " + ENTITLEMENT_ENGINE_CACHE + " is populated with new entry " +
"with tenantId : " + key);
}
} finally {
PrivilegedCarbonContext.endTenantFlow();
}
}