*
* @throws Exception
*/
private void loadSecurityScenarios() throws Exception {
Registry registry = registryService.getConfigSystemRegistry();
try {
// Scenarios are listed in resources/scenario-config.xml
URL resource = bundleContext.getBundle().getResource("scenario-config.xml");
XmlConfiguration xmlConfiguration = new XmlConfiguration(resource.openStream(),
SecurityConstants.SECURITY_NAMESPACE);
OMElement[] elements = xmlConfiguration.getElements("//ns:Scenario");
boolean transactionStarted = Transaction.isStarted();
if (!transactionStarted) {
registry.beginTransaction();
}
for (OMElement scenarioEle : elements) {
SecurityScenario scenario = new SecurityScenario();
String scenarioId = scenarioEle.getAttribute(SecurityConstants.ID_QN)
.getAttributeValue();
scenario.setScenarioId(scenarioId);
scenario.setSummary(scenarioEle.getFirstChildWithName(SecurityConstants.SUMMARY_QN)
.getText());
scenario.setDescription(scenarioEle.getFirstChildWithName(
SecurityConstants.DESCRIPTION_QN).getText());
scenario.setCategory(scenarioEle.getFirstChildWithName(SecurityConstants.CATEGORY_QN)
.getText());
scenario.setWsuId(scenarioEle.getFirstChildWithName(SecurityConstants.WSUID_QN)
.getText());
scenario.setType(scenarioEle.getFirstChildWithName(SecurityConstants.TYPE_QN).getText());
OMElement genPolicyElem = scenarioEle.getFirstChildWithName(SecurityConstants.IS_GEN_POLICY_QN);
if (genPolicyElem != null && genPolicyElem.getText().equals("false")) {
scenario.setGeneralPolicy(false);
}
String resourceUri = SecurityConstants.SECURITY_POLICY + "/" + scenarioId;
for (Iterator modules = scenarioEle.getFirstChildWithName(SecurityConstants.MODULES_QN)
.getChildElements(); modules.hasNext();) {
String module = ((OMElement) modules.next()).getText();
scenario.addModule(module);
}
// Save it in the DB
SecurityScenarioDatabase.put(scenarioId, scenario);
// Store the scenario in the Registry
if (!scenarioId.equals(SecurityConstants.SCENARIO_DISABLE_SECURITY) &&
!scenarioId.equals(SecurityConstants.POLICY_FROM_REG_SCENARIO)) {
Resource scenarioResource = new ResourceImpl();
scenarioResource.setContentStream(
bundleContext.getBundle().getResource(scenarioId + "-policy.xml").openStream());
if (!registry.resourceExists(resourceUri)) {
registry.put(resourceUri, scenarioResource);
}
}
}
if (!transactionStarted) {
registry.commitTransaction();
}
} catch (Exception e) {
registry.rollbackTransaction();
throw e;
}
}