org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder Java Examples
The following examples show how to use
org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder.
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: APIGatewayManager.java From carbon-apimgt with Apache License 2.0 | 6 votes |
private void setSecureVaultPropertyToBeAdded(API api, GatewayAPIDTO gatewayAPIDTO) { boolean isSecureVaultEnabled = Boolean.parseBoolean(ServiceReferenceHolder.getInstance().getAPIManagerConfigurationService(). getAPIManagerConfiguration().getFirstProperty(APIConstants.API_SECUREVAULT_ENABLE)); if (api.isEndpointSecured() && isSecureVaultEnabled) { String secureVaultAlias = api.getId().getProviderName() + "--" + api.getId().getApiName() + api.getId().getVersion(); CredentialDto credentialDto = new CredentialDto(); credentialDto.setAlias(secureVaultAlias); credentialDto.setPassword(api.getEndpointUTPassword()); gatewayAPIDTO.setCredentialsToBeAdd(addCredentialsToList(credentialDto, gatewayAPIDTO.getCredentialsToBeAdd())); } }
Example #2
Source File: CEPPolicyManagementServiceClient.java From carbon-apimgt with Apache License 2.0 | 6 votes |
public CEPPolicyManagementServiceClient() throws APIManagementException { APIManagerConfiguration config = ServiceReferenceHolder.getInstance().getAPIManagerConfigurationService(). getAPIManagerConfiguration(); String serviceURL = config.getFirstProperty(APIConstants.CPS_SERVER_URL); username = config.getFirstProperty(APIConstants.CPS_SERVER_USERNAME); if (serviceURL == null) { throw new APIManagementException("Required connection details for the central policy server not provided"); } try { ConfigurationContext ctx = ConfigurationContextFactory.createConfigurationContextFromFileSystem(null, null); //Initialize the client here } catch (AxisFault axisFault) { throw new APIManagementException("Error while initializing central policy client", axisFault); } }
Example #3
Source File: RegistryCacheInvalidationServiceTestCase.java From carbon-apimgt with Apache License 2.0 | 6 votes |
@Before public void setup() throws Exception { PowerMockito.mockStatic(ServiceReferenceHolder.class); PowerMockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder); Mockito.when(serviceReferenceHolder.getRealmService()).thenReturn(realmService); Mockito.when(realmService.getTenantManager()).thenReturn(tenantManager); Mockito.when(tenantManager.getTenantId(tenantDomain)).thenReturn(6543); Mockito.when(serviceReferenceHolder.getRegistryService()).thenReturn(registryService); Mockito.when(registryService.getGovernanceSystemRegistry(6543)).thenReturn(userRegistry); PowerMockito.mockStatic(RegistryUtils.class); Mockito.when(userRegistry.getRegistryContext()).thenReturn(registryContext); System.setProperty(CARBON_HOME, ""); PrivilegedCarbonContext privilegedCarbonContext = Mockito.mock(PrivilegedCarbonContext.class); PowerMockito.mockStatic(PrivilegedCarbonContext.class); PowerMockito.when(PrivilegedCarbonContext.getThreadLocalCarbonContext()).thenReturn(privilegedCarbonContext); }
Example #4
Source File: KeyMgtNotificationSender.java From carbon-apimgt with Apache License 2.0 | 6 votes |
public void notify(KeyManagerConfigurationDTO keyManagerConfigurationDTO,String action) { String encodedString = ""; if (keyManagerConfigurationDTO.getAdditionalProperties() != null){ String additionalProperties = new Gson().toJson(keyManagerConfigurationDTO.getAdditionalProperties()); encodedString = new String(Base64.encodeBase64(additionalProperties.getBytes())); } Object[] objects = new Object[]{APIConstants.KeyManager.KeyManagerEvent.KEY_MANAGER_CONFIGURATION, action, keyManagerConfigurationDTO.getName(), keyManagerConfigurationDTO.getType(), keyManagerConfigurationDTO.isEnabled(), encodedString, keyManagerConfigurationDTO.getTenantDomain()}; Event keyManagerEvent = new Event(APIConstants.KeyManager.KeyManagerEvent.KEY_MANAGER_STREAM_ID, System.currentTimeMillis(), null, null, objects); EventHubConfigurationDto eventHubConfigurationDto = ServiceReferenceHolder.getInstance().getAPIManagerConfigurationService().getAPIManagerConfiguration() .getEventHubConfigurationDto(); if (eventHubConfigurationDto.isEnabled()) { APIUtil.publishEventToTrafficManager(Collections.EMPTY_MAP, keyManagerEvent); } }
Example #5
Source File: APIUtilTest.java From carbon-apimgt with Apache License 2.0 | 6 votes |
@Test public void testGetOAuthConfigurationFromAPIMConfig () throws Exception { String property = "AuthorizationHeader"; ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class); PowerMockito.mockStatic(ServiceReferenceHolder.class); APIManagerConfigurationService apiManagerConfigurationService = Mockito.mock(APIManagerConfigurationService.class); APIManagerConfiguration apiManagerConfiguration = Mockito.mock(APIManagerConfiguration.class); Mockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder); Mockito.when(serviceReferenceHolder.getAPIManagerConfigurationService()) .thenReturn(apiManagerConfigurationService); Mockito.when(apiManagerConfigurationService.getAPIManagerConfiguration()).thenReturn(apiManagerConfiguration); Mockito.when(apiManagerConfiguration.getFirstProperty(APIConstants.OAUTH_CONFIGS + property)) .thenReturn("APIM_AUTH"); String authHeader = getOAuthConfigurationFromAPIMConfig(property); Assert.assertEquals("APIM_AUTH", authHeader); }
Example #6
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 #7
Source File: APIMRegistryServiceImpl.java From carbon-apimgt with Apache License 2.0 | 6 votes |
@Override public String getGovernanceRegistryResourceContent(String tenantDomain, String registryLocation) throws UserStoreException, RegistryException { String content = null; if (tenantDomain == null) { tenantDomain = MultitenantConstants.SUPER_TENANT_DOMAIN_NAME; } try { PrivilegedCarbonContext.startTenantFlow(); PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain, true); int tenantId = ServiceReferenceHolder.getInstance().getRealmService().getTenantManager().getTenantId(tenantDomain); Registry registry = ServiceReferenceHolder.getInstance().getRegistryService().getGovernanceSystemRegistry(tenantId); if (registry.resourceExists(registryLocation)) { Resource resource = registry.get(registryLocation); content = getString(resource); } } finally { PrivilegedCarbonContext.endTenantFlow(); } return content; }
Example #8
Source File: APIMgtGoogleAnalyticsUtils.java From carbon-apimgt with Apache License 2.0 | 6 votes |
/** * Initialize the google analytics publisher by reading tenants google analytics * configuration from the registry * * @param tenantDomain Tenant domain of the current tenant */ public void init(String tenantDomain) { configKey = APIConstants.GA_CONFIGURATION_LOCATION; try { PrivilegedCarbonContext.startTenantFlow(); PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain, true); Registry registry = ServiceReferenceHolder.getInstance().getRegistryService().getGovernanceSystemRegistry(); Resource resource = registry.get(configKey); InputStream in = resource.getContentStream(); StAXOMBuilder builder = new StAXOMBuilder(in); this.gaConfig = new GoogleAnalyticsConfig(builder.getDocumentElement()); } catch (RegistryException | XMLStreamException e) { // flow should not break. Therefore ignoring the exception log.error("Failed to retrieve google analytics configurations for tenant:" + tenantDomain); } finally { PrivilegedCarbonContext.endTenantFlow(); } }
Example #9
Source File: APIMgtDAOTest.java From carbon-apimgt with Apache License 2.0 | 6 votes |
@Before public void setUp() throws Exception { String dbConfigPath = System.getProperty("APIManagerDBConfigurationPath"); APIManagerConfiguration config = new APIManagerConfiguration(); initializeDatabase(dbConfigPath); config.load(dbConfigPath); ServiceReferenceHolder.getInstance().setAPIManagerConfigurationService(new APIManagerConfigurationServiceImpl (config)); List<Notifier> notifierList = new ArrayList<>(); SubscriptionsNotifier subscriptionsNotifier = new SubscriptionsNotifier(); notifierList.add(subscriptionsNotifier); ServiceReferenceHolder.getInstance().getNotifiersMap().put(subscriptionsNotifier.getType(), notifierList); PowerMockito.mockStatic(KeyManagerHolder.class); keyManager = Mockito.mock(KeyManager.class); APIMgtDBUtil.initialize(); apiMgtDAO = ApiMgtDAO.getInstance(); IdentityTenantUtil.setRealmService(new TestRealmService()); String identityConfigPath = System.getProperty("IdentityConfigurationPath"); IdentityConfigParser.getInstance(identityConfigPath); OAuthServerConfiguration oAuthServerConfiguration = OAuthServerConfiguration.getInstance(); ServiceReferenceHolder.getInstance().setOauthServerConfiguration(oAuthServerConfiguration); }
Example #10
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 #11
Source File: GatewayCertificateManagerTest.java From carbon-apimgt with Apache License 2.0 | 6 votes |
@Before public void init() { apiGatewayAdminClient = PowerMockito.mock(APIGatewayAdminClient.class); Map<String, Environment> environmentMap = getEnvironments(); ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class); APIManagerConfigurationService apiManagerConfigurationService = Mockito.mock(APIManagerConfigurationService .class); APIManagerConfiguration apiManagerConfiguration = Mockito.mock(APIManagerConfiguration.class); PowerMockito.mockStatic(ServiceReferenceHolder.class); Mockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder); Mockito.when(serviceReferenceHolder.getAPIManagerConfigurationService()).thenReturn (apiManagerConfigurationService); Mockito.when(apiManagerConfigurationService.getAPIManagerConfiguration()).thenReturn(apiManagerConfiguration); Mockito.when(apiManagerConfiguration.getApiGatewayEnvironments()).thenReturn(environmentMap); gatewayCertificateManager = GatewayCertificateManager.getInstance(); }
Example #12
Source File: CertificateReLoaderUtil.java From carbon-apimgt with Apache License 2.0 | 5 votes |
public static long getCertificateReLoaderInterval() { String certificateReloaderPeriod = ServiceReferenceHolder.getInstance().getAPIManagerConfigurationService().getAPIManagerConfiguration() .getFirstProperty(APIConstants.CertificateReLoaderConfiguration.PERIOD); if (StringUtils.isNotEmpty(certificateReloaderPeriod)) { return Long.parseLong(certificateReloaderPeriod); } return 2L; }
Example #13
Source File: UserAwareAPIConsumer.java From carbon-apimgt with Apache License 2.0 | 5 votes |
UserAwareAPIConsumer() throws APIManagementException { super(); APIManagerConfiguration config = ServiceReferenceHolder.getInstance(). getAPIManagerConfigurationService().getAPIManagerConfiguration(); isAccessControlRestrictionEnabled = Boolean .parseBoolean(config.getFirstProperty(APIConstants.API_PUBLISHER_ENABLE_ACCESS_CONTROL_LEVELS)); }
Example #14
Source File: RemoteAuthorizationManagerClientTest.java From carbon-apimgt with Apache License 2.0 | 5 votes |
@Before public void setup() throws Exception { MockitoAnnotations.initMocks(this); PowerMockito.mockStatic(ServiceReferenceHolder.class); ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class); Mockito.when(apiManagerConfiguration.getFirstProperty(APIConstants.AUTH_MANAGER_URL)).thenReturn(SERVICE_URL); Mockito.when(apiManagerConfiguration.getFirstProperty(APIConstants.AUTH_MANAGER_USERNAME)).thenReturn(USER); Mockito.when(apiManagerConfiguration.getFirstProperty(APIConstants.AUTH_MANAGER_PASSWORD)).thenReturn(PASSWORD); Mockito.when(apiManagerConfigurationService.getAPIManagerConfiguration()).thenReturn(apiManagerConfiguration); Mockito.when(serviceReferenceHolder.getAPIManagerConfigurationService()) .thenReturn(apiManagerConfigurationService); PowerMockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder); Mockito.when(userStoreManager.getRoleNames()).thenReturn(ROLE_NAMES); Mockito.when(userStoreManager.getRoleListOfUser(USER)).thenReturn(ROLE_LIST); Mockito.when( authorizationManager.isUserAuthorized(USER_WRONG, PERMISSION, CarbonConstants.UI_PERMISSION_ACTION)) .thenReturn(false); Mockito.when(authorizationManager.isUserAuthorized(USER, PERMISSION, CarbonConstants.UI_PERMISSION_ACTION)) .thenReturn(true); Mockito.when(serviceContext.getProperty(HTTPConstants.COOKIE_STRING)).thenReturn(SESSION_COOKIE); Mockito.when(operationContext.getServiceContext()).thenReturn(serviceContext); Mockito.when(serviceClient.getOptions()).thenReturn(options); Mockito.when(serviceClient.getLastOperationContext()).thenReturn(operationContext); Mockito.when(authorizationManager._getServiceClient()).thenReturn(serviceClient); Mockito.when(userStoreManager._getServiceClient()).thenReturn(serviceClient); PowerMockito.whenNew(RemoteUserStoreManagerServiceStub.class).withAnyArguments().thenReturn(userStoreManager); PowerMockito.whenNew(RemoteAuthorizationManagerServiceStub.class).withAnyArguments() .thenReturn(authorizationManager); }
Example #15
Source File: APIUtilTest.java From carbon-apimgt with Apache License 2.0 | 5 votes |
@Test public void testGetCustomInSequence() throws Exception { APIIdentifier apiIdentifier = Mockito.mock(APIIdentifier.class); ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class); RegistryService registryService = Mockito.mock(RegistryService.class); UserRegistry registry = Mockito.mock(UserRegistry.class); PowerMockito.mockStatic(ServiceReferenceHolder.class); Mockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder); Mockito.when(serviceReferenceHolder.getRegistryService()).thenReturn(registryService); Mockito.when(registryService.getGovernanceSystemRegistry(eq(1))).thenReturn(registry); Collection collection = Mockito.mock(Collection.class); String artifactPath = APIConstants.API_ROOT_LOCATION + RegistryConstants.PATH_SEPARATOR + apiIdentifier.getProviderName() + RegistryConstants.PATH_SEPARATOR + apiIdentifier.getApiName() + RegistryConstants.PATH_SEPARATOR + apiIdentifier.getVersion(); String path = artifactPath + RegistryConstants.PATH_SEPARATOR + "in" + RegistryConstants.PATH_SEPARATOR; Mockito.when(registry.get(eq(path))).thenReturn(collection); String[] childPaths = {"test"}; Mockito.when(collection.getChildren()).thenReturn(childPaths); InputStream sampleSequence = new FileInputStream(Thread.currentThread().getContextClassLoader(). getResource("sampleSequence.xml").getFile()); Resource resource = Mockito.mock(Resource.class); Mockito.when(registry.get(eq("test"))).thenReturn(resource); Mockito.when(resource.getContentStream()).thenReturn(sampleSequence); OMElement customSequence = APIUtil.getCustomSequence("sample", 1, "in", apiIdentifier); Assert.assertNotNull(customSequence); sampleSequence.close(); }
Example #16
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 #17
Source File: APIUtilTest.java From carbon-apimgt with Apache License 2.0 | 5 votes |
@Test public void testGetMediationSequenceUuidOutSequence() throws Exception { APIIdentifier apiIdentifier = Mockito.mock(APIIdentifier.class); ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class); RegistryService registryService = Mockito.mock(RegistryService.class); UserRegistry registry = Mockito.mock(UserRegistry.class); PowerMockito.mockStatic(ServiceReferenceHolder.class); Mockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder); Mockito.when(serviceReferenceHolder.getRegistryService()).thenReturn(registryService); Mockito.when(registryService.getGovernanceSystemRegistry(eq(1))).thenReturn(registry); Collection collection = Mockito.mock(Collection.class); String path = APIConstants.API_CUSTOM_SEQUENCE_LOCATION + File.separator + APIConstants.API_CUSTOM_SEQUENCE_TYPE_OUT; Mockito.when(registry.get(eq(path))).thenReturn(collection); String[] childPaths = {"test"}; Mockito.when(collection.getChildren()).thenReturn(childPaths); String expectedUUID = UUID.randomUUID().toString(); InputStream sampleSequence = new FileInputStream(Thread.currentThread().getContextClassLoader(). getResource("sampleSequence.xml").getFile()); Resource resource = Mockito.mock(Resource.class); Mockito.when(registry.get(eq("test"))).thenReturn(resource); Mockito.when(resource.getContentStream()).thenReturn(sampleSequence); Mockito.when(resource.getUUID()).thenReturn(expectedUUID); String actualUUID = APIUtil.getMediationSequenceUuid("sample", 1, "out", apiIdentifier); Assert.assertEquals(expectedUUID, actualUUID); sampleSequence.close(); }
Example #18
Source File: DefaultGroupIDExtractorImplTest.java From carbon-apimgt with Apache License 2.0 | 5 votes |
@Test public void getGroupingIdentifiersTestCase() throws UserStoreException { ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class); PowerMockito.mockStatic(ServiceReferenceHolder.class); RealmService realmService = Mockito.mock(RealmService.class); UserRealm userRealm = Mockito.mock(UserRealm.class); APIManagerConfigurationService apiManagerConfigurationService = Mockito.mock(APIManagerConfigurationService .class); APIManagerConfiguration apiManagerConfiguration = Mockito.mock(APIManagerConfiguration.class); TenantManager tenantManager = Mockito.mock(TenantManager.class); UserStoreManager userStoreManager = Mockito.mock(UserStoreManager.class); Mockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder); Mockito.when(serviceReferenceHolder.getAPIManagerConfigurationService()).thenReturn (apiManagerConfigurationService); Mockito.when(apiManagerConfigurationService.getAPIManagerConfiguration()).thenReturn(apiManagerConfiguration); Mockito.when(apiManagerConfiguration.getFirstProperty(APIConstants.API_STORE_GROUP_EXTRACTOR_CLAIM_URI)) .thenReturn("http://wso2.org/claims/organization"); Mockito.when(serviceReferenceHolder.getRealmService()).thenReturn(realmService); Mockito.when(realmService.getTenantManager()).thenReturn(tenantManager); Mockito.when(tenantManager.getTenantId("carbon.super")).thenReturn(-1234); Mockito.when(realmService.getTenantUserRealm(-1234)).thenReturn(userRealm); Mockito.when(userRealm.getUserStoreManager()).thenReturn(userStoreManager); Mockito.when(userStoreManager.getUserClaimValue(MultitenantUtils. getTenantAwareUsername("user"), "http://wso2.org/claims/organization", null)). thenReturn("organization"); DefaultGroupIDExtractorImpl defaultGroupIDExtractor = new DefaultGroupIDExtractorImpl(); Assert.assertEquals("carbon.super/organization", defaultGroupIDExtractor. getGroupingIdentifiers("{\"user\":\"user\", \"isSuperTenant\":true}")); Assert.assertEquals("carbon.super/organization", defaultGroupIDExtractor. getGroupingIdentifiers("{\"user\":\"user\", \"isSuperTenant\":false}")); }
Example #19
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 #20
Source File: GAConfigMediaTypeHandler.java From carbon-apimgt with Apache License 2.0 | 5 votes |
private APIManagerConfiguration getAPIManagerConfig() { APIManagerConfigurationService apiManagerConfigurationService = ServiceReferenceHolder.getInstance() .getAPIManagerConfigurationService(); if (apiManagerConfigurationService == null) { return null; } return apiManagerConfigurationService.getAPIManagerConfiguration(); }
Example #21
Source File: CertificateManagerImpl.java From carbon-apimgt with Apache License 2.0 | 5 votes |
/** * Initializes an instance of CertificateManagerImpl. */ private CertificateManagerImpl() { String isMutualTLSConfigured = ServiceReferenceHolder.getInstance().getAPIManagerConfigurationService() .getAPIManagerConfiguration().getFirstProperty(APIConstants.ENABLE_MTLS_FOR_APIS); if (StringUtils.isNotEmpty(isMutualTLSConfigured) && isMutualTLSConfigured.equalsIgnoreCase("true")) { isMTLSConfigured = true; } if (isMTLSConfigured) { if (log.isDebugEnabled()) { log.debug("Mutual TLS based security is enabled for APIs. Hence APIs can be secured using mutual TLS " + "and OAuth2"); } TransportInDescription transportInDescription = ServiceReferenceHolder.getContextService() .getServerConfigContext().getAxisConfiguration().getTransportIn(Constants.TRANSPORT_HTTPS); Parameter profilePathParam = transportInDescription.getParameter("dynamicSSLProfilesConfig"); if (profilePathParam == null) { listenerProfileFilePath = null; } else { OMElement pathEl = profilePathParam.getParameterElement(); String path = pathEl.getFirstChildWithName(new QName("filePath")).getText(); if (path != null) { String separator = path.startsWith(File.separator) ? "" : File.separator; listenerProfileFilePath = System.getProperty("user.dir") + separator + path; } } } if (log.isDebugEnabled()) { if (isMTLSConfigured) { log.debug("Mutual SSL based authentication is supported for this server."); } else { log.debug("Mutual SSL based authentication is not supported for this server."); } } }
Example #22
Source File: TierCacheInvalidationClient.java From carbon-apimgt with Apache License 2.0 | 5 votes |
public TierCacheInvalidationClient() throws APIManagementException { APIManagerConfiguration config = ServiceReferenceHolder.getInstance().getAPIManagerConfigurationService() .getAPIManagerConfiguration(); storeServerURL = config.getFirstProperty(APIConstants.API_STORE_SERVER_URL); storeUserName = config.getFirstProperty(APIConstants.API_STORE_USERNAME); storePassword = config.getFirstProperty(APIConstants.API_STORE_PASSWORD); }
Example #23
Source File: APIStateChangeWSWorkflowExecutor.java From carbon-apimgt with Apache License 2.0 | 5 votes |
/** * get credentials that are needed to call the rest api in BPMN engine */ private String getBasicAuthHeader() { // if credentials are not defined in the workflow-extension.xml file, then get the global credentials from the // api-manager.xml configuration if (username == null || password == null) { WorkflowProperties workflowProperties = ServiceReferenceHolder.getInstance() .getAPIManagerConfigurationService().getAPIManagerConfiguration().getWorkflowProperties(); username = workflowProperties.getServerUser(); password = workflowProperties.getServerPassword(); } byte[] encodedAuth = Base64.encodeBase64((username + ":" + password).getBytes(Charset.forName("ISO-8859-1"))); return "Basic " + new String(encodedAuth); }
Example #24
Source File: SubscriptionUpdateWSWorkflowExecutor.java From carbon-apimgt with Apache License 2.0 | 5 votes |
/** * Retrieves configured ServiceClient for communication with external services * * @param action web service action to use * @return configured service client * @throws AxisFault */ public ServiceClient getClient(String action) throws AxisFault { ServiceClient client = new ServiceClient( ServiceReferenceHolder.getInstance().getContextService().getClientConfigContext(), null); Options options = new Options(); options.setAction(action); options.setTo(new EndpointReference(serviceEndpoint)); if (contentType != null) { options.setProperty(Constants.Configuration.MESSAGE_TYPE, contentType); } else { options.setProperty(Constants.Configuration.MESSAGE_TYPE, HTTPConstants.MEDIA_TYPE_TEXT_XML); } HttpTransportProperties.Authenticator auth = new HttpTransportProperties.Authenticator(); // Assumes authentication is required if username and password is given if (username != null && !username.isEmpty() && password != null && password.length != 0) { auth.setUsername(username); auth.setPassword(String.valueOf(password)); auth.setPreemptiveAuthentication(true); List<String> authSchemes = new ArrayList<String>(); authSchemes.add(HttpTransportProperties.Authenticator.BASIC); auth.setAuthSchemes(authSchemes); if (contentType == null) { options.setProperty(Constants.Configuration.MESSAGE_TYPE, HTTPConstants.MEDIA_TYPE_TEXT_XML); } options.setProperty(HTTPConstants.AUTHENTICATE, auth); options.setManageSession(true); } client.setOptions(options); return client; }
Example #25
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 #26
Source File: WorkflowExecutor.java From carbon-apimgt with Apache License 2.0 | 5 votes |
/** * This method is to publish workflow events * * @param workflowDTO workflow DTO */ public void publishEvents(WorkflowDTO workflowDTO) { boolean enabled = APIUtil.isAnalyticsEnabled(); if (enabled) { APIMgtWorkflowDataPublisher publisher = ServiceReferenceHolder.getInstance() .getApiMgtWorkflowDataPublisher(); publisher.publishEvent(workflowDTO); } }
Example #27
Source File: SubscriptionCreationWSWorkflowExecutor.java From carbon-apimgt with Apache License 2.0 | 5 votes |
/** * Retrieves configured ServiceClient for communication with external services * * @param action web service action to use * @return configured service client * @throws AxisFault */ public ServiceClient getClient(String action) throws AxisFault { ServiceClient client = new ServiceClient( ServiceReferenceHolder.getInstance().getContextService().getClientConfigContext(), null); Options options = new Options(); options.setAction(action); options.setTo(new EndpointReference(serviceEndpoint)); if (contentType != null) { options.setProperty(Constants.Configuration.MESSAGE_TYPE, contentType); } else { options.setProperty(Constants.Configuration.MESSAGE_TYPE, HTTPConstants.MEDIA_TYPE_TEXT_XML); } HttpTransportProperties.Authenticator auth = new HttpTransportProperties.Authenticator(); // Assumes authentication is required if username and password is given if (username != null && !username.isEmpty() && password != null && password.length != 0) { auth.setUsername(username); auth.setPassword(String.valueOf(password)); auth.setPreemptiveAuthentication(true); List<String> authSchemes = new ArrayList<String>(); authSchemes.add(HttpTransportProperties.Authenticator.BASIC); auth.setAuthSchemes(authSchemes); if (contentType == null) { options.setProperty(Constants.Configuration.MESSAGE_TYPE, HTTPConstants.MEDIA_TYPE_TEXT_XML); } options.setProperty(org.apache.axis2.transport.http.HTTPConstants.AUTHENTICATE, auth); options.setManageSession(true); } client.setOptions(options); return client; }
Example #28
Source File: ApplicationRegistrationWSWorkflowExecutor.java From carbon-apimgt with Apache License 2.0 | 5 votes |
/** * Retrieves configured ServiceClient for communication with external services * * @param action web service action to use * @return configured service client * @throws AxisFault */ public ServiceClient getClient(String action) throws AxisFault { ServiceClient client = new ServiceClient( ServiceReferenceHolder.getInstance().getContextService().getClientConfigContext(), null); Options options = new Options(); options.setAction(action); options.setTo(new EndpointReference(serviceEndpoint)); if (contentType != null) { options.setProperty(Constants.Configuration.MESSAGE_TYPE, contentType); } else { options.setProperty(Constants.Configuration.MESSAGE_TYPE, HTTPConstants.MEDIA_TYPE_TEXT_XML); } HttpTransportProperties.Authenticator auth = new HttpTransportProperties.Authenticator(); // Assumes authentication is required if username and password is given if (username != null && !username.isEmpty() && password != null && password.length != 0) { auth.setUsername(username); auth.setPassword(String.valueOf(password)); auth.setPreemptiveAuthentication(true); List<String> authSchemes = new ArrayList<String>(); authSchemes.add(HttpTransportProperties.Authenticator.BASIC); auth.setAuthSchemes(authSchemes); if (contentType == null) { options.setProperty(Constants.Configuration.MESSAGE_TYPE, HTTPConstants.MEDIA_TYPE_TEXT_XML); } options.setProperty(org.apache.axis2.transport.http.HTTPConstants.AUTHENTICATE, auth); options.setManageSession(true); } client.setOptions(options); return client; }
Example #29
Source File: ApplicationCreationWSWorkflowExecutor.java From carbon-apimgt with Apache License 2.0 | 5 votes |
/** * Retrieves configured ServiceClient for communication with external services * * @param action web service action to use * @return configured service client * @throws AxisFault */ public ServiceClient getClient(String action) throws AxisFault { ServiceClient client = new ServiceClient( ServiceReferenceHolder.getInstance().getContextService().getClientConfigContext(), null); Options options = new Options(); options.setAction(action); options.setTo(new EndpointReference(serviceEndpoint)); if (contentType != null) { options.setProperty(Constants.Configuration.MESSAGE_TYPE, contentType); } else { options.setProperty(Constants.Configuration.MESSAGE_TYPE, HTTPConstants.MEDIA_TYPE_TEXT_XML); } HttpTransportProperties.Authenticator auth = new HttpTransportProperties.Authenticator(); // Assumes authentication is required if username and password is given if (username != null && !username.isEmpty() && password != null && password.length != 0) { auth.setUsername(username); auth.setPassword(String.valueOf(password)); auth.setPreemptiveAuthentication(true); List<String> authSchemes = new ArrayList<String>(); authSchemes.add(HttpTransportProperties.Authenticator.BASIC); auth.setAuthSchemes(authSchemes); if (contentType == null) { options.setProperty(Constants.Configuration.MESSAGE_TYPE, HTTPConstants.MEDIA_TYPE_TEXT_XML); } options.setProperty(org.apache.axis2.transport.http.HTTPConstants.AUTHENTICATE, auth); options.setManageSession(true); } client.setOptions(options); return client; }
Example #30
Source File: UserAwareAPIConsumer.java From carbon-apimgt with Apache License 2.0 | 5 votes |
UserAwareAPIConsumer(String username, APIMRegistryService registryService) throws APIManagementException { super(username, registryService); this.username = username; APIManagerConfiguration config = ServiceReferenceHolder.getInstance(). getAPIManagerConfigurationService().getAPIManagerConfiguration(); isAccessControlRestrictionEnabled = Boolean .parseBoolean(config.getFirstProperty(APIConstants.API_PUBLISHER_ENABLE_ACCESS_CONTROL_LEVELS)); }