本文整理汇总了Java中org.wso2.carbon.context.PrivilegedCarbonContext.endTenantFlow方法的典型用法代码示例。如果您正苦于以下问题:Java PrivilegedCarbonContext.endTenantFlow方法的具体用法?Java PrivilegedCarbonContext.endTenantFlow怎么用?Java PrivilegedCarbonContext.endTenantFlow使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.wso2.carbon.context.PrivilegedCarbonContext
的用法示例。
在下文中一共展示了PrivilegedCarbonContext.endTenantFlow方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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();
}
}
示例2: 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();
}
}
示例3: 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();
}
}
示例4: 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();
}
}
示例5: getIdentityResource
import org.wso2.carbon.context.PrivilegedCarbonContext; //导入方法依赖的package包/类
@Override
public Resource getIdentityResource(String path,
String tenantDomain) throws IdentityRuntimeException {
startTenantFlow(tenantDomain);
try {
Registry registry = getRegistryForTenant(tenantDomain);
Resource resource = null;
if (registry.resourceExists(path)) {
resource = registry.get(path);
}
return resource;
} catch (RegistryException e) {
String errorMsg = String.format(ERROR_GET_RESOURCE, path, tenantDomain);
throw IdentityRuntimeException.error(errorMsg, e);
} finally {
PrivilegedCarbonContext.endTenantFlow();
}
}
示例6: putIdentityResource
import org.wso2.carbon.context.PrivilegedCarbonContext; //导入方法依赖的package包/类
@Override
public void putIdentityResource(Resource identityResource,
String path,
String tenantDomain) throws IdentityRuntimeException {
startTenantFlow(tenantDomain);
try {
Registry registry = getRegistryForTenant(tenantDomain);
registry.put(path, identityResource);
if (log.isDebugEnabled()) {
log.debug(String.format(MSG_RESOURCE_PERSIST, path, tenantDomain));
}
} catch (RegistryException e) {
String errorMsg = String.format(ERROR_PERSIST_RESOURCE, tenantDomain, path);
throw IdentityRuntimeException.error(errorMsg, e);
} finally {
PrivilegedCarbonContext.endTenantFlow();
}
}
示例7: 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();
}
}
示例8: 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();
}
}
示例9: addCommandOperationInvalidDeviceIds
import org.wso2.carbon.context.PrivilegedCarbonContext; //导入方法依赖的package包/类
@Test
public void addCommandOperationInvalidDeviceIds() throws DeviceManagementException, OperationManagementException,
InvalidDeviceException {
startTenantFlowAsNonAdmin();
try {
ArrayList<DeviceIdentifier> invalidDevices = new ArrayList<>();
for (int i = 0; i < 3; i++) {
invalidDevices.add(new DeviceIdentifier(INVALID_DEVICE + i, DEVICE_TYPE));
}
invalidDevices.addAll(this.deviceIds);
Activity activity = this.operationMgtService.addOperation(getOperation(new CommandOperation(),
Operation.Type.COMMAND, COMMAND_OPERATON_CODE), invalidDevices);
Assert.assertEquals(activity.getActivityStatus().size(), invalidDevices.size(),
"The operation response for add operation only have - " + activity.getActivityStatus().size());
for (int i = 0; i < activity.getActivityStatus().size(); i++) {
ActivityStatus status = activity.getActivityStatus().get(i);
if (i < 3) {
Assert.assertEquals(status.getStatus(), ActivityStatus.Status.INVALID);
} else {
Assert.assertEquals(status.getStatus(), ActivityStatus.Status.UNAUTHORIZED);
}
}
} finally {
PrivilegedCarbonContext.endTenantFlow();
}
}
示例10: 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();
}
}
示例11: 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();
}
}
示例12: updateOperationAsNonAdmin
import org.wso2.carbon.context.PrivilegedCarbonContext; //导入方法依赖的package包/类
@Test(dependsOnMethods = "updateOperation", expectedExceptions = OperationManagementException.class)
public void updateOperationAsNonAdmin() throws OperationManagementException {
//This is required to introduce a delay for the update operation of the device.
try {
Thread.sleep(2000);
} catch (InterruptedException ignored) {
}
try {
DeviceIdentifier deviceIdentifier = this.deviceIds.get(0);
List operations = this.operationMgtService.getPendingOperations(deviceIdentifier);
Assert.assertTrue(operations != null && operations.size() == 3);
startTenantFlowAsNonAdmin();
Operation operation = (Operation) operations.get(0);
operation.setStatus(Operation.Status.COMPLETED);
operation.setOperationResponse("The operation is successfully completed, and updated by non admin!");
this.operationMgtService.updateOperation(deviceIdentifier, operation);
List pendingOperations = this.operationMgtService.getPendingOperations(deviceIdentifier);
Assert.assertEquals(pendingOperations.size(), 3);
} finally {
PrivilegedCarbonContext.endTenantFlow();
}
}
示例13: 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();
}
}
示例14: isResourceExists
import org.wso2.carbon.context.PrivilegedCarbonContext; //导入方法依赖的package包/类
@Override
public boolean isResourceExists(String path,
String tenantDomain) throws IdentityRuntimeException {
startTenantFlow(tenantDomain);
try {
Registry registry = getRegistryForTenant(tenantDomain);
return registry.resourceExists(path);
} catch (RegistryException e) {
String errorMsg = "Error when checking for resource existence at %s in %s tenant domain.";
throw IdentityRuntimeException.error(String.format(errorMsg, path, tenantDomain), e);
} finally {
PrivilegedCarbonContext.endTenantFlow();
}
}
示例15: 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();
}
}