Java Code Examples for org.wso2.carbon.context.PrivilegedCarbonContext#endTenantFlow()
The following examples show how to use
org.wso2.carbon.context.PrivilegedCarbonContext#endTenantFlow() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RegistryBasedTaskRepository.java From carbon-commons with Apache License 2.0 | 6 votes |
@Override public synchronized void addTask(TaskInfo taskInfo) throws TaskException { String tasksPath = this.getMyTasksPath(); String currentTaskPath = tasksPath + "/" + taskInfo.getName(); try { PrivilegedCarbonContext.startTenantFlow(); PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain( MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, true); ByteArrayOutputStream out = new ByteArrayOutputStream(); getTaskMarshaller().marshal(taskInfo, out); ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); Resource resource = getRegistry().newResource(); resource.setContentStream(in); getRegistry().put(currentTaskPath, resource); } catch (Exception e) { throw new TaskException("Error in adding task '" + taskInfo.getName() + "' to the repository: " + e.getMessage(), Code.CONFIG_ERROR, e); } finally { PrivilegedCarbonContext.endTenantFlow(); } }
Example 2
Source File: UserStoreActionListener.java From carbon-identity with Apache License 2.0 | 6 votes |
@Override public boolean doPreDeleteUserClaimValues(String userName, String[] claims, String profileName, UserStoreManager userStoreManager) throws UserStoreException { if (!isEnable() || isCalledViaIdentityMgtListners()) { return true; } try { DeleteMultipleClaimsWFRequestHandler deleteMultipleClaimsWFRequestHandler = new DeleteMultipleClaimsWFRequestHandler(); String domain = userStoreManager.getRealmConfiguration().getUserStoreProperty(UserCoreConstants.RealmConfig .PROPERTY_DOMAIN_NAME); int tenantId = userStoreManager.getTenantId() ; String currentUser = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); PrivilegedCarbonContext.startTenantFlow(); PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(tenantId, true); PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(currentUser); return deleteMultipleClaimsWFRequestHandler.startDeleteMultipleClaimsWorkflow(domain, userName, claims, profileName); } catch (WorkflowException e) { // Sending e.getMessage() since it is required to give error message to end user. throw new UserStoreException(e.getMessage(), e); } finally { PrivilegedCarbonContext.endTenantFlow(); } }
Example 3
Source File: UserStoreActionListener.java From carbon-identity with Apache License 2.0 | 6 votes |
@Override public boolean doPreSetUserClaimValues(String userName, Map<String, String> claims, String profileName, UserStoreManager userStoreManager) throws UserStoreException { if (!isEnable() || isCalledViaIdentityMgtListners()) { return true; } try { SetMultipleClaimsWFRequestHandler setMultipleClaimsWFRequestHandler = new SetMultipleClaimsWFRequestHandler(); String domain = userStoreManager.getRealmConfiguration().getUserStoreProperty(UserCoreConstants.RealmConfig .PROPERTY_DOMAIN_NAME); int tenantId = userStoreManager.getTenantId() ; String currentUser = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); PrivilegedCarbonContext.startTenantFlow(); PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(tenantId, true); PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(currentUser); return setMultipleClaimsWFRequestHandler.startSetMultipleClaimsWorkflow(domain, userName, claims, profileName); } catch (WorkflowException e) { // Sending e.getMessage() since it is required to give error message to end user. throw new UserStoreException(e.getMessage(), e); } finally { PrivilegedCarbonContext.endTenantFlow(); } }
Example 4
Source File: BaseCache.java From carbon-identity-framework with Apache License 2.0 | 6 votes |
/** * 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(); } }
Example 5
Source File: Utils.java From carbon-apimgt with Apache License 2.0 | 6 votes |
/** * Put the access token that was cached in the tenant's cache space into invalid token cache * * @param accessToken - Invalid token that should be added to the invalid token cache * @param cachedTenantDomain - Tenant domain of the cached token */ public static void putInvalidTokenIntoTenantInvalidTokenCache(String accessToken, String cachedTenantDomain) { //If the token was cached in the tenant cache if (cachedTenantDomain != null && !MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(cachedTenantDomain)) { if (log.isDebugEnabled()) { log.debug("Putting the cache entry " + accessToken + " of " + cachedTenantDomain + " domain " + "to the invalid token cache..."); } try { PrivilegedCarbonContext.startTenantFlow(); PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(cachedTenantDomain, true); putInvalidTokenEntryIntoInvalidTokenCache(accessToken, cachedTenantDomain); if (log.isDebugEnabled()) { log.debug(" Token " + accessToken + " of " + cachedTenantDomain + " domain was put to the " + "invalid token cache."); } } finally { PrivilegedCarbonContext.endTenantFlow(); } } }
Example 6
Source File: RemoteTaskManager.java From carbon-commons with Apache License 2.0 | 6 votes |
@Override public void execute(ConfigurationContext ctx) throws ClusteringFault { try { PrivilegedCarbonContext.startTenantFlow(); PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(this.getTenantId(), true); TaskManager tm = TasksDSComponent.getTaskService().getTaskManager( this.getTaskType()); if (tm instanceof RemoteTaskManager) { this.result = new TaskStatusResult(); this.result.setRunning(((RemoteTaskManager) tm).isTaskRunning(this .getTaskName())); } } catch (Exception e) { throw new ClusteringFault(e.getMessage(), e); } finally { PrivilegedCarbonContext.endTenantFlow(); } }
Example 7
Source File: RegistryDataManager.java From product-ei with Apache License 2.0 | 6 votes |
/** * Method to migrate encrypted password of SYSLOG_PROPERTIES registry resource * * @param migrateActiveTenantsOnly * @throws UserStoreException user store exception */ public void migrateSysLogPropertyPassword(boolean migrateActiveTenantsOnly) throws UserStoreException, RegistryException, CryptoException { try { //migrating super tenant configurations migrateSysLogPropertyPasswordForTenant(SUPER_TENANT_ID); log.info("Sys log property password migrated for tenant : " + SUPER_TENANT_DOMAIN_NAME); } catch (Exception e) { log.error("Error while migrating Sys log property password for tenant : " + SUPER_TENANT_DOMAIN_NAME, e); } Tenant[] tenants = MigrationServiceDataHolder.getRealmService().getTenantManager().getAllTenants(); for (Tenant tenant : tenants) { if (migrateActiveTenantsOnly && !tenant.isActive()) { log.info("Tenant " + tenant.getDomain() + " is inactive. Skipping SYSLOG_PROPERTIES file migration. "); continue; } try { migrateSysLogPropertyPasswordForTenant(tenant.getId()); } finally { PrivilegedCarbonContext.endTenantFlow(); } } }
Example 8
Source File: BaseCache.java From carbon-identity with Apache License 2.0 | 6 votes |
/** * 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(); } }
Example 9
Source File: SSOConsentServiceImpl.java From carbon-identity-framework with Apache License 2.0 | 6 votes |
private AddReceiptResponse addReceipt(String subject, String subjectTenantDomain, ServiceProvider serviceProvider, String spTenantDomain, List<ClaimMetaData> claims) throws SSOConsentServiceException { ReceiptInput receiptInput = buildReceiptInput(subject, serviceProvider, spTenantDomain, claims); AddReceiptResponse receiptResponse; try { startTenantFlowWithUser(subject, subjectTenantDomain); receiptResponse = getConsentManager().addConsent(receiptInput); } catch (ConsentManagementException e) { throw new SSOConsentServiceException("Consent receipt error", "Error while adding the consent " + "receipt", e); } finally { PrivilegedCarbonContext.endTenantFlow(); } if (isDebugEnabled()) { logDebug("Successfully added consent receipt: " + receiptResponse.getConsentReceiptId()); } return receiptResponse; }
Example 10
Source File: EmailUserNameMigrationClient.java From product-es with Apache License 2.0 | 5 votes |
/** * This method extracts the artifact types which contains '@{overview_provider}' in the storage path, and call the * migration method. * @param tenant The tenant object * @throws UserStoreException * @throws RegistryException * @throws XMLStreamException */ private void migrate(Tenant tenant) throws UserStoreException, RegistryException, XMLStreamException{ int tenantId = tenant.getId(); try { PrivilegedCarbonContext.startTenantFlow(); PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenant.getDomain(), true); PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(tenantId); String adminName = ServiceHolder.getRealmService().getTenantUserRealm(tenantId).getRealmConfiguration() .getAdminUserName(); PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(adminName); ServiceHolder.getTenantRegLoader().loadTenantRegistry(tenantId); Registry registry = ServiceHolder.getRegistryService().getGovernanceUserRegistry(adminName, tenantId); GovernanceUtils.loadGovernanceArtifacts((UserRegistry) registry); List<GovernanceArtifactConfiguration> configurations = GovernanceUtils. findGovernanceArtifactConfigurations(registry); for (GovernanceArtifactConfiguration governanceArtifactConfiguration : configurations) { String pathExpression = governanceArtifactConfiguration.getPathExpression(); if (pathExpression.contains(Constants.OVERVIEW_PROVIDER) || hasOverviewProviderElement(governanceArtifactConfiguration)) { String shortName = governanceArtifactConfiguration.getKey(); GenericArtifactManager artifactManager = new GenericArtifactManager(registry, shortName); GenericArtifact[] artifacts = artifactManager.getAllGenericArtifacts(); migrateArtifactsWithEmailUserName(artifacts, registry); } } } finally { PrivilegedCarbonContext.endTenantFlow(); } }
Example 11
Source File: GatewayUtils.java From carbon-apimgt with Apache License 2.0 | 5 votes |
/** * Add/Update the given registry property from the given tenant registry * path * * @param propertyName property name * @param propertyValue property value * @param path resource path * @param tenantDomain * @throws APIManagementException */ public static void setRegistryProperty(String propertyName, String propertyValue, String path, String tenantDomain) throws APIManagementException { UserRegistry registry = getRegistry(tenantDomain); PrivilegedCarbonContext.startTenantFlow(); if (tenantDomain != null && StringUtils.isNotEmpty(tenantDomain)) { PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain, true); } else { PrivilegedCarbonContext.getThreadLocalCarbonContext() .setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, true); } try { Resource resource = registry.get(path); // add or update property if (resource.getProperty(propertyName) != null) { resource.setProperty(propertyName, propertyValue); } else { resource.addProperty(propertyName, propertyValue); } registry.put(resource.getPath(), resource); resource.discard(); } catch (RegistryException e) { throw new APIManagementException("Error while reading registry resource " + path + " for tenant " + tenantDomain); } finally { PrivilegedCarbonContext.endTenantFlow(); } }
Example 12
Source File: EntitlementEngineCache.java From carbon-identity-framework with Apache License 2.0 | 5 votes |
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(); } }
Example 13
Source File: UserStoreActionListener.java From carbon-identity with Apache License 2.0 | 5 votes |
@Override public boolean doPreSetUserClaimValue(String userName, String claimURI, String claimValue, String profileName, UserStoreManager userStoreManager) throws UserStoreException { if (!isEnable() || isCalledViaIdentityMgtListners()) { return true; } Map<String, String> claims = new HashMap<>(); claims.put(claimURI, claimValue); try { SetMultipleClaimsWFRequestHandler setMultipleClaimsWFRequestHandler = new SetMultipleClaimsWFRequestHandler(); String domain = userStoreManager.getRealmConfiguration().getUserStoreProperty(UserCoreConstants.RealmConfig .PROPERTY_DOMAIN_NAME); int tenantId = userStoreManager.getTenantId() ; String currentUser = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); PrivilegedCarbonContext.startTenantFlow(); PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(tenantId, true); PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(currentUser); return setMultipleClaimsWFRequestHandler.startSetMultipleClaimsWorkflow(domain, userName, claims, profileName); } catch (WorkflowException e) { // Sending e.getMessage() since it is required to give error message to end user. throw new UserStoreException(e.getMessage(), e); } finally { PrivilegedCarbonContext.endTenantFlow(); } }
Example 14
Source File: InMemoryIdentityDataStore.java From carbon-identity with Apache License 2.0 | 5 votes |
@Override public void remove(String userName, UserStoreManager userStoreManager) throws IdentityException { try { PrivilegedCarbonContext.startTenantFlow(); PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME); PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(MultitenantConstants.SUPER_TENANT_ID); Cache<String, UserIdentityClaimsDO> cache = getCache(); if (userName == null) { return; } if (userStoreManager instanceof org.wso2.carbon.user.core.UserStoreManager) { if (!IdentityUtil.isUserStoreCaseSensitive((org.wso2.carbon.user.core.UserStoreManager) userStoreManager)) { if (log.isDebugEnabled()) { log.debug("Case insensitive user store found. Changing username from : " + userName + " to : " + userName.toLowerCase()); } userName = userName.toLowerCase(); } } org.wso2.carbon.user.core.UserStoreManager store = (org.wso2.carbon.user.core.UserStoreManager) userStoreManager; String domainName = store.getRealmConfiguration().getUserStoreProperty(UserCoreConstants.RealmConfig .PROPERTY_DOMAIN_NAME); cache.remove(domainName + userStoreManager.getTenantId() + userName); } catch (UserStoreException e) { log.error("Error while obtaining tenant ID from user store manager"); } finally { PrivilegedCarbonContext.endTenantFlow(); } }
Example 15
Source File: Worker.java From carbon-commons with Apache License 2.0 | 5 votes |
public void run() { try { PrivilegedCarbonContext.startTenantFlow(); PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(this.subscription.getTenantId()); PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(this.subscription.getOwner()); PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(true); this.notificationManager.sendNotification(this.message, this.subscription); } catch (EventBrokerException e) { log.error("Can not send the notification ", e); } finally { PrivilegedCarbonContext.endTenantFlow(); } }
Example 16
Source File: SelfSignUpUtil.java From carbon-apimgt with Apache License 2.0 | 5 votes |
/** * retrieve self signup configuration from the cache. if cache mises, load * to the cache from * the registry and return configuration * * @param tenantDomain * Domain name of the tenant * @return UserRegistrationConfigDTO self signup configuration for the * tenant * @throws APIManagementException */ public static UserRegistrationConfigDTO getSignupConfiguration(String tenantDomain) throws APIManagementException { UserRegistrationConfigDTO config = null; String currentFlowDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext() .getTenantDomain(); boolean isTenantFlowStarted = false; try { /* start the correct tenant flow to load the tenant's registry*/ if (tenantDomain != null && !MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(tenantDomain)) { if (!currentFlowDomain.equals(tenantDomain)) { /* if the current flow is not the one related to the domain */ isTenantFlowStarted = true; PrivilegedCarbonContext.startTenantFlow(); PrivilegedCarbonContext.getThreadLocalCarbonContext() .setTenantDomain(tenantDomain, true); } } config = getSignupConfigurationFromRegistry(tenantDomain); } finally { if (isTenantFlowStarted) { PrivilegedCarbonContext.endTenantFlow(); } } return config; }
Example 17
Source File: RemoteTaskCallbackServlet.java From carbon-commons with Apache License 2.0 | 4 votes |
@Override protected void doPost(HttpServletRequest req, HttpServletResponse res) { String taskType = null, taskName; try { String remoteTaskId = req.getHeader(REMOTE_SYSTEM_TASK_HEADER_ID); if (remoteTaskId == null) { return; } /* if task execution node is not fully started yet, ignore this remote trigger */ if (!TasksDSComponent.getTaskService().isServerInit()) { if (log.isDebugEnabled()) { log.debug("Ignoring remote task triggered before server startup: " + remoteTaskId); } return; } if (log.isDebugEnabled()) { log.debug("Remote Task Request Received: " + remoteTaskId); } Object[] taskInfo = RemoteTaskUtils.lookupRemoteTask(remoteTaskId); int tenantId = (Integer) taskInfo[0]; taskType = (String) taskInfo[1]; taskName = (String) taskInfo[2]; try { PrivilegedCarbonContext.startTenantFlow(); PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(tenantId, true); TaskManager tm = TasksDSComponent.getTaskService().getTaskManager(taskType); if (!(tm instanceof RemoteTaskManager)) { log.error("The server is not running in remote task mode, " + "the current task manager type used is '" + tm.getClass() + "'"); return; } ((RemoteTaskManager) tm).runTask(taskName); } finally { PrivilegedCarbonContext.endTenantFlow(); } } catch (TaskException e) { if (e.getCode().equals(Code.TASK_NODE_NOT_AVAILABLE)) { log.debug("Remote task request dispatched to an unsupported task node with task type: " + taskType + " returning a SC_NOT_FOUND error code"); /* this is so, a load balancer will send the request to a different task node */ res.setStatus(HttpServletResponse.SC_NOT_FOUND); } else { log.error("Error in executing remote task request: " + e.getMessage(), e); } } }
Example 18
Source File: DeviceManagementAdminServiceImpl.java From carbon-device-mgt with Apache License 2.0 | 4 votes |
@Override @GET public Response getDevicesByName(@QueryParam("name") @Size(max = 45) String name, @QueryParam("type") @Size(min = 2, max = 45) String type, @QueryParam("tenant-domain") String tenantDomain, @HeaderParam("If-Modified-Since") String ifModifiedSince, @QueryParam("offset") int offset, @QueryParam("limit") int limit) { RequestValidationUtil.validatePaginationParameters(offset, limit); int currentTenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); if (MultitenantConstants.SUPER_TENANT_ID != currentTenantId) { return Response.status(Response.Status.UNAUTHORIZED).entity( new ErrorResponse.ErrorResponseBuilder().setMessage( "Current logged in user is not authorized to perform this operation").build()).build(); } try { PrivilegedCarbonContext.startTenantFlow(); PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain); PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(DeviceMgtAPIUtils.getTenantId(tenantDomain)); PaginationRequest request = new PaginationRequest(offset, limit); request.setDeviceType(type); request.setDeviceName(name); List<Device> devices = DeviceMgtAPIUtils.getDeviceManagementService(). getDevicesByNameAndType(request, false); // setting up paginated result DeviceList deviceList = new DeviceList(); deviceList.setList(devices); deviceList.setCount(devices.size()); return Response.status(Response.Status.OK).entity(deviceList).build(); } catch (DeviceManagementException e) { String msg = "Error occurred at server side while fetching device list."; log.error(msg, e); return Response.serverError().entity( new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build(); } finally { PrivilegedCarbonContext.endTenantFlow(); } }
Example 19
Source File: ProvisioningThread.java From carbon-identity with Apache License 2.0 | 4 votes |
@Override public Boolean call() throws IdentityProvisioningException { boolean success = false; String tenantDomainName = this.tenantDomainName; try { PrivilegedCarbonContext.startTenantFlow(); PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomainName); PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(getTenantIdFromDomain(tenantDomainName)); ProvisionedIdentifier provisionedIdentifier = null; // real provisioning happens now. provisionedIdentifier = connector.provision(provisioningEntity); if (provisioningEntity.getOperation() == ProvisioningOperation.DELETE) { deleteProvisionedEntityIdentifier(idPName, connectorType, provisioningEntity, tenantDomainName); } else if (provisioningEntity.getOperation() == ProvisioningOperation.POST) { if (provisionedIdentifier == null || provisionedIdentifier.getIdentifier() == null) { provisionedIdentifier = new ProvisionedIdentifier(); provisionedIdentifier.setIdentifier(UUID.randomUUID().toString()); } provisioningEntity.setIdentifier(provisionedIdentifier); // store provisioned identifier for future reference. storeProvisionedEntityIdentifier(idPName, connectorType, provisioningEntity, tenantDomainName); } else if (provisioningEntity.getEntityType() == ProvisioningEntityType.GROUP && provisioningEntity.getOperation() == ProvisioningOperation.PUT) { String newGroupName = ProvisioningUtil.getAttributeValue(provisioningEntity, IdentityProvisioningConstants.NEW_GROUP_NAME_CLAIM_URI); if(newGroupName != null){ // update provisioned entity name for future reference. this is applicable for only // group name update dao.updateProvisionedEntityName(provisioningEntity); } } success = true; } catch (IdentityApplicationManagementException e) { String errMsg = " Provisioning for Entity " + provisioningEntity.getEntityName() + " For operation = " + provisioningEntity.getOperation(); throw new IdentityProvisioningException(errMsg, e); } finally { PrivilegedCarbonContext.endTenantFlow(); if (tenantDomainName != null) { PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain( tenantDomainName); PrivilegedCarbonContext.getThreadLocalCarbonContext() .setTenantId(getTenantIdFromDomain(tenantDomainName)); } } return success; }
Example 20
Source File: ProxyTimerTask.java From carbon-commons with Apache License 2.0 | 4 votes |
public void run() { synchronized (axisConfig) { PrivilegedCarbonContext.startTenantFlow(); try { PrivilegedCarbonContext privilegedCarbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext(); privilegedCarbonContext.setTenantId(MultitenantConstants.SUPER_TENANT_ID); privilegedCarbonContext.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME); AxisServiceGroup proxyAxisServiceGroup = axisConfig.getServiceGroup(WSDL2FormGenerator.TRYIT_SG_NAME); if (proxyAxisServiceGroup != null) { List removeServiceList = new ArrayList(); for (Iterator iterator = proxyAxisServiceGroup.getServices(); iterator.hasNext();) { AxisService axisServce = (AxisService) iterator.next(); Long longTime = (Long) axisServce .getParameterValue(WSDL2FormGenerator.LAST_TOUCH_TIME); if ((System.currentTimeMillis() - longTime.longValue()) > WSDL2FormGenerator .PERIOD) { removeServiceList.add(axisServce.getName()); } } if (removeServiceList.size() > 0) { for (Iterator iterator = removeServiceList.iterator(); iterator.hasNext();) { String axisServiceName = (String) iterator.next(); proxyAxisServiceGroup.removeService(axisServiceName); } } boolean isLast = proxyAxisServiceGroup.getServices().hasNext(); if (!isLast) { axisConfig.removeServiceGroup(WSDL2FormGenerator.TRYIT_SG_NAME); } } } catch (AxisFault axisFault) { String msg = "Fault occured when manipulating Tryit proxy service group"; log.error(msg, axisFault); } finally { PrivilegedCarbonContext.endTenantFlow(); } } }