Examples of PrivilegedCarbonContext


Examples of org.wso2.carbon.context.PrivilegedCarbonContext

            PrivilegedCarbonContext.endTenantFlow();
        }
    }

    private void setTenantCredentialsInCarbonContext() {
        PrivilegedCarbonContext cc = PrivilegedCarbonContext.getThreadLocalCarbonContext();
        cc.setTenantId(ownerTenantId);
        cc.setTenantDomain(ownerTenantDomain);
    }
View Full Code Here

Examples of org.wso2.carbon.context.PrivilegedCarbonContext

        System.setProperty("carbon.home", new File(".").getAbsolutePath());

        String cacheName = "sampleCache";
        // CacheManager cacheManager = Caching.getCacheManager(); // same as Caching.getCacheManagerFactory().getCacheManager("__default__");

        PrivilegedCarbonContext cc = PrivilegedCarbonContext.getThreadLocalCarbonContext();
        cc.setTenantDomain("foo.com");
        cc.setTenantId(1);

        CacheManager cacheManager = Caching.getCacheManagerFactory().getCacheManager("test");
        cache = cacheManager.getCache(cacheName);
    }
View Full Code Here

Examples of org.wso2.carbon.context.PrivilegedCarbonContext

        String key1 = "testIllegalAccess-123";
        cache.put(key1, sampleValue);

        try {
            PrivilegedCarbonContext.startTenantFlow();
            PrivilegedCarbonContext cc = PrivilegedCarbonContext.getThreadLocalCarbonContext();
            cc.setTenantDomain("bar.com");
            cc.setTenantId(2);

            cache.get(key1); // Should throw SecurityException
        } finally {
            PrivilegedCarbonContext.endTenantFlow();
        }
View Full Code Here

Examples of org.wso2.carbon.context.PrivilegedCarbonContext

        String key1 = "testLegalAccess-123";
        cache.put(key1, sampleValue);

        try {
            PrivilegedCarbonContext.startTenantFlow();
            PrivilegedCarbonContext cc = PrivilegedCarbonContext.getThreadLocalCarbonContext();
            cc.setTenantDomain("foo.com");
            cc.setTenantId(1);

            assertEquals(cache.get(key1), sampleValue);
        } finally {
            PrivilegedCarbonContext.endTenantFlow();
        }
View Full Code Here

Examples of org.wso2.carbon.context.PrivilegedCarbonContext

        String cacheName = "sampleCache";

        // Tenant wso2.com
        try {
            PrivilegedCarbonContext.startTenantFlow();
            PrivilegedCarbonContext cc = PrivilegedCarbonContext.getThreadLocalCarbonContext();
            cc.setTenantDomain("wso2.com");
            cc.setTenantId(1);

            CacheManager cacheManager =
                    Caching.getCacheManagerFactory().getCacheManager(cacheManagerName);
            Cache<String, Integer> cache1 = cacheManager.getCache(cacheName);
            cache1.put(key1, sampleValue);
            cache1.put(key2, sampleValue);
            cache1 = cacheManager.getCache(cacheName);
            assertEquals(sampleValue, cache1.get(key1));
            checkCacheSize(cache1, 2);
        } finally {
            PrivilegedCarbonContext.endTenantFlow();
        }

        // Tenant ibm.com
        try {
            PrivilegedCarbonContext.startTenantFlow();
            PrivilegedCarbonContext cc = PrivilegedCarbonContext.getThreadLocalCarbonContext();
            cc.setTenantDomain("ibm.com");
            cc.setTenantId(2);

            CacheManager cacheManager =
                    Caching.getCacheManagerFactory().getCacheManager(cacheManagerName);
            Cache<String, Integer> cache1 = cacheManager.getCache(cacheName);
            cache1.put(key1, sampleValue);
View Full Code Here

Examples of org.wso2.carbon.context.PrivilegedCarbonContext

        String cacheName = "sampleCache";

        // Tenant apple.com
        try {
            PrivilegedCarbonContext.startTenantFlow();
            PrivilegedCarbonContext cc = PrivilegedCarbonContext.getThreadLocalCarbonContext();
            cc.setTenantDomain("apple.com");
            cc.setTenantId(1);

            CacheManager cacheManager = Caching.getCacheManager(); // Default CacheManager
            Cache<String, Integer> cache1 = cacheManager.getCache(cacheName);
            cache1.put(key1, sampleValue);
            cache1.put(key2, sampleValue);
            cache1 = cacheManager.getCache(cacheName);
            assertEquals(sampleValue, cache1.get(key1));
            checkCacheSize(cache1, 2);
        } finally {
            PrivilegedCarbonContext.endTenantFlow();
        }

        // Tenant orange.com
        try {
            PrivilegedCarbonContext.startTenantFlow();
            PrivilegedCarbonContext cc = PrivilegedCarbonContext.getThreadLocalCarbonContext();
            cc.setTenantDomain("orange.com");
            cc.setTenantId(2);

            CacheManager cacheManager = Caching.getCacheManager(); // Default CacheManager
            Cache<String, Integer> cache1 = cacheManager.getCache(cacheName);
            cache1.put(key1, sampleValue);
            cache1 = cacheManager.getCache(cacheName);
View Full Code Here

Examples of org.wso2.carbon.context.PrivilegedCarbonContext

        int value = 9876;

        // Tenant wso2.org
        try {
            PrivilegedCarbonContext.startTenantFlow();
            PrivilegedCarbonContext cc = PrivilegedCarbonContext.getThreadLocalCarbonContext();
            cc.setTenantDomain("wso2.org");
            cc.setTenantId(4);

            CacheManager cacheManager = Caching.getCacheManager(); // Default CacheManager
            Cache<String, Integer> cache = cacheManager.<String, Integer>createCacheBuilder(cacheName).
                    setExpiry(CacheConfiguration.ExpiryType.MODIFIED, new CacheConfiguration.Duration(TimeUnit.SECONDS, 10)).
                    setStoreByValue(false).build();

            cache.put(key, value);
            assertEquals(cache.get(key).intValue(), value);
        } finally {
            PrivilegedCarbonContext.endTenantFlow();
        }

        // Tenant afkham.org
        try {
            PrivilegedCarbonContext.startTenantFlow();
            PrivilegedCarbonContext cc = PrivilegedCarbonContext.getThreadLocalCarbonContext();
            cc.setTenantDomain("afkham.org");
            cc.setTenantId(5);

            CacheManager cacheManager = Caching.getCacheManager(); // Default CacheManager
            Cache<String, Integer> cache = cacheManager.<String, Integer>createCacheBuilder(cacheName).
                    setExpiry(CacheConfiguration.ExpiryType.MODIFIED, new CacheConfiguration.Duration(TimeUnit.SECONDS, 10)).
                    setStoreByValue(false).build();
View Full Code Here

Examples of org.wso2.carbon.context.PrivilegedCarbonContext

          expectedExceptions = {javax.cache.CacheException.class},
          description = "")
    public void testCreateExistingCache() {
        try {
            PrivilegedCarbonContext.startTenantFlow();
            PrivilegedCarbonContext cc = PrivilegedCarbonContext.getThreadLocalCarbonContext();
            cc.setTenantDomain("apple.com");
            cc.setTenantId(1);
            CacheManager cacheManager = Caching.getCacheManagerFactory().getCacheManager("test");
            String cacheName = "testCreateExistingCache";
            cacheManager.<String, Integer>createCacheBuilder(cacheName).
                    setExpiry(CacheConfiguration.ExpiryType.MODIFIED,
                              new CacheConfiguration.Duration(TimeUnit.SECONDS, 10)).
View Full Code Here

Examples of org.wso2.carbon.context.PrivilegedCarbonContext

    @Test(groups = {"org.wso2.carbon.clustering.hazelcast.jsr107.mt"},
          description = "")
    public void testCacheLoaderForTenants() {
        try {
            PrivilegedCarbonContext.startTenantFlow();
            PrivilegedCarbonContext cc = PrivilegedCarbonContext.getThreadLocalCarbonContext();
            cc.setTenantDomain("bikes.com");
            cc.setTenantId(1);
            CacheManager cacheManager = Caching.getCacheManagerFactory().getCacheManager("test");
            String cacheName = "testCacheLoaderForTenants";
            Cache<String, String> cache =
                    cacheManager.<String, String>createCacheBuilder(cacheName).
                            setCacheLoader(new TestCacheLoader<String, String>()).build();
View Full Code Here

Examples of org.wso2.carbon.context.PrivilegedCarbonContext

        @Override
        public V call() throws Exception {
            Entry<K, ? extends V> entry;
            try {
                PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
                carbonContext.setTenantDomain(tenantDomain);
                carbonContext.setTenantId(tenantId);
                entry = cacheLoader.load(key);
                cache.put(entry.getKey(), entry.getValue());
            } catch (Exception e) {
                log.error("Could not load cache item with key " + key + " into cache " +
                          cache.getName() + " owned by tenant ", e);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.