use of org.wso2.carbon.identity.core.ServiceURL in project identity-inbound-auth-oauth by wso2-extensions.
the class DeviceEndpointTest method testDevice.
/**
* Test the device_authorize endpoint.
*
* @param clientId Consumer key of the application.
* @param expectedStatus Expected status for response.
* @param status Status of user code.
* @throws IdentityOAuth2Exception If failed at device endpoint
* @throws OAuthSystemException If failed at device endpoint.
*/
@Test(dataProvider = "dataValues")
public void testDevice(String clientId, int expectedStatus, boolean status) throws Exception {
DeviceEndpoint deviceEndpoint = PowerMockito.spy(new DeviceEndpoint());
mockOAuthServerConfiguration();
mockStatic(ServiceURLBuilder.class);
mockStatic(ServiceURL.class);
ServiceURLBuilder mockServiceURLBuilder = Mockito.mock(ServiceURLBuilder.class);
ServiceURL mockServiceURL = Mockito.mock(ServiceURL.class);
when(ServiceURLBuilder.create()).thenReturn(mockServiceURLBuilder);
when(mockServiceURLBuilder.addPath(anyString())).thenReturn(mockServiceURLBuilder);
when(mockServiceURLBuilder.addParameter(anyString(), anyString())).thenReturn(mockServiceURLBuilder);
when(mockServiceURLBuilder.build()).thenReturn(mockServiceURL);
when(mockServiceURL.getAbsolutePublicURL()).thenReturn("http://localhost:9443/authenticationendpoint/device.do");
mockStatic(HttpServletRequest.class);
OAuthClientAuthnContext oAuthClientAuthnContext = new OAuthClientAuthnContext();
oAuthClientAuthnContext.setClientId(clientId);
oAuthClientAuthnContext.setAuthenticated(status);
when(request.getAttribute(anyString())).thenReturn(oAuthClientAuthnContext);
DeviceAuthServiceImpl deviceAuthService = new DeviceAuthServiceImpl();
deviceEndpoint.setDeviceAuthService(deviceAuthService);
mockStatic(IdentityDatabaseUtil.class);
when(IdentityDatabaseUtil.getDBConnection(true)).thenReturn(connection);
when(IdentityDatabaseUtil.getDBConnection(false)).thenReturn(connection);
when(httpServletRequest.getParameter(anyString())).thenReturn(clientId);
Response response;
mockStatic(IdentityUtil.class);
when(IdentityUtil.getServerURL(anyString(), anyBoolean(), anyBoolean())).thenReturn(TEST_URL);
mockStatic(DeviceFlowPersistenceFactory.class);
when(DeviceFlowPersistenceFactory.getInstance()).thenReturn(deviceFlowPersistenceFactory);
when(deviceFlowPersistenceFactory.getDeviceFlowDAO()).thenReturn(deviceFlowDAO);
when(deviceFlowDAO.checkClientIdExist(anyString())).thenReturn(status);
PowerMockito.when(deviceEndpoint, "getValidationObject", httpServletRequest).thenReturn(oAuthClientAuthnContext);
response = deviceEndpoint.authorize(httpServletRequest, new MultivaluedHashMap<String, String>(), httpServletResponse);
Assert.assertEquals(expectedStatus, response.getStatus());
}
use of org.wso2.carbon.identity.core.ServiceURL in project product-is by wso2.
the class AbstractIdentityFederationTestCase method createServiceClients.
public void createServiceClients(int portOffset, String sessionCookie, IdentityConstants.ServiceClientType[] adminClients) throws Exception {
if (adminClients == null) {
return;
}
String serviceUrl = getSecureServiceUrl(portOffset, automationContextMap.get(portOffset).getContextUrls().getSecureServiceUrl());
if (sessionCookie == null) {
AuthenticatorClient authenticatorClient = new AuthenticatorClient(serviceUrl);
sessionCookie = authenticatorClient.login(automationContextMap.get(portOffset).getSuperTenant().getTenantAdmin().getUserName(), automationContextMap.get(portOffset).getSuperTenant().getTenantAdmin().getPassword(), automationContextMap.get(portOffset).getDefaultInstance().getHosts().get("default"));
}
if (sessionCookie != null) {
ConfigurationContext configContext = ConfigurationContextFactory.createConfigurationContextFromFileSystem(null, null);
for (IdentityConstants.ServiceClientType clientType : adminClients) {
if (IdentityConstants.ServiceClientType.APPLICATION_MANAGEMENT.equals(clientType)) {
applicationManagementServiceClients.put(portOffset, new ApplicationManagementServiceClient(sessionCookie, serviceUrl, configContext));
} else if (IdentityConstants.ServiceClientType.IDENTITY_PROVIDER_MGT.equals(clientType)) {
identityProviderMgtServiceClients.put(portOffset, new IdentityProviderMgtServiceClient(sessionCookie, serviceUrl));
} else if (IdentityConstants.ServiceClientType.SAML_SSO_CONFIG.equals(clientType)) {
samlSSOConfigServiceClients.put(portOffset, new SAMLSSOConfigServiceClient(serviceUrl, sessionCookie));
} else if (IdentityConstants.ServiceClientType.OAUTH_ADMIN.equals(clientType)) {
oauthAdminClients.put(portOffset, new OauthAdminClient(serviceUrl, sessionCookie));
}
}
}
}
use of org.wso2.carbon.identity.core.ServiceURL in project carbon-apimgt by wso2.
the class APIKeyValidator method isAPIResourceValidationEnabled.
public boolean isAPIResourceValidationEnabled() {
try {
APIManagerConfiguration config = getApiManagerConfiguration();
String serviceURL = config.getFirstProperty(APIConstants.GATEWAY_RESOURCE_CACHE_ENABLED);
return Boolean.parseBoolean(serviceURL);
} catch (Exception e) {
log.error("Did not found valid API Resource Validation Information cache configuration. Use default configuration" + e);
}
return true;
}
use of org.wso2.carbon.identity.core.ServiceURL in project carbon-apimgt by wso2.
the class APIManagerConfiguration method setThrottleProperties.
/**
* set the Advance Throttle Properties into Configuration
*
* @param element
*/
private void setThrottleProperties(OMElement element) {
OMElement throttleConfigurationElement = element.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.THROTTLING_CONFIGURATIONS));
if (throttleConfigurationElement != null) {
// Check unlimited tier enabled
OMElement enableUnlimitedTierElement = throttleConfigurationElement.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.ENABLE_UNLIMITED_TIER));
if (enableUnlimitedTierElement != null) {
throttleProperties.setEnableUnlimitedTier(JavaUtils.isTrueExplicitly(enableUnlimitedTierElement.getText()));
}
// Check header condition enable
OMElement enableHeaderConditionsElement = throttleConfigurationElement.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.ENABLE_HEADER_CONDITIONS));
if (enableHeaderConditionsElement != null) {
throttleProperties.setEnableHeaderConditions(JavaUtils.isTrueExplicitly(enableHeaderConditionsElement.getText()));
}
// Check JWT condition enable
OMElement enableJwtElement = throttleConfigurationElement.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.ENABLE_JWT_CLAIM_CONDITIONS));
if (enableJwtElement != null) {
throttleProperties.setEnableJwtConditions(JavaUtils.isTrueExplicitly(enableJwtElement.getText()));
}
// Check query param condition enable
OMElement enableQueryParamElement = throttleConfigurationElement.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.ENABLE_QUERY_PARAM_CONDITIONS));
if (enableQueryParamElement != null) {
throttleProperties.setEnableQueryParamConditions(JavaUtils.isTrueExplicitly(enableQueryParamElement.getText()));
}
// Check skip redeploy throttle policies
OMElement skipRedeployingPoliciesElement = throttleConfigurationElement.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.SKIP_REDEPLOYING_POLICIES));
if (skipRedeployingPoliciesElement != null) {
throttleProperties.setSkipRedeployingPolicies(skipRedeployingPoliciesElement.getText().split(APIConstants.DELEM_COMMA));
}
OMElement enablePolicyDeployElement = throttleConfigurationElement.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.ENABLE_POLICY_DEPLOYMENT));
if (enablePolicyDeployElement != null) {
throttleProperties.setEnablePolicyDeployment(Boolean.parseBoolean(enablePolicyDeployElement.getText()));
}
// Check subscription spike arrest enable
OMElement enabledSubscriptionLevelSpikeArrestElement = throttleConfigurationElement.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.ENABLE_SUBSCRIPTION_SPIKE_ARREST));
if (enabledSubscriptionLevelSpikeArrestElement != null) {
throttleProperties.setEnabledSubscriptionLevelSpikeArrest(JavaUtils.isTrueExplicitly(enabledSubscriptionLevelSpikeArrestElement.getText()));
}
// Reading TrafficManager configuration
OMElement trafficManagerConfigurationElement = throttleConfigurationElement.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.TRAFFIC_MANAGER));
ThrottleProperties.TrafficManager trafficManager = new ThrottleProperties.TrafficManager();
if (trafficManagerConfigurationElement != null) {
OMElement receiverUrlGroupElement = trafficManagerConfigurationElement.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.DATA_PUBLISHER_CONFIGURAION_REVEIVER_URL_GROUP));
if (receiverUrlGroupElement != null) {
trafficManager.setReceiverUrlGroup(APIUtil.replaceSystemProperty(receiverUrlGroupElement.getText()));
}
OMElement authUrlGroupElement = trafficManagerConfigurationElement.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.DATA_PUBLISHER_CONFIGURAION_AUTH_URL_GROUP));
if (authUrlGroupElement != null) {
trafficManager.setAuthUrlGroup(APIUtil.replaceSystemProperty(authUrlGroupElement.getText()));
}
OMElement dataPublisherUsernameElement = trafficManagerConfigurationElement.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.USERNAME));
if (dataPublisherUsernameElement != null) {
trafficManager.setUsername(APIUtil.replaceSystemProperty(dataPublisherUsernameElement.getText()));
}
OMElement dataPublisherTypeElement = trafficManagerConfigurationElement.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.DATA_PUBLISHER_CONFIGURAION_TYPE));
if (dataPublisherTypeElement != null) {
trafficManager.setType(dataPublisherTypeElement.getText());
}
String dataPublisherConfigurationPassword;
OMElement dataPublisherConfigurationPasswordOmElement = trafficManagerConfigurationElement.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.PASSWORD));
dataPublisherConfigurationPassword = MiscellaneousUtil.resolve(dataPublisherConfigurationPasswordOmElement, secretResolver);
trafficManager.setPassword(APIUtil.replaceSystemProperty(dataPublisherConfigurationPassword));
throttleProperties.setTrafficManager(trafficManager);
}
// Configuring throttle data publisher
ThrottleProperties.DataPublisher dataPublisher = new ThrottleProperties.DataPublisher();
OMElement dataPublisherConfigurationElement = throttleConfigurationElement.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.DATA_PUBLISHER_CONFIGURATION));
if (dataPublisherConfigurationElement != null) {
OMElement dataPublisherEnabledElement = dataPublisherConfigurationElement.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.ENABLED));
dataPublisher.setEnabled(JavaUtils.isTrueExplicitly(dataPublisherEnabledElement.getText()));
dataPublisher.setAuthUrlGroup(trafficManager.getAuthUrlGroup());
dataPublisher.setReceiverUrlGroup(trafficManager.getReceiverUrlGroup());
dataPublisher.setUsername(trafficManager.getUsername());
dataPublisher.setPassword(trafficManager.getPassword());
dataPublisher.setType(trafficManager.getType());
}
if (dataPublisher.isEnabled()) {
throttleProperties.setDataPublisher(dataPublisher);
// Data publisher pool configuration
OMElement dataPublisherPoolConfigurationElement = dataPublisherConfigurationElement.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.DATA_PUBLISHER_POOL_CONFIGURATION));
ThrottleProperties.DataPublisherPool dataPublisherPool = new ThrottleProperties.DataPublisherPool();
OMElement maxIdleElement = dataPublisherPoolConfigurationElement.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.DATA_PUBLISHER_POOL_CONFIGURAION_MAX_IDLE));
if (maxIdleElement != null) {
dataPublisherPool.setMaxIdle(Integer.parseInt(maxIdleElement.getText()));
}
OMElement initIdleElement = dataPublisherPoolConfigurationElement.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.DATA_PUBLISHER_POOL_CONFIGURAION_INIT_IDLE));
if (initIdleElement != null) {
dataPublisherPool.setInitIdleCapacity(Integer.parseInt(initIdleElement.getText()));
}
throttleProperties.setDataPublisherPool(dataPublisherPool);
// Data publisher thread pool configuration
OMElement dataPublisherThreadPoolConfigurationElement = dataPublisherConfigurationElement.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.DATA_PUBLISHER_THREAD_POOL_CONFIGURATION));
ThrottleProperties.DataPublisherThreadPool dataPublisherThreadPool = new ThrottleProperties.DataPublisherThreadPool();
if (dataPublisherThreadPoolConfigurationElement != null) {
OMElement corePoolSizeElement = dataPublisherThreadPoolConfigurationElement.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.DATA_PUBLISHER_THREAD_POOL_CONFIGURATION_CORE_POOL_SIZE));
if (corePoolSizeElement != null) {
dataPublisherThreadPool.setCorePoolSize(Integer.parseInt(corePoolSizeElement.getText()));
}
OMElement maximumPoolSizeElement = dataPublisherThreadPoolConfigurationElement.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.DATA_PUBLISHER_THREAD_POOL_CONFIGURATION_MAXMIMUM_POOL_SIZE));
if (maximumPoolSizeElement != null) {
dataPublisherThreadPool.setMaximumPoolSize(Integer.parseInt(maximumPoolSizeElement.getText()));
}
OMElement keepAliveTimeElement = dataPublisherThreadPoolConfigurationElement.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.DATA_PUBLISHER_THREAD_POOL_CONFIGURATION_KEEP_ALIVE_TIME));
if (keepAliveTimeElement != null) {
dataPublisherThreadPool.setKeepAliveTime(Long.parseLong(keepAliveTimeElement.getText()));
}
}
throttleProperties.setDataPublisherThreadPool(dataPublisherThreadPool);
}
// Configuring JMSConnectionDetails
ThrottleProperties.JMSConnectionProperties jmsConnectionProperties = new ThrottleProperties.JMSConnectionProperties();
OMElement jmsConnectionDetailElement = throttleConfigurationElement.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.JMS_CONNECTION_DETAILS));
if (jmsConnectionDetailElement != null) {
OMElement jmsConnectionEnabledElement = jmsConnectionDetailElement.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.ENABLED));
jmsConnectionProperties.setEnabled(JavaUtils.isTrueExplicitly(jmsConnectionEnabledElement.getText()));
OMElement jmsConnectionUrlElement = jmsConnectionDetailElement.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.SERVICE_URL));
if (jmsConnectionUrlElement != null) {
jmsConnectionProperties.setServiceUrl(APIUtil.replaceSystemProperty(jmsConnectionUrlElement.getText()));
System.setProperty("jms.url", jmsConnectionProperties.getServiceUrl());
}
OMElement jmsConnectionUserElement = jmsConnectionDetailElement.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.USERNAME));
if (jmsConnectionUserElement != null) {
jmsConnectionProperties.setUsername(APIUtil.replaceSystemProperty(jmsConnectionUserElement.getText()));
System.setProperty("jms.username", jmsConnectionProperties.getUsername());
}
OMElement jmsConnectionPasswordElement = jmsConnectionDetailElement.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.PASSWORD));
if (jmsConnectionPasswordElement != null) {
OMElement jmsConnectionPasswordOmElement = jmsConnectionDetailElement.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.PASSWORD));
String jmsConnectionPassword = MiscellaneousUtil.resolve(jmsConnectionPasswordOmElement, secretResolver);
jmsConnectionProperties.setPassword(APIUtil.replaceSystemProperty(jmsConnectionPassword));
System.setProperty("jms.password", jmsConnectionProperties.getPassword());
}
OMElement jmsConnectionParameterElement = jmsConnectionDetailElement.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.JMS_CONNECTION_PARAMETERS));
if (jmsConnectionParameterElement != null) {
Iterator jmsProperties = jmsConnectionParameterElement.getChildElements();
Properties properties = new Properties();
while (jmsProperties.hasNext()) {
OMElement property = (OMElement) jmsProperties.next();
String value = MiscellaneousUtil.resolve(property, secretResolver);
properties.put(property.getLocalName(), APIUtil.replaceSystemProperty(value));
}
jmsConnectionProperties.setJmsConnectionProperties(properties);
}
// Configuring JMS Task Manager
ThrottleProperties.JMSConnectionProperties.JMSTaskManagerProperties jmsTaskManagerProperties = new ThrottleProperties.JMSConnectionProperties.JMSTaskManagerProperties();
OMElement jmsTaskManagerElement = jmsConnectionDetailElement.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.JMS_TASK_MANAGER));
if (jmsTaskManagerElement != null) {
OMElement minThreadPoolSizeElement = jmsTaskManagerElement.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.MIN_THREAD_POOL_SIZE));
if (minThreadPoolSizeElement != null) {
jmsTaskManagerProperties.setMinThreadPoolSize(Integer.parseInt(minThreadPoolSizeElement.getText()));
}
OMElement maxThreadPoolSizeElement = jmsTaskManagerElement.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.MAX_THREAD_POOL_SIZE));
if (maxThreadPoolSizeElement != null) {
jmsTaskManagerProperties.setMaxThreadPoolSize(Integer.parseInt(maxThreadPoolSizeElement.getText()));
}
OMElement keepAliveTimeInMillisElement = jmsTaskManagerElement.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.KEEP_ALIVE_TIME_IN_MILLIS));
if (keepAliveTimeInMillisElement != null) {
jmsTaskManagerProperties.setKeepAliveTimeInMillis(Integer.parseInt(keepAliveTimeInMillisElement.getText()));
}
OMElement jobQueueSizeElement = jmsTaskManagerElement.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.JOB_QUEUE_SIZE));
if (keepAliveTimeInMillisElement != null) {
jmsTaskManagerProperties.setJobQueueSize(Integer.parseInt(jobQueueSizeElement.getText()));
}
}
jmsConnectionProperties.setJmsTaskManagerProperties(jmsTaskManagerProperties);
OMElement jmsConnectionInitialDelayElement = jmsConnectionDetailElement.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.BLOCK_CONDITION_RETRIEVER_INIT_DELAY));
if (jmsConnectionInitialDelayElement != null) {
jmsConnectionProperties.setInitialDelay(Long.parseLong(jmsConnectionInitialDelayElement.getText()));
}
}
throttleProperties.setJmsConnectionProperties(jmsConnectionProperties);
// Configuring default tier limits
Map<String, Long> defaultThrottleTierLimits = new HashMap<String, Long>();
OMElement defaultTierLimits = throttleConfigurationElement.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.DEFAULT_THROTTLE_LIMITS));
if (defaultTierLimits != null) {
OMElement subscriptionPolicyLimits = defaultTierLimits.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.SUBSCRIPTION_THROTTLE_LIMITS));
if (subscriptionPolicyLimits != null) {
OMElement goldTierElement = subscriptionPolicyLimits.getFirstChildWithName(new QName(APIConstants.DEFAULT_SUB_POLICY_GOLD));
if (goldTierElement != null) {
defaultThrottleTierLimits.put(APIConstants.DEFAULT_SUB_POLICY_GOLD, Long.parseLong(goldTierElement.getText()));
}
OMElement silverTierElement = subscriptionPolicyLimits.getFirstChildWithName(new QName(APIConstants.DEFAULT_SUB_POLICY_SILVER));
if (silverTierElement != null) {
defaultThrottleTierLimits.put(APIConstants.DEFAULT_SUB_POLICY_SILVER, Long.parseLong(silverTierElement.getText()));
}
OMElement bronzeTierElement = subscriptionPolicyLimits.getFirstChildWithName(new QName(APIConstants.DEFAULT_SUB_POLICY_BRONZE));
if (bronzeTierElement != null) {
defaultThrottleTierLimits.put(APIConstants.DEFAULT_SUB_POLICY_BRONZE, Long.parseLong(bronzeTierElement.getText()));
}
OMElement unauthenticatedTierElement = subscriptionPolicyLimits.getFirstChildWithName(new QName(APIConstants.DEFAULT_SUB_POLICY_UNAUTHENTICATED));
if (unauthenticatedTierElement != null) {
defaultThrottleTierLimits.put(APIConstants.DEFAULT_SUB_POLICY_UNAUTHENTICATED, Long.parseLong(unauthenticatedTierElement.getText()));
}
}
OMElement applicationPolicyLimits = defaultTierLimits.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.APPLICATION_THROTTLE_LIMITS));
if (subscriptionPolicyLimits != null) {
OMElement largeTierElement = applicationPolicyLimits.getFirstChildWithName(new QName(APIConstants.DEFAULT_APP_POLICY_FIFTY_REQ_PER_MIN));
if (largeTierElement != null) {
defaultThrottleTierLimits.put(APIConstants.DEFAULT_APP_POLICY_FIFTY_REQ_PER_MIN, Long.parseLong(largeTierElement.getText()));
}
OMElement mediumTierElement = applicationPolicyLimits.getFirstChildWithName(new QName(APIConstants.DEFAULT_APP_POLICY_TWENTY_REQ_PER_MIN));
if (mediumTierElement != null) {
defaultThrottleTierLimits.put(APIConstants.DEFAULT_APP_POLICY_TWENTY_REQ_PER_MIN, Long.parseLong(mediumTierElement.getText()));
}
OMElement smallTierElement = applicationPolicyLimits.getFirstChildWithName(new QName(APIConstants.DEFAULT_APP_POLICY_TEN_REQ_PER_MIN));
if (smallTierElement != null) {
defaultThrottleTierLimits.put(APIConstants.DEFAULT_APP_POLICY_TEN_REQ_PER_MIN, Long.parseLong(smallTierElement.getText()));
}
}
OMElement resourceLevelPolicyLimits = defaultTierLimits.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.RESOURCE_THROTTLE_LIMITS));
if (resourceLevelPolicyLimits != null) {
OMElement ultimateTierElement = resourceLevelPolicyLimits.getFirstChildWithName(new QName(APIConstants.DEFAULT_API_POLICY_FIFTY_THOUSAND_REQ_PER_MIN));
if (ultimateTierElement != null) {
defaultThrottleTierLimits.put(APIConstants.DEFAULT_API_POLICY_FIFTY_THOUSAND_REQ_PER_MIN, Long.parseLong(ultimateTierElement.getText()));
}
OMElement plusTierElement = resourceLevelPolicyLimits.getFirstChildWithName(new QName(APIConstants.DEFAULT_API_POLICY_TWENTY_THOUSAND_REQ_PER_MIN));
if (plusTierElement != null) {
defaultThrottleTierLimits.put(APIConstants.DEFAULT_API_POLICY_TWENTY_THOUSAND_REQ_PER_MIN, Long.parseLong(plusTierElement.getText()));
}
OMElement basicTierElement = resourceLevelPolicyLimits.getFirstChildWithName(new QName(APIConstants.DEFAULT_API_POLICY_TEN_THOUSAND_REQ_PER_MIN));
if (basicTierElement != null) {
defaultThrottleTierLimits.put(APIConstants.DEFAULT_API_POLICY_TEN_THOUSAND_REQ_PER_MIN, Long.parseLong(basicTierElement.getText()));
}
}
}
throttleProperties.setDefaultThrottleTierLimits(defaultThrottleTierLimits);
// Configuring policy deployer
OMElement policyDeployerConnectionElement = throttleConfigurationElement.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.POLICY_DEPLOYER_CONFIGURATION));
ThrottleProperties.PolicyDeployer policyDeployerConfiguration = new ThrottleProperties.PolicyDeployer();
if (policyDeployerConnectionElement != null) {
OMElement policyDeployerConnectionEnabledElement = policyDeployerConnectionElement.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.ENABLED));
policyDeployerConfiguration.setEnabled(JavaUtils.isTrueExplicitly(policyDeployerConnectionEnabledElement.getText()));
OMElement policyDeployerServiceUrlElement = policyDeployerConnectionElement.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.SERVICE_URL));
if (policyDeployerServiceUrlElement != null) {
policyDeployerConfiguration.setServiceUrl(APIUtil.replaceSystemProperty(policyDeployerServiceUrlElement.getText()));
}
OMElement policyDeployerServiceServiceUsernameElement = policyDeployerConnectionElement.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.USERNAME));
if (policyDeployerServiceServiceUsernameElement != null) {
policyDeployerConfiguration.setUsername(APIUtil.replaceSystemProperty(policyDeployerServiceServiceUsernameElement.getText()));
}
OMElement policyDeployerServicePasswordElement = policyDeployerConnectionElement.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.PASSWORD));
String policyDeployerServicePassword = MiscellaneousUtil.resolve(policyDeployerServicePasswordElement, secretResolver);
policyDeployerConfiguration.setPassword(APIUtil.replaceSystemProperty(policyDeployerServicePassword));
}
throttleProperties.setPolicyDeployer(policyDeployerConfiguration);
// Configuring Block Condition retriever configuration
OMElement blockConditionRetrieverElement = throttleConfigurationElement.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.BLOCK_CONDITION_RETRIEVER_CONFIGURATION));
ThrottleProperties.BlockCondition blockConditionRetrieverConfiguration = new ThrottleProperties.BlockCondition();
if (blockConditionRetrieverElement != null) {
OMElement blockingConditionEnabledElement = blockConditionRetrieverElement.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.ENABLED));
blockConditionRetrieverConfiguration.setEnabled(JavaUtils.isTrueExplicitly(blockingConditionEnabledElement.getText()));
OMElement blockConditionRetrieverServiceUrlElement = blockConditionRetrieverElement.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.SERVICE_URL));
if (blockConditionRetrieverServiceUrlElement != null) {
blockConditionRetrieverConfiguration.setServiceUrl(APIUtil.replaceSystemProperty(blockConditionRetrieverServiceUrlElement.getText()));
} else {
String serviceUrl = "https://" + System.getProperty(APIConstants.KEYMANAGER_HOSTNAME) + ":" + System.getProperty(APIConstants.KEYMANAGER_PORT) + APIConstants.INTERNAL_WEB_APP_EP;
blockConditionRetrieverConfiguration.setServiceUrl(serviceUrl);
}
blockConditionRetrieverConfiguration.setUsername(getFirstProperty(APIConstants.API_KEY_VALIDATOR_USERNAME));
OMElement blockConditionRetrieverThreadPoolSizeElement = blockConditionRetrieverElement.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.MAX_THREAD_POOL_SIZE));
if (blockConditionRetrieverThreadPoolSizeElement != null) {
blockConditionRetrieverConfiguration.setCorePoolSize(Integer.parseInt(blockConditionRetrieverThreadPoolSizeElement.getText()));
}
OMElement blockConditionRetrieverInitIdleElement = blockConditionRetrieverElement.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.BLOCK_CONDITION_RETRIEVER_INIT_DELAY));
if (blockConditionRetrieverInitIdleElement != null) {
blockConditionRetrieverConfiguration.setInitDelay(Long.parseLong(blockConditionRetrieverInitIdleElement.getText()));
}
OMElement blockConditionRetrieverTimeIntervalElement = blockConditionRetrieverElement.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.BLOCK_CONDITION_RETRIEVER_PERIOD));
if (blockConditionRetrieverTimeIntervalElement != null) {
blockConditionRetrieverConfiguration.setPeriod(Long.parseLong(blockConditionRetrieverTimeIntervalElement.getText()));
}
blockConditionRetrieverConfiguration.setPassword(getFirstProperty(APIConstants.API_KEY_VALIDATOR_PASSWORD));
}
throttleProperties.setBlockCondition(blockConditionRetrieverConfiguration);
}
}
use of org.wso2.carbon.identity.core.ServiceURL in project carbon-apimgt by wso2.
the class SubscriptionDataLoaderImpl method invokeService.
private String invokeService(String path, String tenantDomain) throws DataLoadingException, IOException {
String serviceURLStr = getEventHubConfigurationDto.getServiceUrl().concat(APIConstants.INTERNAL_WEB_APP_EP);
HttpGet method = new HttpGet(serviceURLStr + path);
URL serviceURL = new URL(serviceURLStr + path);
byte[] credentials = getServiceCredentials(getEventHubConfigurationDto);
int servicePort = serviceURL.getPort();
String serviceProtocol = serviceURL.getProtocol();
method.setHeader(APIConstants.AUTHORIZATION_HEADER_DEFAULT, APIConstants.AUTHORIZATION_BASIC + new String(credentials, StandardCharsets.UTF_8));
if (tenantDomain != null) {
method.setHeader(APIConstants.HEADER_TENANT, tenantDomain);
}
HttpClient httpClient = APIUtil.getHttpClient(servicePort, serviceProtocol);
HttpResponse httpResponse = null;
int retryCount = 0;
boolean retry = false;
do {
try {
httpResponse = httpClient.execute(method);
if (HttpStatus.SC_OK != httpResponse.getStatusLine().getStatusCode()) {
log.error("Could not retrieve subscriptions for tenantDomain: " + tenantDomain + ". Received response with status code " + httpResponse.getStatusLine().getStatusCode());
throw new DataLoadingException("Error while retrieving subscription");
}
retry = false;
} catch (IOException | DataLoadingException ex) {
retryCount++;
if (retryCount < retrievalRetries) {
retry = true;
log.warn("Failed retrieving " + path + " from remote endpoint: " + ex.getMessage() + ". Retrying after " + retrievalTimeoutInSeconds + " seconds.");
try {
Thread.sleep(retrievalTimeoutInSeconds * 1000);
} catch (InterruptedException e) {
// Ignore
}
} else {
throw ex;
}
}
} while (retry);
if (HttpStatus.SC_OK != httpResponse.getStatusLine().getStatusCode()) {
log.error("Could not retrieve subscriptions for tenantDomain : " + tenantDomain);
throw new DataLoadingException("Error while retrieving subscription from " + path);
}
String responseString = EntityUtils.toString(httpResponse.getEntity(), UTF8);
if (log.isDebugEnabled()) {
log.debug("Response : " + responseString);
}
return responseString;
}
Aggregations