if (wafId == null) {
log.warn("Received incomplete REST request to add a WAF");
return failure(WAF_LOOKUP_FAILED);
}
Application application = applicationService.loadApplication(appId);
Waf waf = wafService.loadWaf(wafId);
if (application == null) {
log.warn(APPLICATION_LOOKUP_FAILED);
return failure(APPLICATION_LOOKUP_FAILED);
} else if (waf == null) {
log.warn(WAF_LOOKUP_FAILED);
return failure(WAF_LOOKUP_FAILED);
} else {
// Delete WAF rules if the WAF has changed
Integer oldWafId = null;
if (application.getWaf() != null && application.getWaf().getId() != null) {
oldWafId = application.getWaf().getId();
}
application.setWaf(waf);
applicationService.updateWafRules(application, oldWafId);
applicationService.storeApplication(application);
return writeSuccessObjectWithView(application, AllViews.RestViewApplication2_1.class);
}
}