org.wso2.carbon.user.core.tenant.TenantManager Java Examples
The following examples show how to use
org.wso2.carbon.user.core.tenant.TenantManager.
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: APIUtilTest.java From carbon-apimgt with Apache License 2.0 | 6 votes |
@Test public void testIsRoleNameNotExist() throws Exception { String userName = "John"; String roleName = "developer"; ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class); RealmService realmService = Mockito.mock(RealmService.class); TenantManager tenantManager = Mockito.mock(TenantManager.class); UserRealm userRealm = Mockito.mock(UserRealm.class); UserStoreManager userStoreManager = Mockito.mock(UserStoreManager.class); PowerMockito.mockStatic(ServiceReferenceHolder.class); Mockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder); Mockito.when(serviceReferenceHolder.getRealmService()).thenReturn(realmService); Mockito.when(realmService.getTenantManager()).thenReturn(tenantManager); Mockito.when(realmService.getTenantUserRealm(Mockito.anyInt())).thenReturn(userRealm); Mockito.when(userRealm.getUserStoreManager()).thenReturn(userStoreManager); Mockito.when(userStoreManager.isExistingRole(roleName)).thenReturn(false); Assert.assertFalse(APIUtil.isRoleNameExist(userName, roleName)); }
Example #2
Source File: StratosApiV40.java From attic-stratos with Apache License 2.0 | 6 votes |
private List<TenantInfoBean> searchPartialTenantsDomains(String domain) throws RestAPIException { TenantManager tenantManager = ServiceHolder.getTenantManager(); Tenant[] tenants; try { domain = domain.trim(); tenants = (Tenant[]) tenantManager.getAllTenantsForTenantDomainStr(domain); } catch (Exception e) { String msg = "Error in retrieving the tenant information."; log.error(msg, e); throw new RestAPIException(msg); } List<TenantInfoBean> tenantList = new ArrayList<TenantInfoBean>(); for (Tenant tenant : tenants) { TenantInfoBean bean = TenantMgtUtil.getTenantInfoBeanfromTenant(tenant.getId(), tenant); tenantList.add(bean); } return tenantList; }
Example #3
Source File: StratosApiV41Utils.java From attic-stratos with Apache License 2.0 | 6 votes |
/** * Get a list of available Tenants * * @return list of available Tenants * @throws RestAPIException */ public static List<org.apache.stratos.common.beans.TenantInfoBean> getAllTenants() throws RestAPIException { TenantManager tenantManager = ServiceHolder.getTenantManager(); Tenant[] tenants; try { tenants = (Tenant[]) tenantManager.getAllTenants(); } catch (Exception e) { String msg = "Error in retrieving the tenant information"; log.error(msg, e); throw new RestAPIException(msg); } List<org.apache.stratos.common.beans.TenantInfoBean> tenantList = new ArrayList<org.apache.stratos.common.beans.TenantInfoBean>(); for (Tenant tenant : tenants) { org.apache.stratos.common.beans.TenantInfoBean tenantInfoBean = ObjectConverter .convertCarbonTenantInfoBeanToTenantInfoBean( TenantMgtUtil.getTenantInfoBeanfromTenant(tenant.getId(), tenant)); tenantList.add(tenantInfoBean); } return tenantList; }
Example #4
Source File: StratosApiV41Utils.java From attic-stratos with Apache License 2.0 | 6 votes |
/** * Get List of Partial Tenant Domains * * @param domain domain Name * @return List of Partial Tenant Domains * @throws RestAPIException */ public static List<org.apache.stratos.common.beans.TenantInfoBean> searchPartialTenantsDomains(String domain) throws RestAPIException { TenantManager tenantManager = ServiceHolder.getTenantManager(); Tenant[] tenants; try { domain = domain.trim(); tenants = (Tenant[]) tenantManager.getAllTenantsForTenantDomainStr(domain); } catch (Exception e) { String msg = "Error in retrieving the tenant information."; log.error(msg, e); throw new RestAPIException(msg); } List<org.apache.stratos.common.beans.TenantInfoBean> tenantList = new ArrayList<org.apache.stratos.common.beans.TenantInfoBean>(); for (Tenant tenant : tenants) { org.apache.stratos.common.beans.TenantInfoBean bean = ObjectConverter .convertCarbonTenantInfoBeanToTenantInfoBean( TenantMgtUtil.getTenantInfoBeanfromTenant(tenant.getId(), tenant)); tenantList.add(bean); } return tenantList; }
Example #5
Source File: StratosApiV40.java From attic-stratos with Apache License 2.0 | 6 votes |
private List<TenantInfoBean> getAllTenants() throws RestAPIException { TenantManager tenantManager = ServiceHolder.getTenantManager(); Tenant[] tenants; try { tenants = (Tenant[]) tenantManager.getAllTenants(); } catch (Exception e) { String msg = "Error in retrieving the tenant information"; log.error(msg, e); throw new RestAPIException(msg); } List<TenantInfoBean> tenantList = new ArrayList<TenantInfoBean>(); for (Tenant tenant : tenants) { TenantInfoBean bean = TenantMgtUtil.getTenantInfoBeanfromTenant(tenant.getId(), tenant); tenantList.add(bean); } return tenantList; }
Example #6
Source File: ImportApiServiceImplTestCase.java From carbon-apimgt with Apache License 2.0 | 6 votes |
@Before public void init() throws Exception { importApiService = new ImportApiServiceImpl(); apiConsumer = Mockito.mock(APIConsumer.class); PowerMockito.mockStatic(ServiceReferenceHolder.class); serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class); PowerMockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder); RealmService realmService = Mockito.mock(RealmService.class); Mockito.when(serviceReferenceHolder.getRealmService()).thenReturn(realmService); TenantManager tenantManager = Mockito.mock(TenantManager.class); Mockito.when(realmService.getTenantManager()).thenReturn(tenantManager); PowerMockito.when(tenantManager.getTenantId("carbon.super")).thenReturn(-1234); apiManagerConfigurationService = Mockito.mock(APIManagerConfigurationService.class); Mockito.when(serviceReferenceHolder.getAPIManagerConfigurationService()).thenReturn(apiManagerConfigurationService); apimConfig = Mockito.mock(APIManagerConfiguration.class); Mockito.when(apiManagerConfigurationService.getAPIManagerConfiguration()).thenReturn(apimConfig); }
Example #7
Source File: ApplicationThrottleControllerTest.java From carbon-apimgt with Apache License 2.0 | 6 votes |
@Before public void init() throws RegistryException, UserStoreException { System.setProperty(CARBON_HOME, ""); tenantDomain = "carbon.super"; applicationId = "1"; tenantID = tenantID; messageContext = TestUtils.getMessageContextWithAuthContext("api", "v1"); registryServiceHolder = Mockito.mock(RegistryServiceHolder.class); registryService = Mockito.mock(RegistryService.class); registry = Mockito.mock(UserRegistry.class); realmService = Mockito.mock(RealmService.class); tenantManager = Mockito.mock(TenantManager.class); carbonContext = Mockito.mock(PrivilegedCarbonContext.class); throttleDataHolder = Mockito.mock(ThrottleDataHolder.class); throttlingPolicyResource = Mockito.mock(Resource.class); throttleContext = Mockito.mock(ThrottleContext.class); PowerMockito.mockStatic(PrivilegedCarbonContext.class); PowerMockito.mockStatic(RegistryServiceHolder.class); PowerMockito.when(PrivilegedCarbonContext.getThreadLocalCarbonContext()).thenReturn(carbonContext); PowerMockito.when(RegistryServiceHolder.getInstance()).thenReturn(registryServiceHolder); PowerMockito.when(registryServiceHolder.getRegistryService()).thenReturn(registryService); PowerMockito.when(carbonContext.getOSGiService(RealmService.class, null)).thenReturn(realmService); PowerMockito.when(realmService.getTenantManager()).thenReturn(tenantManager); }
Example #8
Source File: StratosUserManagerUtils.java From attic-stratos with Apache License 2.0 | 6 votes |
public static String getTenantDomain(int tenantId) { if(tenantId == -1234) { return "carbon.super"; } TenantManager tenantManager = getTenantManager(); Tenant[] tenants = null; try { tenants = (Tenant[]) tenantManager.getAllTenants(); } catch (Exception e) { String msg = "Error in retrieving the tenant information"; log.error(msg, e); } if(tenants != null) { for(Tenant tenant : tenants) { if(tenant.getId() == tenantId) { return tenant.getDomain(); } } } log.warn(String.format("Could not find tenant domain: [tenant-id] %d", tenantId)); return null; }
Example #9
Source File: APIUtilTest.java From carbon-apimgt with Apache License 2.0 | 6 votes |
@Test public void testGetRoleNamesNonSuperTenant() throws Exception { String userName = "John"; ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class); RealmService realmService = Mockito.mock(RealmService.class); TenantManager tenantManager = Mockito.mock(TenantManager.class); UserRealm userRealm = Mockito.mock(UserRealm.class); UserStoreManager userStoreManager = Mockito.mock(UserStoreManager.class); String[] roleNames = {"role1", "role2"}; PowerMockito.mockStatic(ServiceReferenceHolder.class); PowerMockito.mockStatic(MultitenantUtils.class); Mockito.when(MultitenantUtils.getTenantDomain(userName)). thenReturn("test.com"); Mockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder); Mockito.when(serviceReferenceHolder.getRealmService()).thenReturn(realmService); Mockito.when(realmService.getTenantManager()).thenReturn(tenantManager); Mockito.when(realmService.getTenantUserRealm(Mockito.anyInt())).thenReturn(userRealm); Mockito.when(userRealm.getUserStoreManager()).thenReturn(userStoreManager); Mockito.when(userStoreManager.getRoleNames()).thenReturn(roleNames); Assert.assertEquals(roleNames, APIUtil.getRoleNames(userName)); }
Example #10
Source File: SequenceUtilsTestCase.java From carbon-apimgt with Apache License 2.0 | 6 votes |
@Before public void setup() throws UserStoreException, RegistryException { userRegistry = Mockito.mock(UserRegistry.class); serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class); registryService = Mockito.mock(RegistryService.class); realmService = Mockito.mock(RealmService.class); tenantManager = Mockito.mock(TenantManager.class); PowerMockito.mockStatic(APIUtil.class); PowerMockito.mockStatic(ServiceReferenceHolder.class); PowerMockito.mockStatic(MultitenantUtils.class); PowerMockito.mockStatic(RegistryUtils.class); PowerMockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder); Mockito.when(serviceReferenceHolder.getRegistryService()).thenReturn(registryService); Mockito.when(registryService.getGovernanceSystemRegistry(Mockito.anyInt())).thenReturn(userRegistry); Mockito.when(serviceReferenceHolder.getRealmService()).thenReturn(realmService); Mockito.when(realmService.getTenantManager()).thenReturn(tenantManager); }
Example #11
Source File: SAMLSSOServiceProviderDAOTest.java From carbon-identity-framework with Apache License 2.0 | 6 votes |
@Test public void testGetServiceProvider() throws Exception { mockStatic(IdentityTenantUtil.class); RealmService mockRealmService = mock(RealmService.class); TenantManager mockTenantManager = mock(TenantManager.class); when(IdentityTenantUtil.getRealmService()).thenReturn(mockRealmService); when(mockRealmService.getTenantManager()).thenReturn(mockTenantManager); when(mockTenantManager.getDomain(anyInt())).thenReturn("test.com"); Properties dummyResourceProperties = new Properties(); dummyResourceProperties.putAll(dummyBasicProperties); Resource dummyResource = new ResourceImpl(); dummyResource.setProperties(dummyResourceProperties); String path = getPath(dummyResource.getProperty(IdentityRegistryResources.PROP_SAML_SSO_ISSUER)); when(mockRegistry.resourceExists(path)).thenReturn(true); when(mockRegistry.get(path)).thenReturn(dummyResource); SAMLSSOServiceProviderDO serviceProviderDO = objUnderTest.getServiceProvider(dummyResource.getProperty (IdentityRegistryResources.PROP_SAML_SSO_ISSUER)); assertEquals(serviceProviderDO.getTenantDomain(), "test.com", "Retrieved resource's tenant domain mismatch"); }
Example #12
Source File: AbstractAPIManagerTestCase.java From carbon-apimgt with Apache License 2.0 | 6 votes |
@Before public void init() { System.setProperty(CARBON_HOME, ""); privilegedCarbonContext = Mockito.mock(PrivilegedCarbonContext.class); PowerMockito.mockStatic(PrivilegedCarbonContext.class); PowerMockito.when(PrivilegedCarbonContext.getThreadLocalCarbonContext()).thenReturn(privilegedCarbonContext); PowerMockito.mockStatic(GovernanceUtils.class); paginationContext = Mockito.mock(PaginationContext.class); PowerMockito.mockStatic(PaginationContext.class); PowerMockito.when(PaginationContext.getInstance()).thenReturn(paginationContext); apiMgtDAO = Mockito.mock(ApiMgtDAO.class); registry = Mockito.mock(Registry.class); genericArtifactManager = Mockito.mock(GenericArtifactManager.class); registryService = Mockito.mock(RegistryService.class); tenantManager = Mockito.mock(TenantManager.class); graphQLSchemaDefinition = Mockito.mock(GraphQLSchemaDefinition.class); keyManager = Mockito.mock(KeyManager.class); PowerMockito.mockStatic(KeyManagerHolder.class); PowerMockito.when(KeyManagerHolder.getKeyManagerInstance("carbon.super")).thenReturn(keyManager); }
Example #13
Source File: APIMRegistryServiceImplTest.java From carbon-apimgt with Apache License 2.0 | 5 votes |
@Test public void getConfigRegistryResourceContentTestCase() throws UserStoreException, RegistryException, APIManagementException{ APIMRegistryServiceImpl apimRegistryService = new APIMRegistryServiceImplWrapper(); System.setProperty(CARBON_HOME, ""); PrivilegedCarbonContext privilegedCarbonContext = Mockito.mock(PrivilegedCarbonContext.class); PowerMockito.mockStatic(PrivilegedCarbonContext.class); PowerMockito.when(PrivilegedCarbonContext.getThreadLocalCarbonContext()).thenReturn(privilegedCarbonContext); Mockito.when(privilegedCarbonContext.getTenantDomain()).thenReturn(TENANT_DOMAIN); Mockito.when(privilegedCarbonContext.getTenantId()).thenReturn(TENANT_ID); RealmService realmService = Mockito.mock(RealmService.class); TenantManager tenantManager = Mockito.mock(TenantManager.class); RegistryService registryService = Mockito.mock(RegistryService.class); UserRegistry registry = Mockito.mock(UserRegistry.class); Resource resource = Mockito.mock(Resource.class); ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class); PowerMockito.mockStatic(ServiceReferenceHolder.class); Mockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder); Mockito.when(serviceReferenceHolder.getRealmService()).thenReturn(realmService); Mockito.when(realmService.getTenantManager()).thenReturn(tenantManager); Mockito.when(serviceReferenceHolder.getRegistryService()).thenReturn(registryService); Mockito.when(tenantManager.getTenantId(TENANT_DOMAIN)).thenReturn(TENANT_ID); Mockito.when(registryService.getConfigSystemRegistry(TENANT_ID)).thenReturn(registry); PowerMockito.mockStatic(APIUtil.class); APIUtil.loadTenantConf(TENANT_ID); Mockito.when(registry.resourceExists("testLocation")).thenReturn(true); Mockito.when(registry.get("testLocation")).thenReturn(resource); Assert.assertEquals("testContent", apimRegistryService. getConfigRegistryResourceContent("test.foo", "testLocation")); }
Example #14
Source File: MigrateFrom200to210.java From product-es with Apache License 2.0 | 5 votes |
/** * This method returns the list of tenants. * @return list of tenants * @throws org.wso2.carbon.user.api.UserStoreException */ private List<Tenant> getTenantsArray() throws UserStoreException { TenantManager tenantManager = ServiceHolder.getRealmService().getTenantManager(); List<Tenant> tenantsArray = new ArrayList<Tenant>(Arrays.asList(tenantManager.getAllTenants())); Tenant superTenant = new Tenant(); superTenant.setDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME); superTenant.setId(MultitenantConstants.SUPER_TENANT_ID); tenantsArray.add(superTenant); return tenantsArray; }
Example #15
Source File: EmailUserNameMigrationClient.java From product-es with Apache License 2.0 | 5 votes |
/** * This method returns the list of tenants. * @return list of tenants * @throws UserStoreException */ private List<Tenant> getTenantsArray() throws UserStoreException { TenantManager tenantManager = ServiceHolder.getRealmService().getTenantManager(); List<Tenant> tenantsArray = new ArrayList<Tenant>(Arrays.asList(tenantManager.getAllTenants())); Tenant superTenant = new Tenant(); superTenant.setDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME); superTenant.setId(MultitenantConstants.SUPER_TENANT_ID); tenantsArray.add(superTenant); return tenantsArray; }
Example #16
Source File: CORSManagementServiceTest.java From carbon-identity-framework with Apache License 2.0 | 5 votes |
@BeforeMethod public void setUp() throws Exception { initiateH2Base(); String carbonHome = Paths.get(System.getProperty("user.dir"), "target", "test-classes").toString(); System.setProperty(CarbonBaseConstants.CARBON_HOME, carbonHome); System.setProperty(CarbonBaseConstants.CARBON_CONFIG_DIR_PATH, Paths.get(carbonHome, "conf").toString()); DataSource dataSource = mock(DataSource.class); mockStatic(IdentityDatabaseUtil.class); when(IdentityDatabaseUtil.getDataSource()).thenReturn(dataSource); connection = TestUtils.getConnection(); Connection spyConnection = spyConnection(connection); when(dataSource.getConnection()).thenReturn(spyConnection); ConfigurationManagerComponentDataHolder.setUseCreatedTime(true); ConfigurationManagerConfigurationHolder configurationHolder = new ConfigurationManagerConfigurationHolder(); ConfigurationDAO configurationDAO = new ConfigurationDAOImpl(); configurationHolder.setConfigurationDAOS(Collections.singletonList(configurationDAO)); mockCarbonContextForTenant(SUPER_TENANT_ID, SUPER_TENANT_DOMAIN_NAME); mockIdentityTenantUtility(); configurationManager = new ConfigurationManagerImpl(configurationHolder); ConfigurationManagerComponentDataHolder.getInstance().setConfigurationManagementEnabled(true); RealmService mockRealmService = mock(RealmService.class); TenantManager tenantManager = mock(TenantManager.class); when(mockRealmService.getTenantManager()).thenReturn(tenantManager); FrameworkServiceDataHolder.getInstance().setRealmService(mockRealmService); corsManagementService = new CORSManagementServiceImpl(); CORSManagementServiceHolder.getInstance().setConfigurationManager(configurationManager); }
Example #17
Source File: ProviderMigrationClient.java From product-es with Apache License 2.0 | 5 votes |
private List<Tenant> getTenantsArray() throws UserStoreException { TenantManager tenantManager = ServiceHolder.getRealmService().getTenantManager(); List<Tenant> tenantsArray = new ArrayList<Tenant>(Arrays.asList(tenantManager.getAllTenants())); Tenant superTenant = new Tenant(); superTenant.setDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME); superTenant.setId(MultitenantConstants.SUPER_TENANT_ID); tenantsArray.add(superTenant); return tenantsArray; }
Example #18
Source File: GraphBasedSequenceHandlerAbstractTest.java From carbon-identity-framework with Apache License 2.0 | 5 votes |
@BeforeMethod protected void setUp() throws UserStoreException, NoSuchFieldException, IllegalAccessException, NoSuchMethodException, URISyntaxException { URL root = this.getClass().getClassLoader().getResource("."); File file = new File(root.getPath()); System.setProperty("carbon.home", file.toString()); resetAuthenticators(); FrameworkServiceDataHolder.getInstance().setRealmService(mock(RealmService.class)); CacheBackedIdPMgtDAO cacheBackedIdPMgtDAO = mock(CacheBackedIdPMgtDAO.class); Field daoField = IdentityProviderManager.class.getDeclaredField("dao"); daoField.setAccessible(true); daoField.set(IdentityProviderManager.getInstance(), cacheBackedIdPMgtDAO); RealmService mockRealmService = mock(RealmService.class); TenantManager tenantManager = mock(TenantManager.class); when(tenantManager.getTenantId(anyString())).thenReturn(1); when(mockRealmService.getTenantManager()).thenReturn(tenantManager); IdentityTenantUtil.setRealmService(mockRealmService); Field configFilePathField = FileBasedConfigurationBuilder.class.getDeclaredField("configFilePath"); configFilePathField.setAccessible(true); URL url = this.getClass().getResource(APPLICATION_AUTHENTICATION_FILE_NAME); configFilePathField.set(null, Paths.get(url.toURI()).toString()); }
Example #19
Source File: MutualAuthHostObjectTest.java From carbon-apimgt with Apache License 2.0 | 5 votes |
@Test(expected = ScriptException.class) public void testJsFunction_validateUserNameHeader() throws Exception { Object args[] = {"[email protected]"}; PowerMockito.mockStatic(ServiceReferenceHolder.class); ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class); TenantManager tenantManager = Mockito.mock(TenantManager.class); UserRealm userRealm = Mockito.mock(UserRealm.class); UserStoreManager userStoreManager = Mockito.mock(UserStoreManager.class); RealmService realmService = Mockito.mock(org.wso2.carbon.user.core.service.RealmService.class); Mockito.when(serviceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder); Mockito.when(serviceReferenceHolder.getRealmService()).thenReturn(realmService); Mockito.when(realmService.getTenantManager()).thenReturn(tenantManager); Mockito.when(realmService.getTenantUserRealm(Mockito.anyInt())).thenReturn(userRealm); Mockito.when(userRealm.getUserStoreManager()).thenReturn(userStoreManager); mutualAuthHostObject.jsFunction_validateUserNameHeader(null, null, args, null); //with existing username Mockito.when(userStoreManager.isExistingUser(Mockito.anyString())).thenReturn(true); mutualAuthHostObject.jsFunction_validateUserNameHeader(null, null, args, null); //invalid arguments Object argsInvalid1[] = {}; mutualAuthHostObject.jsFunction_validateUserNameHeader(null, null, argsInvalid1, null); }
Example #20
Source File: MigrateData.java From product-es with Apache License 2.0 | 5 votes |
/** * This method returns the list of tenants. * * @return list of tenants * @throws UserStoreException */ private List<Tenant> getTenantsArray() throws UserStoreException { TenantManager tenantManager = ServiceHolder.getRealmService().getTenantManager(); List<Tenant> tenantsArray = new ArrayList<Tenant>(Arrays.asList(tenantManager.getAllTenants())); Tenant superTenant = new Tenant(); superTenant.setDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME); superTenant.setId(MultitenantConstants.SUPER_TENANT_ID); tenantsArray.add(superTenant); return tenantsArray; }
Example #21
Source File: AbstractAPIManagerWrapper.java From carbon-apimgt with Apache License 2.0 | 5 votes |
public AbstractAPIManagerWrapper(GenericArtifactManager genericArtifactManager, RegistryService registryService, Registry registry, TenantManager tenantManager) throws APIManagementException { this.genericArtifactManager = genericArtifactManager; this.registry = registry; this.tenantManager = tenantManager; this.registryService = registryService; }
Example #22
Source File: AbstractAPIManagerWrapper.java From carbon-apimgt with Apache License 2.0 | 5 votes |
public AbstractAPIManagerWrapper(GenericArtifactManager genericArtifactManager, RegistryService registryService, Registry registry, TenantManager tenantManager, ApiMgtDAO apiMgtDAO) throws APIManagementException { this.genericArtifactManager = genericArtifactManager; this.registry = registry; this.tenantManager = tenantManager; this.registryService = registryService; this.apiMgtDAO = apiMgtDAO; }
Example #23
Source File: HostUtil.java From carbon-commons with Apache License 2.0 | 5 votes |
public static String getTenantDomainFromTID(int tenantId) { String tenantDomain = MultitenantConstants.SUPER_TENANT_DOMAIN_NAME; TenantManager tenantManager = DataHolder.getInstance().getRealmService().getTenantManager(); try { tenantDomain = tenantManager.getTenant(tenantId).getDomain(); } catch (UserStoreException e) { log.error("error while getting tenant" ,e); } return tenantDomain; }
Example #24
Source File: APIConsumerImplTest.java From carbon-apimgt with Apache License 2.0 | 5 votes |
@Before public void init() throws UserStoreException, RegistryException { apiMgtDAO = Mockito.mock(ApiMgtDAO.class); userRealm = Mockito.mock(UserRealm.class); serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class); realmService = Mockito.mock(RealmService.class); tenantManager = Mockito.mock(TenantManager.class); userStoreManager = Mockito.mock(UserStoreManager.class); keyManager = Mockito.mock(KeyManager.class); cacheInvalidator = Mockito.mock(CacheInvalidator.class); registryService = Mockito.mock(RegistryService.class); genericArtifactManager = Mockito.mock(GenericArtifactManager.class); registry = Mockito.mock(Registry.class); userRegistry = Mockito.mock(UserRegistry.class); authorizationManager = Mockito.mock(AuthorizationManager.class); PowerMockito.mockStatic(APIUtil.class); PowerMockito.mockStatic(ApplicationUtils.class); PowerMockito.mockStatic(ServiceReferenceHolder.class); PowerMockito.mockStatic(MultitenantUtils.class); PowerMockito.mockStatic(KeyManagerHolder.class); PowerMockito.mockStatic(CacheInvalidator.class); PowerMockito.mockStatic(RegistryUtils.class); PowerMockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder); PowerMockito.when(CacheInvalidator.getInstance()).thenReturn(cacheInvalidator); Mockito.when(serviceReferenceHolder.getRealmService()).thenReturn(realmService); Mockito.when(realmService.getTenantUserRealm(Mockito.anyInt())).thenReturn(userRealm); Mockito.when(realmService.getTenantManager()).thenReturn(tenantManager); Mockito.when(userRealm.getUserStoreManager()).thenReturn(userStoreManager); Mockito.when(serviceReferenceHolder.getRegistryService()).thenReturn(registryService); Mockito.when(registryService.getGovernanceSystemRegistry(Mockito.anyInt())).thenReturn(userRegistry); Mockito.when(userRealm.getAuthorizationManager()).thenReturn(authorizationManager); Mockito.when(KeyManagerHolder.getKeyManagerInstance(Mockito.anyString(),Mockito.anyString())).thenReturn(keyManager); PowerMockito.when(APIUtil.replaceSystemProperty(anyString())).thenAnswer((Answer<String>) invocation -> { Object[] args = invocation.getArguments(); return (String) args[0]; }); }
Example #25
Source File: APIUtilTest.java From carbon-apimgt with Apache License 2.0 | 5 votes |
@Test public void testIsRoleNameExist() throws Exception { String userName = "John"; String roleName = "developer"; ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class); RealmService realmService = Mockito.mock(RealmService.class); TenantManager tenantManager = Mockito.mock(TenantManager.class); UserRealm userRealm = Mockito.mock(UserRealm.class); UserStoreManager userStoreManager = Mockito.mock(UserStoreManager.class); PowerMockito.mockStatic(ServiceReferenceHolder.class); Mockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder); Mockito.when(serviceReferenceHolder.getRealmService()).thenReturn(realmService); Mockito.when(realmService.getTenantManager()).thenReturn(tenantManager); Mockito.when(realmService.getTenantUserRealm(Mockito.anyInt())).thenReturn(userRealm); Mockito.when(userRealm.getUserStoreManager()).thenReturn(userStoreManager); Mockito.when(userStoreManager.isExistingRole(roleName)).thenReturn(true); Mockito.when(userStoreManager.isExistingRole("NonExistingDomain/role")).thenThrow(UserStoreException.class); Mockito.when(userStoreManager.isExistingRole("NonExistingDomain/")).thenThrow(UserStoreException.class); Assert.assertTrue(APIUtil.isRoleNameExist(userName, roleName)); Assert.assertFalse(APIUtil.isRoleNameExist(userName, "NonExistingDomain/role")); Assert.assertFalse(APIUtil.isRoleNameExist(userName, "NonExistingDomain/")); Assert.assertTrue(APIUtil.isRoleNameExist(userName, ""));//allow adding empty role }
Example #26
Source File: SelfSignupUtilTestCase.java From carbon-apimgt with Apache License 2.0 | 5 votes |
@Test public void testGetSelfSignupConfigFromRegistry() throws Exception { System.setProperty(CARBON_HOME, ""); PrivilegedCarbonContext privilegedCarbonContext = Mockito.mock(PrivilegedCarbonContext.class); PowerMockito.mockStatic(PrivilegedCarbonContext.class); PowerMockito.when(PrivilegedCarbonContext.getThreadLocalCarbonContext()).thenReturn(privilegedCarbonContext); Mockito.when(privilegedCarbonContext.getTenantDomain()).thenReturn("foo.com"); Mockito.when(privilegedCarbonContext.getRegistry(RegistryType.SYSTEM_GOVERNANCE)).thenReturn(registry); PowerMockito.mockStatic(ServiceReferenceHolder.class); ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class); PowerMockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder); RealmService realmService = Mockito.mock(RealmService.class); Mockito.when(serviceReferenceHolder.getRealmService()).thenReturn(realmService); TenantManager tenantManager = Mockito.mock(TenantManager.class); Mockito.when(realmService.getTenantManager()).thenReturn(tenantManager); Mockito.when(tenantManager.getTenantId("foo.com")).thenReturn(4444); PowerMockito.mockStatic(APIUtil.class); Mockito.when(registry.resourceExists(APIConstants.SELF_SIGN_UP_CONFIG_LOCATION)).thenReturn(true); Resource resource = Mockito.mock(Resource.class); Mockito.when(resource.getContent()).thenReturn("wsdl".getBytes()); Mockito.when(registry.get(APIConstants.SELF_SIGN_UP_CONFIG_LOCATION)).thenReturn(resource); OMElement omElement = Mockito.mock(OMElement.class); Mockito.when(omElement.getFirstChildWithName(Matchers.any(QName.class))).thenReturn(omElement); PowerMockito.mockStatic(AXIOMUtil.class); Mockito.when(omElement.getChildrenWithLocalName(APIConstants.SELF_SIGN_UP_REG_ROLE_ELEM)).thenReturn(Mockito.mock(Iterator.class)); PowerMockito.when(AXIOMUtil.stringToOM("wsdl")).thenReturn(omElement); PowerMockito.mockStatic(PasswordResolverFactory.class); PasswordResolver passwordResolver = Mockito.mock(PasswordResolver.class); PowerMockito.when(PasswordResolverFactory.getInstance()).thenReturn(passwordResolver); UserRegistrationConfigDTO userRegistrationConfigDTO = SelfSignUpUtil.getSignupConfiguration("foo.com"); Assert.assertNotNull(userRegistrationConfigDTO); }
Example #27
Source File: SelfSignupUtilTestCase.java From carbon-apimgt with Apache License 2.0 | 5 votes |
@Test public void testGetSelfSignupConfigFromRegistryTenant() throws Exception { System.setProperty(CARBON_HOME, ""); PrivilegedCarbonContext privilegedCarbonContext = Mockito.mock(PrivilegedCarbonContext.class); PowerMockito.mockStatic(PrivilegedCarbonContext.class); PowerMockito.when(PrivilegedCarbonContext.getThreadLocalCarbonContext()).thenReturn(privilegedCarbonContext); Mockito.when(privilegedCarbonContext.getTenantDomain()).thenReturn("foo.com"); Mockito.when(privilegedCarbonContext.getRegistry(RegistryType.SYSTEM_GOVERNANCE)).thenReturn(registry); PowerMockito.mockStatic(ServiceReferenceHolder.class); ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class); PowerMockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder); RealmService realmService = Mockito.mock(RealmService.class); Mockito.when(serviceReferenceHolder.getRealmService()).thenReturn(realmService); TenantManager tenantManager = Mockito.mock(TenantManager.class); Mockito.when(realmService.getTenantManager()).thenReturn(tenantManager); Mockito.when(tenantManager.getTenantId("foo.com")).thenReturn(4444); PowerMockito.mockStatic(APIUtil.class); Mockito.when(registry.resourceExists(APIConstants.SELF_SIGN_UP_CONFIG_LOCATION)).thenReturn(true); Resource resource = Mockito.mock(Resource.class); Mockito.when(resource.getContent()).thenReturn("wsdl".getBytes()); Mockito.when(registry.get(APIConstants.SELF_SIGN_UP_CONFIG_LOCATION)).thenReturn(resource); OMElement omElement = Mockito.mock(OMElement.class); Mockito.when(omElement.getFirstChildWithName(Matchers.any(QName.class))).thenReturn(omElement); PowerMockito.mockStatic(AXIOMUtil.class); Mockito.when(omElement.getChildrenWithLocalName(APIConstants.SELF_SIGN_UP_REG_ROLE_ELEM)).thenReturn(Mockito.mock(Iterator.class)); PowerMockito.when(AXIOMUtil.stringToOM("wsdl")).thenReturn(omElement); PowerMockito.mockStatic(PasswordResolverFactory.class); PasswordResolver passwordResolver = Mockito.mock(PasswordResolver.class); PowerMockito.when(PasswordResolverFactory.getInstance()).thenReturn(passwordResolver); UserRegistrationConfigDTO userRegistrationConfigDTO = SelfSignUpUtil.getSignupConfiguration("bar.com"); Assert.assertNotNull(userRegistrationConfigDTO); PowerMockito.verifyStatic(PrivilegedCarbonContext.class); PrivilegedCarbonContext.endTenantFlow(); }
Example #28
Source File: UserSignUpSimpleWorkflowExecutorTest.java From carbon-apimgt with Apache License 2.0 | 5 votes |
@Before public void init() throws Exception { userSignUpSimpleWorkflowExecutor = new UserSignUpSimpleWorkflowExecutor(); workflowDTO = new WorkflowDTO(); workflowDTO.setExternalWorkflowReference("12345"); workflowDTO.setTenantDomain(tenantDomain); workflowDTO.setStatus(WorkflowStatus.APPROVED); workflowDTO.setWorkflowReference(username); ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class); apiManagerConfiguration = Mockito.mock(APIManagerConfiguration.class); RealmService realmService = Mockito.mock(RealmService.class); TenantManager tenantManager = Mockito.mock(TenantManager.class); UserRealm userRealm = Mockito.mock(UserRealm.class); userStoreManager = Mockito.mock(UserStoreManager.class); userAdminStub = Mockito.mock(UserAdminStub.class); serviceClient = Mockito.mock(ServiceClient.class); PowerMockito.mockStatic(ServiceReferenceHolder.class); PowerMockito.mockStatic(SelfSignUpUtil.class); PowerMockito.mockStatic(CarbonUtils.class); Mockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder); APIManagerConfigurationService apiManagerConfigurationService = new APIManagerConfigurationServiceImpl (apiManagerConfiguration); Mockito.when(serviceReferenceHolder.getAPIManagerConfigurationService()).thenReturn (apiManagerConfigurationService); Mockito.when(serviceReferenceHolder.getRealmService()).thenReturn(realmService); Mockito.when(realmService.getTenantManager()).thenReturn(tenantManager); Mockito.when(tenantManager.getTenantId(tenantDomain)).thenReturn(tenantID); Mockito.when(tenantManager.getTenantId(tenantDomain)).thenReturn(tenantID); Mockito.when(realmService.getTenantUserRealm(tenantID)).thenReturn(userRealm); Mockito.when(userRealm.getUserStoreManager()).thenReturn(userStoreManager); PowerMockito.whenNew(UserAdminStub.class).withAnyArguments().thenReturn(userAdminStub); Mockito.when(userAdminStub._getServiceClient()).thenReturn(serviceClient); PowerMockito.doNothing().when(CarbonUtils.class, "setBasicAccessSecurityHeaders", Mockito.anyString(), Mockito.anyString(), Mockito.anyBoolean(), (ServiceClient) Mockito.anyObject()); }
Example #29
Source File: TestUtils.java From carbon-apimgt with Apache License 2.0 | 5 votes |
public static ServiceReferenceHolder mockRegistryAndUserRealm(int tenantId) throws UserStoreException, RegistryException { ServiceReferenceHolder sh = getServiceReferenceHolder(); RealmService realmService = Mockito.mock(RealmService.class); TenantManager tm = Mockito.mock(TenantManager.class); PowerMockito.when(sh.getRealmService()).thenReturn(realmService); PowerMockito.when(realmService.getTenantManager()).thenReturn(tm); RegistryService registryService = Mockito.mock(RegistryService.class); PowerMockito.when(sh.getRegistryService()).thenReturn(registryService); UserRegistry userReg = Mockito.mock(UserRegistry.class); PowerMockito.when(registryService.getGovernanceUserRegistry()).thenReturn(userReg); UserRegistry systemReg = Mockito.mock(UserRegistry.class); PowerMockito.when(registryService.getConfigSystemRegistry()).thenReturn(systemReg); UserRealm userRealm = Mockito.mock(UserRealm.class); UserRealm bootstrapRealm = Mockito.mock(UserRealm.class); PowerMockito.when(systemReg.getUserRealm()).thenReturn(userRealm); PowerMockito.doNothing().when(ServiceReferenceHolder.class); ServiceReferenceHolder.setUserRealm(userRealm); org.wso2.carbon.user.api.UserRealm userR = Mockito.mock(org.wso2.carbon.user.api.UserRealm.class); PowerMockito.when(realmService.getTenantUserRealm(-1234)).thenReturn(userR); AuthorizationManager authManager = Mockito.mock(AuthorizationManager.class); PowerMockito.when(userR.getAuthorizationManager()).thenReturn(authManager); PowerMockito.when(realmService.getBootstrapRealm()).thenReturn(bootstrapRealm); ServiceReferenceHolder.setUserRealm(bootstrapRealm); PowerMockito.when(tm.getTenantId(Matchers.anyString())).thenReturn(tenantId); return sh; }
Example #30
Source File: TestUtils.java From carbon-apimgt with Apache License 2.0 | 5 votes |
public static TenantManager getTenantManager() { ServiceReferenceHolder serviceReferenceHolder = getServiceReferenceHolder(); RealmService realmService = Mockito.mock(RealmService.class); TenantManager tenantManager = Mockito.mock(TenantManager.class); PowerMockito.when(serviceReferenceHolder.getRealmService()).thenReturn(realmService); PowerMockito.when(realmService.getTenantManager()).thenReturn(tenantManager); return tenantManager; }