use of org.wso2.carbon.bpel.core.ode.integration.jmx.Instance in project carbon-apimgt by wso2.
the class AuthenticatorAPIFactory method getService.
/**
* Get an instance of AuthenticatorService
*
* @return AuthenticatorService
* @throws APIMgtDAOException if failed to initialize SystemApplicationDao
* @throws IdentityProviderException if failed to initialize IdentityProvider
*/
public synchronized AuthenticatorService getService() throws APIMgtDAOException, IdentityProviderException {
if (service == null) {
IdentityProvider identityProvider = APIManagerFactory.getInstance().getIdentityProvider();
SystemApplicationDao systemApplicationDao = DAOFactory.getSystemApplicationDao();
APIMConfigurationService apimConfigurationService = APIMConfigurationService.getInstance();
APIMAppConfigurationService apimAppConfigurationService = APIMAppConfigurationService.getInstance();
service = new AuthenticatorService(identityProvider, systemApplicationDao, apimConfigurationService, apimAppConfigurationService);
}
return service;
}
use of org.wso2.carbon.bpel.core.ode.integration.jmx.Instance in project carbon-apimgt by wso2.
the class ServiceReferenceHolderTestCase method testGetRestAPIConfigurationMap.
@Test
public void testGetRestAPIConfigurationMap() throws ConfigurationException {
// // Happy Path
ServiceReferenceHolder instance = ServiceReferenceHolder.getInstance();
ConfigProvider configProvider = Mockito.mock(ConfigProvider.class);
instance.setConfigProvider(configProvider);
Map<String, String> expectedConfigMap = new HashMap<>();
expectedConfigMap.put("apimBaseUrl", "https://localhost:9443/");
Mockito.when(configProvider.getConfigurationObject("xxx-namespace-xxx")).thenReturn(expectedConfigMap);
Map<String, String> actualConfigMap = instance.getRestAPIConfigurationMap("xxx-namespace-xxx");
Assert.assertEquals(expectedConfigMap, actualConfigMap);
// // Error path
// // ConfigurationException
Mockito.when(configProvider.getConfigurationObject("xxx-namespace-xxx")).thenThrow(ConfigurationException.class);
actualConfigMap = instance.getRestAPIConfigurationMap("xxx-namespace-xxx");
Assert.assertNull(actualConfigMap);
// // config provider is null
instance.setConfigProvider(null);
actualConfigMap = instance.getRestAPIConfigurationMap("xxx-namespace-xxx");
Assert.assertNull(actualConfigMap);
}
use of org.wso2.carbon.bpel.core.ode.integration.jmx.Instance in project carbon-apimgt by wso2.
the class AnalyzerHolder method getAnalyzer.
/**
* Borrows an object from pools (xml or json) for threat analysis
*
* @param contentType Content-Type of the payload
* @param policyId ID of the API
* @return Instance of APIMThreatAnalyzer based on content type
*/
public static APIMThreatAnalyzer getAnalyzer(String contentType, String policyId) {
APIMThreatAnalyzer analyzer = null;
if (T_TEXT_XML.equalsIgnoreCase(contentType) || T_APPLICATION_XML.equalsIgnoreCase(contentType)) {
try {
analyzer = xmlAnalyzerAnalyzerPool.borrowObject();
// configure per api
XMLConfig xmlConfig = ConfigurationHolder.getXmlConfig(policyId);
if (xmlConfig == null) {
xmlConfig = ConfigurationHolder.getXmlConfig("GLOBAL-XML");
}
if (xmlConfig == null) {
return null;
}
analyzer.configure(xmlConfig);
} catch (Exception e) {
logger.error("Threat Protection: Failed to create XMLAnalyzer, " + e.getMessage());
}
} else if (T_TEXT_JSON.equalsIgnoreCase(contentType) || T_APPLICATION_JSON.equalsIgnoreCase(contentType)) {
try {
analyzer = jsonAnalyzerAnalyzerPool.borrowObject();
// configure per api
JSONConfig jsonConfig = ConfigurationHolder.getJsonConfig(policyId);
if (jsonConfig == null) {
jsonConfig = ConfigurationHolder.getJsonConfig("GLOBAL-JSON");
}
if (jsonConfig == null) {
return null;
}
analyzer.configure(jsonConfig);
} catch (Exception e) {
logger.error("Threat Protection: Failed to create JSONAnalyzer, " + e.getMessage());
}
}
return analyzer;
}
use of org.wso2.carbon.bpel.core.ode.integration.jmx.Instance in project carbon-apimgt by wso2.
the class ApiStoreSdkGenerationManagerTestCase method testGenerateSdkForApi.
@Test
public void testGenerateSdkForApi() throws APIManagementException, ApiStoreSdkGenerationException {
String apiId = UUID.randomUUID().toString();
APIManagerFactory instance = Mockito.mock(APIManagerFactory.class);
PowerMockito.mockStatic(APIManagerFactory.class);
PowerMockito.when(APIManagerFactory.getInstance()).thenReturn(instance);
APIStore apiStore = Mockito.mock(APIStoreImpl.class);
Mockito.when(instance.getAPIConsumer(USER)).thenReturn(apiStore);
API api = SampleTestObjectCreator.createDefaultAPI().build();
Mockito.when(apiStore.getAPIbyUUID(apiId)).thenReturn(api);
Mockito.when(apiStore.getApiSwaggerDefinition(apiId)).thenReturn(swaggerPetStore);
ApiStoreSdkGenerationManager sdkGenerationManager = new ApiStoreSdkGenerationManager();
String pathToZip = sdkGenerationManager.generateSdkForApi(apiId, LANGUAGE, USER);
File sdkZipFile = new File(pathToZip);
Assert.assertTrue(sdkZipFile.exists() && sdkZipFile.length() > MIN_SDK_SIZE);
}
use of org.wso2.carbon.bpel.core.ode.integration.jmx.Instance in project carbon-apimgt by wso2.
the class ApiStoreSdkGenerationManagerTestCase method testGenerateSdkForApiIncorrectSwagger.
@Test(expected = NullPointerException.class)
public void testGenerateSdkForApiIncorrectSwagger() throws APIManagementException, ApiStoreSdkGenerationException {
String apiId = UUID.randomUUID().toString();
APIManagerFactory instance = Mockito.mock(APIManagerFactory.class);
PowerMockito.mockStatic(APIManagerFactory.class);
PowerMockito.when(APIManagerFactory.getInstance()).thenReturn(instance);
APIStore apiStore = Mockito.mock(APIStoreImpl.class);
Mockito.when(instance.getAPIConsumer(USER)).thenReturn(apiStore);
API api = SampleTestObjectCreator.createDefaultAPI().build();
Mockito.when(apiStore.getAPIbyUUID(apiId)).thenReturn(api);
Mockito.when(apiStore.getApiSwaggerDefinition(apiId)).thenReturn(null);
ApiStoreSdkGenerationManager sdkGenerationManager = new ApiStoreSdkGenerationManager();
sdkGenerationManager.generateSdkForApi(apiId, LANGUAGE, USER);
}
Aggregations