use of org.apereo.cas.support.events.config.CasConfigurationModifiedEvent in project cas by apereo.
the class ConfigurationStateController method updateConfiguration.
/**
* Update configuration map.
*
* @param jsonInput the json input
* @param request the request
* @param response the response
*/
@PostMapping("/updateConfiguration")
@ResponseBody
public void updateConfiguration(@RequestBody final Map<String, Map<String, String>> jsonInput, final HttpServletRequest request, final HttpServletResponse response) {
ensureEndpointAccessIsAuthorized(request, response);
if (isUpdateEnabled()) {
final Map<String, String> newData = jsonInput.get("new");
configurationPropertiesEnvironmentManager.savePropertyForStandaloneProfile(Pair.of(newData.get("key"), newData.get("value")));
eventPublisher.publishEvent(new CasConfigurationModifiedEvent(this, !casProperties.getEvents().isTrackConfigurationModifications()));
}
}
use of org.apereo.cas.support.events.config.CasConfigurationModifiedEvent in project cas by apereo.
the class ConfigurationDirectoryPathWatchService method watch.
/**
* Watch the directory for changes.
*/
public void watch() {
long lastModified = System.currentTimeMillis();
while (true) {
final WatchKey key;
try {
key = watcher.take();
} catch (final InterruptedException e) {
LOGGER.warn(e.getMessage(), e);
return;
}
for (final WatchEvent<?> event : key.pollEvents()) {
final WatchEvent.Kind<?> kind = event.kind();
if (kind == OVERFLOW) {
LOGGER.warn("An overflow event occurred. File system events may be lost or discarded.");
continue;
}
final WatchEvent<Path> ev = (WatchEvent<Path>) event;
final Path filename = ev.context();
try {
final Path child = this.directory.resolve(filename);
if (System.currentTimeMillis() - lastModified >= MONITOR_INTERVAL) {
LOGGER.debug("Detected configuration change [{}]", kind.name());
if (StringUtils.equalsIgnoreCase(StandardWatchEventKinds.ENTRY_CREATE.name(), kind.name())) {
this.eventPublisher.publishEvent(new CasConfigurationCreatedEvent(this, child));
}
if (StringUtils.equalsIgnoreCase(StandardWatchEventKinds.ENTRY_DELETE.name(), kind.name())) {
this.eventPublisher.publishEvent(new CasConfigurationDeletedEvent(this, child));
}
if (StringUtils.equalsIgnoreCase(StandardWatchEventKinds.ENTRY_MODIFY.name(), kind.name())) {
this.eventPublisher.publishEvent(new CasConfigurationModifiedEvent(this, child));
}
lastModified = System.currentTimeMillis();
}
} catch (final Exception e) {
LOGGER.warn(e.getMessage(), e);
continue;
}
}
final boolean valid = key.reset();
if (!valid) {
break;
}
}
}
Aggregations