Search in sources :

Example 1 with PERSISTENCE_TOPIC

use of org.openremote.container.persistence.PersistenceService.PERSISTENCE_TOPIC in project openremote by openremote.

the class MqttBrokerService method configure.

@SuppressWarnings("unchecked")
@Override
public void configure() throws Exception {
    from(PERSISTENCE_TOPIC).routeId("UserPersistenceChanges").filter(isPersistenceEventForEntityType(User.class)).process(exchange -> {
        PersistenceEvent<User> persistenceEvent = (PersistenceEvent<User>) exchange.getIn().getBody(PersistenceEvent.class);
        User user = persistenceEvent.getEntity();
        if (!user.isServiceAccount()) {
            return;
        }
        boolean forceDisconnect = persistenceEvent.getCause() == PersistenceEvent.Cause.DELETE;
        if (persistenceEvent.getCause() == PersistenceEvent.Cause.UPDATE) {
            // Force disconnect if certain properties have changed
            forceDisconnect = Arrays.stream(persistenceEvent.getPropertyNames()).anyMatch((propertyName) -> (propertyName.equals("enabled") && !user.getEnabled()) || propertyName.equals("username"));
        }
        if (forceDisconnect) {
            // Find existing connection for this user
            Arrays.stream(getConnections()).filter(connection -> user.getUsername().equals(connection.getUsername())).findFirst().ifPresent(connection -> {
                LOG.info("User modified or deleted so forcing connected client to disconnect: connection=" + connection);
                forceDisconnect(connection.getClientId());
            });
        }
    });
}
Also used : AssetStorageService(org.openremote.manager.asset.AssetStorageService) Tenant(org.openremote.model.security.Tenant) MqttMessageBuilders(io.netty.handler.codec.mqtt.MqttMessageBuilders) MqttQoS(io.netty.handler.codec.mqtt.MqttQoS) ManagerKeycloakIdentityProvider(org.openremote.manager.security.ManagerKeycloakIdentityProvider) java.util(java.util) MemoryConfig(io.moquette.broker.config.MemoryConfig) ValueUtil(org.openremote.model.util.ValueUtil) MapAccess.getInteger(org.openremote.container.util.MapAccess.getInteger) MapAccess.getString(org.openremote.container.util.MapAccess.getString) IAuthenticator(io.moquette.broker.security.IAuthenticator) Unpooled(io.netty.buffer.Unpooled) Level(java.util.logging.Level) ByteBuf(io.netty.buffer.ByteBuf) Charset(java.nio.charset.Charset) BrokerConstants(io.moquette.BrokerConstants) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) SyslogCategory(org.openremote.model.syslog.SyslogCategory) TextUtil(org.openremote.model.util.TextUtil) Method(java.lang.reflect.Method) PersistenceEvent(org.openremote.model.PersistenceEvent) MessageBrokerService(org.openremote.container.message.MessageBrokerService) User(org.openremote.model.security.User) MqttPublishMessage(io.netty.handler.codec.mqtt.MqttPublishMessage) ManagerIdentityService(org.openremote.manager.security.ManagerIdentityService) API(org.openremote.model.syslog.SyslogCategory.API) ContainerService(org.openremote.model.ContainerService) Field(java.lang.reflect.Field) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) InterceptHandler(io.moquette.interception.InterceptHandler) Container(org.openremote.model.Container) SessionRegistry(io.moquette.broker.SessionRegistry) ClientEventService(org.openremote.manager.event.ClientEventService) StreamSupport.stream(java.util.stream.StreamSupport.stream) Server(io.moquette.broker.Server) RouteBuilder(org.apache.camel.builder.RouteBuilder) TimerService(org.openremote.container.timer.TimerService) PERSISTENCE_TOPIC(org.openremote.container.persistence.PersistenceService.PERSISTENCE_TOPIC) PersistenceService.isPersistenceEventForEntityType(org.openremote.container.persistence.PersistenceService.isPersistenceEventForEntityType) User(org.openremote.model.security.User) PersistenceEvent(org.openremote.model.PersistenceEvent)

Aggregations

BrokerConstants (io.moquette.BrokerConstants)1 Server (io.moquette.broker.Server)1 SessionRegistry (io.moquette.broker.SessionRegistry)1 MemoryConfig (io.moquette.broker.config.MemoryConfig)1 IAuthenticator (io.moquette.broker.security.IAuthenticator)1 InterceptHandler (io.moquette.interception.InterceptHandler)1 ByteBuf (io.netty.buffer.ByteBuf)1 Unpooled (io.netty.buffer.Unpooled)1 MqttMessageBuilders (io.netty.handler.codec.mqtt.MqttMessageBuilders)1 MqttPublishMessage (io.netty.handler.codec.mqtt.MqttPublishMessage)1 MqttQoS (io.netty.handler.codec.mqtt.MqttQoS)1 Field (java.lang.reflect.Field)1 Method (java.lang.reflect.Method)1 Charset (java.nio.charset.Charset)1 StandardCharsets (java.nio.charset.StandardCharsets)1 java.util (java.util)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 Level (java.util.logging.Level)1 Logger (java.util.logging.Logger)1 Collectors (java.util.stream.Collectors)1