Search in sources :

Example 1 with CasConfigurationModifiedEvent

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()));
    }
}
Also used : CasConfigurationModifiedEvent(org.apereo.cas.support.events.config.CasConfigurationModifiedEvent) PostMapping(org.springframework.web.bind.annotation.PostMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 2 with CasConfigurationModifiedEvent

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;
        }
    }
}
Also used : Path(java.nio.file.Path) CasConfigurationCreatedEvent(org.apereo.cas.support.events.config.CasConfigurationCreatedEvent) WatchKey(java.nio.file.WatchKey) CasConfigurationModifiedEvent(org.apereo.cas.support.events.config.CasConfigurationModifiedEvent) WatchEvent(java.nio.file.WatchEvent) CasConfigurationDeletedEvent(org.apereo.cas.support.events.config.CasConfigurationDeletedEvent)

Aggregations

CasConfigurationModifiedEvent (org.apereo.cas.support.events.config.CasConfigurationModifiedEvent)2 Path (java.nio.file.Path)1 WatchEvent (java.nio.file.WatchEvent)1 WatchKey (java.nio.file.WatchKey)1 CasConfigurationCreatedEvent (org.apereo.cas.support.events.config.CasConfigurationCreatedEvent)1 CasConfigurationDeletedEvent (org.apereo.cas.support.events.config.CasConfigurationDeletedEvent)1 PostMapping (org.springframework.web.bind.annotation.PostMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1