Java Code Examples for org.wso2.carbon.utils.multitenancy.MultitenantConstants#SUPER_TENANT_ID
The following examples show how to use
org.wso2.carbon.utils.multitenancy.MultitenantConstants#SUPER_TENANT_ID .
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: EmailSender.java From carbon-commons with Apache License 2.0 | 6 votes |
private String getRequestMessage() { String msg; String targetEpr = config.getTargetEpr(); String tenantDomain = this.tenantDomain; if (tenantDomain == null) { PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(true); } if (tenantDomain != null && targetEpr.indexOf("/carbon") > 0 && MultitenantUtils.getTenantDomainFromRequestURL(targetEpr) == null && PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true)!= MultitenantConstants.SUPER_TENANT_ID) { targetEpr = targetEpr.replace("/carbon", "/" + MultitenantConstants.TENANT_AWARE_URL_PREFIX + "/" + tenantDomain + "/carbon"); } if (config.getEmailBody().length() == 0) { msg = EmailVerifierConfig.DEFAULT_VALUE_MESSAGE + "\n" + targetEpr + "?" + CONF_STRING + "=" + secretKey + "\n"; } else { msg = config.getEmailBody() + "\n" + targetEpr + "?" + CONF_STRING + "=" + secretKey + "\n"; } if (config.getEmailFooter() != null) { msg = msg + "\n" + config.getEmailFooter(); } return msg; }
Example 2
Source File: KeyStoreCertificateRetriever.java From carbon-identity-framework with Apache License 2.0 | 6 votes |
/** * @param certificateId Alias of the certificate to be retrieved. * @param tenant The tenant where the key store file should be loaded from. * If the tenant is the super tenant, the primary key store will be used. * @return The certificate for the given alias */ @Override public X509Certificate getCertificate(String certificateId, Tenant tenant) throws CertificateRetrievingException { KeyStoreManager keyStoreManager = KeyStoreManager.getInstance(tenant.getId()); KeyStore keyStore; try { if (tenant.getId() != MultitenantConstants.SUPER_TENANT_ID) { // This is a tenant. So load the tenant key store. keyStore = keyStoreManager.getKeyStore(getKeyStoreName(tenant.getDomain())); } else { // This is the super tenant. So load the primary key store. keyStore = keyStoreManager.getPrimaryKeyStore(); } X509Certificate certificate = (X509Certificate) keyStore.getCertificate(certificateId); return certificate; } catch (Exception e) { String errorMsg = String.format("Error occurred while retrieving the certificate for the alias '%s' " + "of the tenant domain '%s'." + certificateId, tenant.getDomain()); throw new CertificateRetrievingException(errorMsg, e); } }
Example 3
Source File: ClaimsMgtUtil.java From carbon-commons with Apache License 2.0 | 6 votes |
/** * Method to get the name of the admin user given the tenant id * * @param tenantId * tenant id * @return admin user name * @throws Exception * UserStoreException */ public static String getAdminUserNameFromTenantId(RealmService realmService, int tenantId) throws Exception { if (tenantId == MultitenantConstants.SUPER_TENANT_ID) { return realmService.getBootstrapRealmConfiguration().getAdminUserName(); } String tenantAdminName =""; try { if (realmService.getTenantManager().getTenant(tenantId) != null) { tenantAdminName = realmService.getTenantManager().getTenant(tenantId).getAdminName(); } } catch (org.wso2.carbon.user.api.UserStoreException e) { String msg = "Unable to retrieve the admin name for the tenant with the tenant Id: " + tenantId; log.error(msg, e); throw new Exception(msg, e); } return tenantAdminName; }
Example 4
Source File: FrameworkUtils.java From carbon-identity with Apache License 2.0 | 6 votes |
/** * 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); }
Example 5
Source File: EntitlementEngine.java From carbon-identity with Apache License 2.0 | 6 votes |
/** * Get a EntitlementEngine instance for that tenant. This method will return an * EntitlementEngine instance if exists, or creates a new one * * @return EntitlementEngine instance for that tenant */ public static EntitlementEngine getInstance() { int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); if (tenantId == MultitenantConstants.SUPER_TENANT_ID) { if (entitlementEngine == null) { synchronized (lock) { if (entitlementEngine == null) { entitlementEngine = new EntitlementEngine(tenantId); } } } return entitlementEngine; } if (!entitlementEngines.contains(tenantId)) { synchronized (lock) { if (!entitlementEngines.contains(tenantId)) { entitlementEngines.put(tenantId, new EntitlementEngine(tenantId)); } } } return entitlementEngines.get(tenantId); }
Example 6
Source File: AbstractApi.java From attic-stratos with Apache License 2.0 | 6 votes |
protected ConfigurationContext getConfigContext() { // If a tenant has been set, then try to get the ConfigurationContext of that tenant PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext(); ConfigurationContextService configurationContextService = (ConfigurationContextService) carbonContext.getOSGiService(ConfigurationContextService.class); ConfigurationContext mainConfigContext = configurationContextService.getServerConfigContext(); String domain = carbonContext.getTenantDomain(); if (domain != null && !MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(domain)) { return TenantAxisUtils.getTenantConfigurationContext(domain, mainConfigContext); } else if (carbonContext.getTenantId() == MultitenantConstants.SUPER_TENANT_ID) { return mainConfigContext; } else { throw new UnsupportedOperationException("Tenant domain unidentified. " + "Upstream code needs to identify & set the tenant domain & tenant ID. " + " The TenantDomain SOAP header could be set by the clients or " + "tenant authentication should be carried out."); } }
Example 7
Source File: ServiceUtils.java From product-private-paas with Apache License 2.0 | 6 votes |
private static ConfigurationContext getConfigContext() { // If a tenant has been set, then try to get the ConfigurationContext of that tenant PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext(); ConfigurationContextService configurationContextService = (ConfigurationContextService) carbonContext .getOSGiService(ConfigurationContextService.class); ConfigurationContext mainConfigContext = configurationContextService.getServerConfigContext(); String domain = carbonContext.getTenantDomain(); if (domain != null && !MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(domain)) { return TenantAxisUtils.getTenantConfigurationContext(domain, mainConfigContext); } else if (carbonContext.getTenantId() == MultitenantConstants.SUPER_TENANT_ID) { return mainConfigContext; } else { throw new UnsupportedOperationException("Tenant domain unidentified. " + "Upstream code needs to identify & set the tenant domain & tenant ID. " + " The TenantDomain SOAP header could be set by the clients or " + "tenant authentication should be carried out."); } }
Example 8
Source File: AbstractAPIManager.java From carbon-apimgt with Apache License 2.0 | 6 votes |
/** * Returns a list of pre-defined # {@link org.wso2.carbon.apimgt.api.model.Tier} in the system. * * @return Set<Tier> */ public Set<Tier> getTiers(String tenantDomain) throws APIManagementException { Set<Tier> tiers = new TreeSet<Tier>(new TierNameComparator()); Map<String, Tier> tierMap; if (!APIUtil.isAdvanceThrottlingEnabled()) { startTenantFlow(tenantDomain); int requestedTenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); if (requestedTenantId == MultitenantConstants.SUPER_TENANT_ID || requestedTenantId == MultitenantConstants.INVALID_TENANT_ID) { tierMap = APIUtil.getTiers(); } else { tierMap = APIUtil.getTiers(requestedTenantId); } tiers.addAll(tierMap.values()); endTenantFlow(); } else { tierMap = APIUtil.getTiersFromPolicies(PolicyConstants.POLICY_LEVEL_SUB, tenantId); tiers.addAll(tierMap.values()); } return tiers; }
Example 9
Source File: AbstractAdmin.java From product-private-paas with Apache License 2.0 | 6 votes |
protected ConfigurationContext getConfigContext() { // If a tenant has been set, then try to get the ConfigurationContext of that tenant PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext(); ConfigurationContextService configurationContextService = (ConfigurationContextService) carbonContext .getOSGiService(ConfigurationContextService.class); ConfigurationContext mainConfigContext = configurationContextService.getServerConfigContext(); String domain = carbonContext.getTenantDomain(); if (domain != null && !MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(domain)) { return TenantAxisUtils.getTenantConfigurationContext(domain, mainConfigContext); } else if (carbonContext.getTenantId() == MultitenantConstants.SUPER_TENANT_ID) { return mainConfigContext; } else { throw new UnsupportedOperationException("Tenant domain unidentified. " + "Upstream code needs to identify & set the tenant domain & tenant ID. " + " The TenantDomain SOAP header could be set by the clients or " + "tenant authentication should be carried out."); } }
Example 10
Source File: StratosAuthorizingHandler.java From product-private-paas with Apache License 2.0 | 5 votes |
private boolean isCurrentUserSuperTenant(String tenantDomain, int tenantId) { if (MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(tenantDomain) && MultitenantConstants.SUPER_TENANT_ID == tenantId) { return true; } return false; }
Example 11
Source File: FileBasedUserStoreDAOImpl.java From carbon-identity-framework with Apache License 2.0 | 5 votes |
@Override public void deleteUserStores(String[] domains) throws IdentityUserStoreMgtException { int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); Path path; if (tenantId == MultitenantConstants.SUPER_TENANT_ID) { path = Paths.get(DEPLOYMENT_DIRECTORY); } else { path = Paths.get(CarbonUtils.getCarbonTenantsDirPath(), String.valueOf(tenantId), USERSTORES); } File file = path.toFile(); for (String domainName : domains) { if (log.isDebugEnabled()) { log.debug("Deleting, .... " + domainName + " domain."); } try { // Run pre user-store name update listeners triggerListnersOnUserStorePreDelete(domainName); // Delete persisted domain name deletePersitedDomain(tenantId, domainName); } catch (UserStoreException e) { String errorMessage = "Error while deleting user store : " + domainName; log.error(errorMessage, e); throw new IdentityUserStoreMgtException(errorMessage); } // Delete file deleteFile(file, domainName.replace(".", "_").concat(".xml")); } }
Example 12
Source File: StratosAuthorizingHandler.java From attic-stratos with Apache License 2.0 | 5 votes |
private boolean isCurrentUserSuperTenant(String tenantDomain, int tenantId) { if (MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(tenantDomain) && MultitenantConstants.SUPER_TENANT_ID == tenantId) { return true; } return false; }
Example 13
Source File: SubscriptionValidationDAO.java From carbon-apimgt with Apache License 2.0 | 5 votes |
public List<URLMapping> getAllURLMappings(int tenantId) { List<URLMapping> urlMappings = new ArrayList<>(); String sql = SubscriptionValidationSQLConstants.GET_TENANT_API_URL_MAPPING_SQL; String tenantDomain = APIUtil.getTenantDomainFromTenantId(tenantId); String contextParam = null; if (tenantId == MultitenantConstants.SUPER_TENANT_ID) { sql = SubscriptionValidationSQLConstants.GET_ST_API_URL_MAPPING_SQL; contextParam = "%/t/%"; } else if (tenantId > 0) { contextParam = "%" + tenantDomain + "%"; } else { sql = SubscriptionValidationSQLConstants.GET_ALL_API_URL_MAPPING_SQL; } try (Connection conn = APIMgtDBUtil.getConnection(); PreparedStatement ps = conn.prepareStatement(sql); ) { if (contextParam != null) { ps.setString(1, contextParam); } ResultSet resultSet = ps.executeQuery(); while (resultSet.next()) { URLMapping urlMapping = new URLMapping(); urlMapping.setAuthScheme(resultSet.getString("AUTH_SCHEME")); urlMapping.setHttpMethod(resultSet.getString("HTTP_METHOD")); urlMapping.setThrottlingPolicy(resultSet.getString("POLICY")); urlMappings.add(urlMapping); } } catch (SQLException e) { log.error("Error in loading URLMappings for tenantId : " + tenantId, e); } return urlMappings; }
Example 14
Source File: AbstractAPIManager.java From carbon-apimgt with Apache License 2.0 | 5 votes |
@Override public Set<Tier> getAllTiers(String tenantDomain) throws APIManagementException { Set<Tier> tiers = new TreeSet<Tier>(new TierNameComparator()); Map<String, Tier> tierMap; boolean isTenantFlowStarted = false; try { if (tenantDomain != null && !MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(tenantDomain)) { startTenantFlow(tenantDomain); isTenantFlowStarted = true; } int requestedTenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); if (requestedTenantId == MultitenantConstants.SUPER_TENANT_ID || requestedTenantId == MultitenantConstants.INVALID_TENANT_ID) { tierMap = APIUtil.getAllTiers(); } else { tierMap = APIUtil.getAllTiers(requestedTenantId); } } finally { if (isTenantFlowStarted) { endTenantFlow(); } } tiers.addAll(tierMap.values()); return tiers; }
Example 15
Source File: LogFileProvider.java From carbon-commons with Apache License 2.0 | 4 votes |
private boolean isSuperTenantUser() { CarbonContext carbonContext = CarbonContext.getThreadLocalCarbonContext(); int tenantId = carbonContext.getTenantId(); return tenantId == MultitenantConstants.SUPER_TENANT_ID; }
Example 16
Source File: SystemStatistics.java From carbon-commons with Apache License 2.0 | 4 votes |
public void update(AxisConfiguration axisConfig) throws AxisFault { int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); Parameter systemStartTime = axisConfig.getParameter(CarbonConstants.SERVER_START_TIME); long startTime = 0; if (systemStartTime != null) { startTime = Long.parseLong((String) systemStartTime.getValue()); } Date stTime = new Date(startTime); // only super admin can view serverStartTime and systemUpTime if (tenantId == MultitenantConstants.SUPER_TENANT_ID) { serverStartTime = dateFormatter.format(stTime); systemUpTime = (getTime((System.currentTimeMillis() - startTime) / 1000)); } try { totalRequestCount = statService.getTotalSystemRequestCount(axisConfig); totalResponseCount = statService.getSystemResponseCount(axisConfig); totalFaultCount = statService.getSystemFaultCount(axisConfig); avgResponseTime = statService.getAvgSystemResponseTime(axisConfig); maxResponseTime = statService.getMaxSystemResponseTime(axisConfig); minResponseTime = statService.getMinSystemResponseTime(axisConfig); } catch (Exception e) { throw AxisFault.makeFault(e); } Runtime runtime = Runtime.getRuntime(); // only super admin can view usedMemory and totalMemory if (tenantId == MultitenantConstants.SUPER_TENANT_ID) { usedMemory = formatMemoryValue(runtime.totalMemory() - runtime.freeMemory()); totalMemory = formatMemoryValue(runtime.totalMemory()); } wso2wsasVersion = ServerConfiguration.getInstance().getFirstProperty("Version"); int activeServices = 0; for (Iterator services = axisConfig.getServices().values().iterator(); services.hasNext(); ) { AxisService axisService = (AxisService) services.next(); AxisServiceGroup asGroup = (AxisServiceGroup) axisService.getParent(); if (axisService.isActive() && !axisService.isClientSide() && !SystemFilter.isFilteredOutService(asGroup)) { activeServices++; } } this.services = activeServices; try { // only susper admin is allow to view serverName. if (tenantId == MultitenantConstants.SUPER_TENANT_ID) { serverName = NetworkUtils.getLocalHostname(); } } catch (SocketException ignored) { } }
Example 17
Source File: SingleLogoutMessageBuilder.java From carbon-identity with Apache License 2.0 | 4 votes |
public LogoutResponse buildLogoutResponse(String id, String status, String statMsg, String destination, boolean isSignResponse, String tenantDomain, String responseSigningAlgorithmUri, String responseDigestAlgoUri) throws IdentityException { LogoutResponse logoutResp = new LogoutResponseBuilder().buildObject(); logoutResp.setID(SAMLSSOUtil.createID()); logoutResp.setInResponseTo(id); logoutResp.setIssuer(SAMLSSOUtil.getIssuer()); logoutResp.setStatus(buildStatus(status, statMsg)); logoutResp.setIssueInstant(new DateTime()); logoutResp.setDestination(destination); // Currently, does not sign the error response since this message pass through a url to the error page if (isSignResponse && SAMLSSOConstants.StatusCodes.SUCCESS_CODE.equals(status)) { int tenantId; if (StringUtils.isEmpty(tenantDomain)) { tenantDomain = MultitenantConstants.SUPER_TENANT_DOMAIN_NAME; tenantId = MultitenantConstants.SUPER_TENANT_ID; } else { try { tenantId = SAMLSSOUtil.getRealmService().getTenantManager().getTenantId(tenantDomain); } catch (UserStoreException e) { throw IdentityException.error("Error occurred while retrieving tenant id from tenant domain", e); } if(MultitenantConstants.INVALID_TENANT_ID == tenantId) { throw IdentityException.error("Invalid tenant domain - '" + tenantDomain + "'" ); } } try { PrivilegedCarbonContext.startTenantFlow(); PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain); PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(tenantId); SAMLSSOUtil.setSignature(logoutResp, responseSigningAlgorithmUri, responseDigestAlgoUri, new SignKeyDataHolder(null)); } finally { PrivilegedCarbonContext.endTenantFlow(); } } return logoutResp; }
Example 18
Source File: UserRecoveryDTO.java From carbon-identity with Apache License 2.0 | 4 votes |
public UserRecoveryDTO(String userId) { this.userId = userId; this.tenantDomain = MultitenantConstants.SUPER_TENANT_DOMAIN_NAME; this.tenantId = MultitenantConstants.SUPER_TENANT_ID; }
Example 19
Source File: ApplicationDAOImpl.java From carbon-identity with Apache License 2.0 | 4 votes |
@Override public ServiceProvider getApplication(String applicationName, String tenantDomain) throws IdentityApplicationManagementException { int applicationId = 0; int tenantID = MultitenantConstants.SUPER_TENANT_ID; if (tenantDomain != null) { try { tenantID = ApplicationManagementServiceComponentHolder.getInstance().getRealmService() .getTenantManager().getTenantId(tenantDomain); } catch (UserStoreException e1) { log.error("Error in reading application", e1); throw new IdentityApplicationManagementException("Error while reading application", e1); } } Connection connection = IdentityDatabaseUtil.getDBConnection(); try { // Load basic application data ServiceProvider serviceProvider = getBasicApplicationData(applicationName, connection, tenantID); if ((serviceProvider == null || serviceProvider.getApplicationName() == null) && ApplicationConstants.LOCAL_SP.equals(applicationName)) { ServiceProvider localServiceProvider = new ServiceProvider(); localServiceProvider.setApplicationName(applicationName); localServiceProvider.setDescription("Local Service Provider"); createApplication(localServiceProvider, tenantDomain); serviceProvider = getBasicApplicationData(applicationName, connection, tenantID); } if (serviceProvider == null) { return null; } applicationId = serviceProvider.getApplicationID(); serviceProvider.setInboundAuthenticationConfig(getInboundAuthenticationConfig( applicationId, connection, tenantID)); serviceProvider .setLocalAndOutBoundAuthenticationConfig(getLocalAndOutboundAuthenticationConfig( applicationId, connection, tenantID)); serviceProvider.setInboundProvisioningConfig(getInboundProvisioningConfiguration( applicationId, connection, tenantID)); serviceProvider.setOutboundProvisioningConfig(getOutboundProvisioningConfiguration( applicationId, connection, tenantID)); // Load Claim Mapping serviceProvider.setClaimConfig(getClaimConfiguration(applicationId, connection, tenantID)); // Load Role Mappings List<RoleMapping> roleMappings = getRoleMappingOfApplication(applicationId, connection, tenantID); PermissionsAndRoleConfig permissionAndRoleConfig = new PermissionsAndRoleConfig(); permissionAndRoleConfig.setRoleMappings(roleMappings .toArray(new RoleMapping[roleMappings.size()])); serviceProvider.setPermissionAndRoleConfig(permissionAndRoleConfig); RequestPathAuthenticatorConfig[] requestPathAuthenticators = getRequestPathAuthenticators( applicationId, connection, tenantID); serviceProvider.setRequestPathAuthenticatorConfigs(requestPathAuthenticators); List<ServiceProviderProperty> propertyList = getServicePropertiesBySpId(connection, applicationId); serviceProvider.setSpProperties(propertyList.toArray(new ServiceProviderProperty[propertyList.size()])); return serviceProvider; } catch (SQLException e) { throw new IdentityApplicationManagementException("Failed to update service provider " + applicationId, e); } finally { IdentityApplicationManagementUtil.closeConnection(connection); } }
Example 20
Source File: UserRecoveryDTO.java From carbon-identity-framework with Apache License 2.0 | 4 votes |
public UserRecoveryDTO(String userId) { this.userId = userId; this.tenantDomain = MultitenantConstants.SUPER_TENANT_DOMAIN_NAME; this.tenantId = MultitenantConstants.SUPER_TENANT_ID; }