use of org.wso2.carbon.identity.event.bean.Subscription in project product-microgateway by wso2.
the class AuthenticationFailureTestCase method testWithInvalidSubscription.
@Test(description = "Test with invalid subscription")
public void testWithInvalidSubscription() throws Exception {
Map<String, String> headers = new HashMap<>();
headers.put(HttpHeaderNames.AUTHORIZATION.toString(), "Bearer " + invalidSubscriptionToken);
HttpResponse response = HttpClientRequest.doGet(getServiceURLHttp("pizzashack/1.0.0/menu"), headers);
Assert.assertNotNull(response);
Assert.assertEquals(response.getResponseCode(), 403, "Response code mismatched");
Assert.assertTrue(response.getData().contains("Resource forbidden"));
}
use of org.wso2.carbon.identity.event.bean.Subscription in project product-microgateway by wso2.
the class ThrottlePolicyGenerator method generate.
/**
* Generate ballerina and stream source for a given app and subs policies.
*
* @param outPath Destination file path to save generated source files. If not provided
* {@code definitionPath} will be used as the default destination path
* @param projectName Project name
* @throws IOException when file operations fail
*/
public void generate(String outPath, String projectName) throws IOException {
ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
String policyFileLocation = CmdUtils.getProjectDirectoryPath(projectName) + File.separator + CliConstants.GW_DIST_POLICIES_FILE;
ThrottlePolicyListMapper throttlePolicyListMapper = mapper.readValue(new File(policyFileLocation), ThrottlePolicyListMapper.class);
// read application throttle policies and subscription throttle policies
List<ThrottlePolicyMapper> applicationPolicies = throttlePolicyListMapper.getApplicationPolicies();
List<ThrottlePolicyMapper> subscriptionPolicies = throttlePolicyListMapper.getSubscriptionPolicies();
List<ThrottlePolicyMapper> resourcePolicies = throttlePolicyListMapper.getResourcePolicies();
if (applicationPolicies == null && subscriptionPolicies == null && resourcePolicies == null) {
return;
}
checkDuplicatePolicyNames(applicationPolicies, subscriptionPolicies, resourcePolicies);
List<GenSrcFile> genFiles = new ArrayList<>();
GenSrcFile initGenFile = generateInitBal(applicationPolicies, subscriptionPolicies, resourcePolicies);
genFiles.add(initGenFile);
CodegenUtils.writeGeneratedSources(genFiles, Paths.get(outPath), true);
}
use of org.wso2.carbon.identity.event.bean.Subscription in project product-microgateway by wso2.
the class HashUtils method detectChanges.
/**
* Generate hashes for the specified apis, subscription and application policies, then compare with the previously
* generated hashes and detect if there are changes with them.
*
* @param apis APIs list
* @param subscriptionPolicies Subscription Policies list
* @param appPolicies Application policies list
* @param projectName Name of the project
* @return true if there are changes detected vs the previous check
* @throws HashingException error while change detection
*/
public static boolean detectChanges(List<ExtendedAPI> apis, List<SubscriptionThrottlePolicyDTO> subscriptionPolicies, List<ApplicationThrottlePolicyDTO> appPolicies, String projectName) throws HashingException {
boolean hasChanges = true;
Map<String, String> allHashesMap = new HashMap<>();
Map<String, String> apiHashesMap = getMapOfHashes(apis);
Map<String, String> appPolicyHashesMap = getMapOfHashes(appPolicies);
Map<String, String> subsPolicyHashesMap = getMapOfHashes(subscriptionPolicies);
logger.debug("API calculated hashes {}", apiHashesMap);
logger.debug("App policy calculated hashes {}", appPolicyHashesMap);
logger.debug("Subscription policy calculated hashes {}", subsPolicyHashesMap);
allHashesMap.putAll(apiHashesMap);
allHashesMap.putAll(appPolicyHashesMap);
allHashesMap.putAll(subsPolicyHashesMap);
try {
Map<String, String> storedHashes = loadStoredResourceHashes(projectName);
if (equalMaps(storedHashes, allHashesMap)) {
logger.debug("No changes detected after calculating hashes.");
hasChanges = false;
} else {
logger.debug("Storing calculated resource hashes.");
storeResourceHashes(allHashesMap, projectName);
logger.debug("Storing calculated resource hashes success.");
}
} catch (IOException e) {
throw new HashingException("Error while resource change detection", e);
}
return hasChanges;
}
use of org.wso2.carbon.identity.event.bean.Subscription in project carbon-identity-framework by wso2.
the class EventDistributionTask method run.
@Override
public void run() {
running = true;
// Run forever until stop the bundle. Will stop in eventQueue.take()
while (running) {
try {
final PublisherEvent event = eventQueue.take();
for (final NotificationSendingModule module : notificationSendingModules) {
// If the module is subscribed to the event, module will be executed.
try {
if (module.isSubscribed(event)) {
// Create a runnable and submit to the thread pool for sending message.
Runnable msgSender = new Runnable() {
@Override
public void run() {
if (log.isDebugEnabled()) {
log.debug("Executing " + module.getModuleName() + " on event" + event.getEventName());
}
try {
module.sendMessage(event);
} catch (NotificationManagementException e) {
log.error("Error while invoking notification sending module " + module.getModuleName(), e);
}
}
};
NotificationManagementServiceDataHolder.getInstance().getThreadPool().submit(msgSender);
}
} catch (NotificationManagementException e) {
log.error("Error while getting subscription status from notification module " + module.getModuleName(), e);
}
}
} catch (InterruptedException e) {
log.error("Error while picking up event from event queue", e);
}
}
}
use of org.wso2.carbon.identity.event.bean.Subscription in project carbon-identity-framework by wso2.
the class NotificationMgtConfigBuilder method buildModuleConfigurations.
/**
* Building per module configuration objects
*
* @param moduleName Name of the module
* @return ModuleConfiguration object which has configurations for the given module name
*/
private ModuleConfiguration buildModuleConfigurations(String moduleName) {
Properties moduleProperties = getModuleProperties(moduleName);
List<Subscription> subscriptionList = buildSubscriptionList(moduleName, moduleProperties);
return new ModuleConfiguration(getModuleProperties(moduleName), subscriptionList);
}
Aggregations