try {
AxisService service = axisConfig.getServiceForActivation(serviceName);
if (service == null) {
throw new SecurityConfigException("AxisService is Null");
}
// at registry
String servicePath = RegistryResources.SERVICE_GROUPS
+ service.getAxisServiceGroup().getServiceGroupName()
+ RegistryResources.SERVICES + serviceName;
String policyResourcePath = servicePath + RegistryResources.POLICIES;
log.debug("Removing " + policyResourcePath);
if (!registry.resourceExists(policyResourcePath)) {
return;
}
SecurityScenario scenario = readCurrentScenario(serviceName);
if (scenario == null) {
return;
}
String secPolicyPath = servicePath + RegistryResources.POLICIES + scenario.getWsuId();
if (registry.resourceExists(secPolicyPath)) {
registry.delete(secPolicyPath);
}
String[] moduleNames = scenario.getModules().toArray(
new String[scenario.getModules().size()]);
// disengage modules
for (String moduleName : moduleNames) {
AxisModule module = service.getAxisConfiguration().getModule(moduleName);
service.disengageModule(module);
String modPath = RegistryResources.MODULES + module.getName() + "/" + module.getVersion();
registry.removeAssociation(servicePath, modPath,
RegistryResources.Associations.ENGAGED_MODULES);
}
// remove poicy
SecurityServiceAdmin admin = new SecurityServiceAdmin(axisConfig, registry);
admin.removeSecurityPolicyFromAllBindings(service, scenario.getWsuId());
String scenarioId = scenario.getScenarioId();
String resourceUri = SecurityConstants.SECURITY_POLICY + "/" + scenarioId;
// unpersist data
try {
boolean transactionStarted = Transaction.isStarted();
if (!transactionStarted) {
registry.beginTransaction();
}
registry.removeAssociation(resourceUri, servicePath,
SecurityConstants.ASSOCIATION_SERVICE_SECURING_POLICY);
AuthorizationManager acAdmin = realm.getAuthorizationManager();
String[] roles = acAdmin.getAllowedRolesForResource(servicePath,
UserCoreConstants.INVOKE_SERVICE_PERMISSION);
for (int i = 0; i < roles.length; i++) {
acAdmin.clearRoleAuthorization(roles[i], servicePath,
UserCoreConstants.INVOKE_SERVICE_PERMISSION);
}
Association[] kss = registry.getAssociations(RegistryConstants.CONFIG_REGISTRY_BASE_PATH +
servicePath,
SecurityConstants.ASSOCIATION_PRIVATE_KEYSTORE);
for (int i = 0; i < kss.length; i++) {
registry.removeAssociation(RegistryConstants.CONFIG_REGISTRY_BASE_PATH + servicePath, kss[i].getDestinationPath(),
SecurityConstants.ASSOCIATION_PRIVATE_KEYSTORE);
}
Association[] tkss = registry.getAssociations(RegistryConstants.CONFIG_REGISTRY_BASE_PATH + servicePath,
SecurityConstants.ASSOCIATION_TRUSTED_KEYSTORE);
for (int i = 0; i < tkss.length; i++) {
registry.removeAssociation(RegistryConstants.CONFIG_REGISTRY_BASE_PATH +
servicePath, tkss[i].getDestinationPath(),
SecurityConstants.ASSOCIATION_TRUSTED_KEYSTORE);
}
// remove the policy path parameter if it is set..
String paramPath = servicePath + RegistryResources.PARAMETERS
+ SecurityConstants.SECURITY_POLICY_PATH;
if (registry.resourceExists(paramPath)) {
registry.delete(paramPath);
}
if (!transactionStarted) {
registry.commitTransaction();
}
} catch (RegistryException e) {
registry.rollbackTransaction();
String msg = "Unable to remove persisted data.";
log.error(msg);
throw new AxisFault(msg, e);
}
Parameter param = new Parameter();
param.setName(WSHandlerConstants.PW_CALLBACK_REF);
service.removeParameter(param);
Parameter param2 = new Parameter();
param2.setName("disableREST"); // TODO Find the constant
service.removeParameter(param2);
Parameter pathParam = service.getParameter(SecurityConstants.SECURITY_POLICY_PATH);
String policyPath = null;
if (pathParam != null) {
policyPath = (String) pathParam.getValue();
service.removeParameter(pathParam);
}
// unlock transports
Policy policy = this.loadPolicy(scenarioId, policyPath);
if (isHttpsTransportOnly(policy)) {
try {
boolean transactionStarted = Transaction.isStarted();
if (!transactionStarted) {
registry.beginTransaction();
}
Resource resource = registry.get(servicePath);
resource.removeProperty(RegistryResources.ServiceProperties.IS_UT_ENABLED);
List<String> transports = getAllTransports();
setServiceTransports(serviceName, transports);
// Fire the transport binding added event
AxisEvent event = new AxisEvent(CarbonConstants.AxisEvent.TRANSPORT_BINDING_ADDED,
service);
axisConfig.notifyObservers(event, service);
resource.setProperty(
RegistryResources.ServiceProperties.EXPOSED_ON_ALL_TANSPORTS,
Boolean.TRUE.toString());
for (String trans : transports) {
if (trans.endsWith("https")) {
continue;
}
String transPath = RegistryResources.TRANSPORTS + trans;
if (registry.resourceExists(transPath)) {
registry.addAssociation(servicePath, transPath,
RegistryResources.Associations.EXPOSED_TRANSPORTS);
} else {
String msg = "Transport path " + transPath + " does not exist in the registry";
log.error(msg);
throw new AxisFault(msg);
}
}
registry.put(resource.getPath(), resource);
if (!transactionStarted) {
registry.commitTransaction();
}
} catch (RegistryException e) {
registry.rollbackTransaction();
String msg = "Service with name " + serviceName + " not found.";
log.error(msg);
throw new AxisFault(msg, e);
}
}
} catch (AxisFault e) {
e.printStackTrace();
} catch (SecurityConfigException e) {
throw e;
} catch (Exception e) {
log.error(e);
throw new SecurityConfigException("removingPolicy", e);
}
}