本文整理汇总了Java中org.wso2.carbon.context.PrivilegedCarbonContext类的典型用法代码示例。如果您正苦于以下问题:Java PrivilegedCarbonContext类的具体用法?Java PrivilegedCarbonContext怎么用?Java PrivilegedCarbonContext使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PrivilegedCarbonContext类属于org.wso2.carbon.context包,在下文中一共展示了PrivilegedCarbonContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createRegistryService
import org.wso2.carbon.context.PrivilegedCarbonContext; //导入依赖的package包/类
private void createRegistryService(Class realClass, WithRegistry withRegistry) {
try {
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(withRegistry.tenantDomain());
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(withRegistry.tenantId());
RegistryContext registryContext = RegistryContext.getBaseInstance(IdentityTenantUtil.getRealmService());
DataSource dataSource = MockInitialContextFactory
.initializeDatasource(REG_DB_JNDI_NAME, realClass, new String[] { REG_DB_SQL_FILE });
registryContext.setDataAccessManager(new JDBCDataAccessManager(dataSource));
RegistryService registryService = new EmbeddedRegistryService(registryContext);
OSGiDataHolder.getInstance().setRegistryService(registryService);
PrivilegedCarbonContext.getThreadLocalCarbonContext()
.setRegistry(RegistryType.USER_GOVERNANCE, registryService.getRegistry());
Class[] singletonClasses = withRegistry.injectToSingletons();
injectSingletonVariables(registryService, RegistryService.class, singletonClasses);
} catch (RegistryException e) {
log.error("Error creating the registry.", e);
}
}
示例2: 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);
}
示例3: 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();
}
}
示例4: 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();
}
}
示例5: 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();
}
}
示例6: 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();
}
}
示例7: 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();
}
}
示例8: 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();
}
}
示例9: 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();
}
}
示例10: 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();
}
}
示例11: saveEmailConfig
import org.wso2.carbon.context.PrivilegedCarbonContext; //导入依赖的package包/类
/**
* This method is used to save the Email template configurations which is specific to tenant.
*
* @param emailTemplates - Email templates to be saved.
* @throws IdentityMgtServiceException
*/
public void saveEmailConfig(EmailTemplateDTO[] emailTemplates)
throws IdentityMgtServiceException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext()
.getTenantId();
EmailNotificationConfig emailConfig = new EmailNotificationConfig();
ConfigBuilder configBuilder = ConfigBuilder.getInstance();
try {
Properties props = EmailConfigTransformer.transform(emailTemplates);
emailConfig.setProperties(props);
configBuilder.saveConfiguration(StorageType.REGISTRY, tenantId,
emailConfig);
} catch (Exception e) {
log.error("Error occurred while saving email configuration", e);
throw new IdentityMgtServiceException("Error occurred while saving email configuration");
}
}
示例12: getEmailConfig
import org.wso2.carbon.context.PrivilegedCarbonContext; //导入依赖的package包/类
/**
* This method is used to load the tenant specific Email template configurations.
*
* @return an array of templates.
* @throws IdentityMgtServiceException
*/
public EmailTemplateDTO[] getEmailConfig() throws IdentityMgtServiceException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext()
.getTenantId();
Config emailConfig = null;
EmailTemplateDTO[] templates = null;
ConfigBuilder configBuilder = ConfigBuilder.getInstance();
try {
emailConfig = configBuilder.loadConfiguration(ConfigType.EMAIL,
StorageType.REGISTRY, tenantId);
if (emailConfig != null) {
templates = EmailConfigTransformer.transform(emailConfig.getProperties());
}
} catch (Exception e) {
log.error("Error occurred while loading email configuration", e);
throw new IdentityMgtServiceException("Error occurred while loading email configuration");
}
return templates;
}
示例13: 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);
}
}
示例14: getAllPermittedRoleNames
import org.wso2.carbon.context.PrivilegedCarbonContext; //导入依赖的package包/类
/**
* Get list of roles which have given permission
*
* @param filter filter to check
* @param permission permission to check
* @param limit
* @return
* @throws UserAdminException
*/
public FlaggedName[] getAllPermittedRoleNames(String filter, String permission, int limit) throws
UserAdminException {
FlaggedName[] roles = getUserAdminProxy().getAllRolesNames(filter, limit);
List<FlaggedName> permittedRoles = new ArrayList<>();
try {
org.wso2.carbon.user.api.UserRealm realm = UserMgtDSComponent.getRealmService().getTenantUserRealm
(PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId());
AuthorizationManager authorizationManager = realm.getAuthorizationManager();
for (int i = 0; i < roles.length - 1; i++) {
if (authorizationManager.isRoleAuthorized(roles[i].getItemName(), permission, UserMgtConstants
.EXECUTE_ACTION)) {
permittedRoles.add(roles[i]);
}
}
permittedRoles.add(roles[roles.length - 1]);
} catch (org.wso2.carbon.user.api.UserStoreException e) {
throw new UserAdminException("Error while filtering authorized roles.", e);
}
FlaggedName[] permittedRolesArray = new FlaggedName[permittedRoles.size()];
return permittedRoles.toArray(permittedRolesArray);
}
示例15: listUserByClaimWithPermission
import org.wso2.carbon.context.PrivilegedCarbonContext; //导入依赖的package包/类
/**
* List users with given claim value and permission
*
* @param claimValue claim to check
* @param filter filter to check
* @param permission permission to check
* @param maxLimit
* @return
* @throws UserAdminException
*/
public FlaggedName[] listUserByClaimWithPermission(ClaimValue claimValue, String filter, String permission, int
maxLimit)
throws UserAdminException {
List<FlaggedName> permittedUsers = new ArrayList<>();
try {
org.wso2.carbon.user.api.UserRealm realm = UserMgtDSComponent.getRealmService().getTenantUserRealm
(PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId());
AuthorizationManager authorizationManager = realm.getAuthorizationManager();
FlaggedName[] users = getUserAdminProxy().listUsers(claimValue, filter, maxLimit);
for (int i = 0; i < users.length - 1; i++) {
if (authorizationManager.isUserAuthorized(users[i].getItemName(),
permission, UserMgtConstants.EXECUTE_ACTION)) {
permittedUsers.add(users[i]);
}
}
} catch (org.wso2.carbon.user.api.UserStoreException e) {
throw new UserAdminException("Error while filtering authorized users.", e);
}
FlaggedName[] permittedUsersArray = new FlaggedName[permittedUsers.size()];
return permittedUsers.toArray(permittedUsersArray);
}