use of org.wso2.carbon.apimgt.impl.APIManagerConfiguration in project carbon-apimgt by wso2.
the class ThrottleHandlerTest method init.
@Before
public void init() {
timer = Mockito.mock(Timer.class);
timer = Mockito.mock(Timer.class);
context = Mockito.mock(Timer.Context.class);
throttleEvaluator = Mockito.mock(ThrottleConditionEvaluator.class);
accessInformation = Mockito.mock(AccessInformation.class);
Mockito.when(timer.start()).thenReturn(context);
verbInfoDTO = new ArrayList<>();
verbInfo = new VerbInfoDTO();
verbInfo.setHttpVerb(httpVerb);
verbInfo.setRequestKey(apiContext + "/" + apiVersion + resourceUri + ":" + httpVerb);
verbInfo.setThrottling(throttlingTier);
verbInfoDTO.add(verbInfo);
conditionGroupDTO = new ConditionGroupDTO();
conditionGroupDTO.setConditionGroupId("_default");
conditionGroupDTOs = new ConditionGroupDTO[1];
conditionGroupDTOs[0] = conditionGroupDTO;
apiLevelThrottleKey = apiContext + ":" + apiVersion;
resourceLevelThrottleKey = apiContext + "/" + apiVersion + resourceUri + ":" + httpVerb;
org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder.class);
PowerMockito.mockStatic(org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder.class);
Mockito.when(org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder);
APIManagerConfigurationService apiManagerConfigurationService = Mockito.mock(APIManagerConfigurationService.class);
APIManagerConfiguration apiManagerConfiguration = Mockito.mock(APIManagerConfiguration.class);
Mockito.when(serviceReferenceHolder.getAPIManagerConfigurationService()).thenReturn(apiManagerConfigurationService);
Mockito.when(apiManagerConfigurationService.getAPIManagerConfiguration()).thenReturn(apiManagerConfiguration);
Mockito.when(apiManagerConfiguration.getExtensionListenerMap()).thenReturn(extensionListenerMap);
}
use of org.wso2.carbon.apimgt.impl.APIManagerConfiguration in project carbon-apimgt by wso2.
the class APISecurityUtilsTestCase method testSetAuthenticationContext.
public void testSetAuthenticationContext() {
PowerMockito.mockStatic(ServiceReferenceHolder.class);
ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class);
PowerMockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder);
APIManagerConfiguration apiMgtConfig = Mockito.mock(APIManagerConfiguration.class);
Mockito.when(serviceReferenceHolder.getAPIManagerConfiguration()).thenReturn(apiMgtConfig);
MessageContext messageContext = Mockito.mock(Axis2MessageContext.class);
AuthenticationContext authenticationContext = Mockito.mock(AuthenticationContext.class);
Mockito.when(authenticationContext.getKeyType()).thenReturn("keyType");
APISecurityUtils.setAuthenticationContext(messageContext, authenticationContext, "abc");
// test when caller token is not null
Mockito.when(authenticationContext.getCallerToken()).thenReturn("callertoken");
Mockito.when(messageContext.getProperty(APIConstants.API_KEY_TYPE)).thenReturn("keyType");
// Axis2MessageContext axis2MessageContext = Mockito.mock(Axis2MessageContext.class);
org.apache.axis2.context.MessageContext axis2MsgCntxt = Mockito.mock(org.apache.axis2.context.MessageContext.class);
Mockito.when(((Axis2MessageContext) messageContext).getAxis2MessageContext()).thenReturn(axis2MsgCntxt);
Map transportHeaders = new HashMap();
Mockito.when(axis2MsgCntxt.getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS)).thenReturn(transportHeaders);
APISecurityUtils.setAuthenticationContext(messageContext, authenticationContext, "abc");
Assert.assertEquals(APISecurityUtils.getAuthenticationContext(messageContext).getCallerToken(), "callertoken");
Assert.assertEquals("keyType", messageContext.getProperty(APIConstants.API_KEY_TYPE));
// test for IllegalStateException
String API_AUTH_CONTEXT = "__API_AUTH_CONTEXT";
Mockito.when(authenticationContext.getCallerToken()).thenReturn("newCallerToken");
Mockito.when(messageContext.getProperty(API_AUTH_CONTEXT)).thenReturn("abc");
APISecurityUtils.setAuthenticationContext(messageContext, authenticationContext, "abc");
Assert.assertEquals(APISecurityUtils.getAuthenticationContext(messageContext).getCallerToken(), "newCallerToken");
}
use of org.wso2.carbon.apimgt.impl.APIManagerConfiguration in project carbon-apimgt by wso2.
the class OAuthAuthenticatorTest method initOAuthParams.
@Test
public void initOAuthParams() throws Exception {
APIManagerConfiguration apiManagerConfiguration = Mockito.mock(APIManagerConfiguration.class);
OAuthAuthenticator oauthAuthenticator = new OauthAuthenticatorWrapper(apiManagerConfiguration);
Mockito.when(apiManagerConfiguration.getFirstProperty(APIConstants.REMOVE_OAUTH_HEADERS_FROM_MESSAGE)).thenReturn("true");
Mockito.when(apiManagerConfiguration.getJwtConfigurationDto()).thenReturn(new ExtendedJWTConfigurationDto());
}
use of org.wso2.carbon.apimgt.impl.APIManagerConfiguration in project carbon-apimgt by wso2.
the class CommonConfigDeployer method createdConfigurationContext.
public void createdConfigurationContext(ConfigurationContext configurationContext) {
final String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
final int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
APIManagerConfiguration configuration = ServiceReferenceHolder.getInstance().getAPIManagerConfigurationService().getAPIManagerConfiguration();
try {
// TODO adding only the policies to data wouldn't be sufficient. Need to figure out approach after tenant story has finalized
// Add default set of policies to database
ThrottleProperties.PolicyDeployer policyDeployer = configuration.getThrottleProperties().getPolicyDeployer();
// Also this will avoid tenant login overhead as well
if (policyDeployer.isEnabled()) {
Thread t1 = new Thread(new Runnable() {
public void run() {
try {
APIUtil.addDefaultTenantAdvancedThrottlePolicies(tenantDomain, tenantId);
} catch (APIManagementException e) {
log.error("Error while deploying throttle policies", e);
}
}
});
t1.start();
}
} catch (Exception e) {
log.error("Failed to load default policies to tenant" + tenantDomain, e);
}
try {
// Check whether GatewayType is "Synapse" before attempting to load Custom-Sequences into registry
String gatewayType = configuration.getFirstProperty(APIConstants.API_GATEWAY_TYPE);
if (APIConstants.API_GATEWAY_TYPE_SYNAPSE.equalsIgnoreCase(gatewayType)) {
APIUtil.writeDefinedSequencesToTenantRegistry(tenantId);
}
}// Need to continue the execution even if we encounter an error.
catch (Exception e) {
log.error("Failed to write defined sequences to tenant " + tenantDomain + "'s registry", e);
}
try {
APIUtil.loadTenantExternalStoreConfig(tenantDomain);
} catch (Exception e) {
log.error("Failed to load external-stores.xml to tenant " + tenantDomain + "'s registry", e);
}
try {
APIUtil.loadTenantGAConfig(tenantDomain);
} catch (Exception e) {
log.error("Failed to load ga-config.xml to tenant " + tenantDomain + "'s registry", e);
}
try {
// load workflow-extension configuration to the registry
APIUtil.loadTenantWorkFlowExtensions(tenantDomain);
} catch (Exception e) {
log.error("Failed to load workflow-extension.xml to tenant " + tenantDomain + "'s registry", e);
}
try {
// load self signup configurations to the registry
APIUtil.loadTenantSelfSignUpConfigurations(tenantDomain);
} catch (Exception e) {
log.error("Failed to load sign-up-config.xml to tenant " + tenantDomain + "'s registry", e);
}
try {
APIUtil.loadAndSyncTenantConf(tenantDomain);
} catch (APIManagementException e) {
log.error("Failed to load " + APIConstants.API_TENANT_CONF + " for tenant " + tenantDomain, e);
} catch (Exception e) {
// The generic Exception is handled explicitly so execution does not stop during config deployment
log.error("Exception when loading " + APIConstants.API_TENANT_CONF + " for tenant " + tenantDomain, e);
}
try {
// Load common operation policies to tenant
APIUtil.loadCommonOperationPolicies(tenantDomain);
} catch (Exception e) {
// The generic Exception is handled explicitly so execution does not stop during config deployment
log.error("Exception when loading " + APIConstants.OPERATION_POLICIES + " for tenant " + tenantDomain, e);
}
try {
APIUtil.createDefaultRoles(tenantId);
} catch (APIManagementException e) {
log.error("Failed create default roles for tenant " + tenantDomain, e);
} catch (Exception e) {
// The generic Exception is handled explicitly so execution does not stop during config deployment
log.error("Exception when creating default roles for tenant " + tenantDomain, e);
}
try {
CommonUtil.addDefaultLifecyclesIfNotAvailable(ServiceReferenceHolder.getInstance().getRegistryService().getConfigSystemRegistry(tenantId), CommonUtil.getRootSystemRegistry(tenantId));
} catch (RegistryException e) {
log.error("Error while accessing registry", e);
} catch (FileNotFoundException e) {
log.error("Error while find lifecycle.xml", e);
} catch (XMLStreamException e) {
log.error("Error while parsing Lifecycle.xml", e);
}
KeyManagerConfigurationDataRetriever keyManagerConfigurationDataRetriever = new KeyManagerConfigurationDataRetriever(tenantDomain);
keyManagerConfigurationDataRetriever.startLoadKeyManagerConfigurations();
}
use of org.wso2.carbon.apimgt.impl.APIManagerConfiguration in project carbon-apimgt by wso2.
the class JMSListenerComponent method activate.
@Activate
protected void activate(ComponentContext context) {
log.debug("Activating component...");
APIManagerConfiguration configuration = ServiceReferenceHolder.getInstance().getAPIMConfiguration();
if (configuration == null) {
log.warn("API Manager Configuration not properly set.");
return;
}
JMSListenerStartupShutdownListener jmsListenerStartupShutdownListener = new JMSListenerStartupShutdownListener();
registration = context.getBundleContext().registerService(ServerStartupObserver.class, jmsListenerStartupShutdownListener, null);
registration = context.getBundleContext().registerService(ServerShutdownHandler.class, jmsListenerStartupShutdownListener, null);
registration = context.getBundleContext().registerService(JMSListenerShutDownService.class, jmsListenerStartupShutdownListener, null);
}
Aggregations