|
Before Width: | Height: | Size: 55 KiB After Width: | Height: | Size: 56 KiB |
|
Before Width: | Height: | Size: 55 KiB After Width: | Height: | Size: 56 KiB |
|
Before Width: | Height: | Size: 42 KiB After Width: | Height: | Size: 42 KiB |
|
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 14 KiB |
@ -1,74 +0,0 @@ |
|||
{ |
|||
"widgetsBundle": { |
|||
"alias": "scada_water_system_symbols", |
|||
"title": "SCADA water system symbols", |
|||
"scada": true, |
|||
"image": null, |
|||
"description": "Bundle with SCADA symbols for water system", |
|||
"order": 9300, |
|||
"name": "SCADA water system symbols" |
|||
}, |
|||
"widgetTypeFqns": [ |
|||
"horizontal_pipe", |
|||
"long_horizontal_pipe", |
|||
"vertical_pipe", |
|||
"long_vertical_pipe", |
|||
"left_bottom_elbow_pipe", |
|||
"bottom_right_elbow_pipe", |
|||
"top_right_elbow_pipe", |
|||
"left_top_elbow_pipe", |
|||
"cross_pipe", |
|||
"left_tee_pipe", |
|||
"bottom_tee_pipe", |
|||
"right_tee_pipe", |
|||
"top_tee_pipe", |
|||
"right_elbow_drain_pipe", |
|||
"left_elbow_drain_pipe", |
|||
"left_drain_pipe", |
|||
"right_drain_pipe", |
|||
"short_left_drain_pipe", |
|||
"short_right_drain_pipe", |
|||
"top_flow_meter", |
|||
"right_flow_meter", |
|||
"bottom_flow_meter", |
|||
"left_flow_meter", |
|||
"horizontal_inline_flow_meter", |
|||
"vertical_inline_flow_meter", |
|||
"left_analog_water_level_meter", |
|||
"right_analog_water_level_meter", |
|||
"leak_sensor", |
|||
"centrifugal_pump", |
|||
"small_right_motor_pump", |
|||
"small_left_motor_pump", |
|||
"right_motor_pump", |
|||
"left_motor_pump", |
|||
"right_heat_pump", |
|||
"left_heat_pump", |
|||
"short_bottom_filter", |
|||
"long_bottom_filter", |
|||
"short_top_filter", |
|||
"long_top_filter", |
|||
"stand_filter", |
|||
"horizontal_wheel_valve", |
|||
"vertical_wheel_valve", |
|||
"horizontal_ball_valve", |
|||
"vertical_ball_valve", |
|||
"water_stop", |
|||
"vertical_tank", |
|||
"stand_vertical_tank", |
|||
"cylindrical_tank", |
|||
"stand_cylindrical_tank", |
|||
"vertical_short_tank", |
|||
"stand_vertical_short_tank", |
|||
"large_cylindrical_tank", |
|||
"large_stand_cylindrical_tank", |
|||
"large_vertical_tank", |
|||
"large_stand_vertical_tank", |
|||
"horizontal_tank", |
|||
"stand_horizontal_tank", |
|||
"spherical_tank", |
|||
"small_spherical_tank", |
|||
"elevated_tank", |
|||
"pool" |
|||
] |
|||
} |
|||
@ -0,0 +1,26 @@ |
|||
/** |
|||
* Copyright © 2016-2024 The Thingsboard Authors |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
package org.thingsboard.server.cache; |
|||
|
|||
import java.io.Serializable; |
|||
|
|||
public interface VersionedCacheKey extends Serializable { |
|||
|
|||
default boolean isVersioned() { |
|||
return false; |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,19 @@ |
|||
/** |
|||
* Copyright © 2016-2024 The Thingsboard Authors |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
package org.thingsboard.server.common.data; |
|||
|
|||
public record UserActivationLink(String value, long ttlMs) { |
|||
} |
|||
@ -0,0 +1,128 @@ |
|||
/** |
|||
* Copyright © 2016-2024 The Thingsboard Authors |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
package org.thingsboard.server.queue.rabbitmq; |
|||
|
|||
import static org.assertj.core.api.Assertions.assertThat; |
|||
import static org.mockito.ArgumentMatchers.anyBoolean; |
|||
import static org.mockito.ArgumentMatchers.anyString; |
|||
import static org.mockito.Mockito.times; |
|||
import static org.mockito.Mockito.verify; |
|||
import static org.mockito.Mockito.when; |
|||
|
|||
import com.rabbitmq.client.Channel; |
|||
import com.rabbitmq.client.Connection; |
|||
import com.rabbitmq.client.ConnectionFactory; |
|||
import com.rabbitmq.client.GetResponse; |
|||
import java.nio.charset.StandardCharsets; |
|||
import java.util.Set; |
|||
import java.util.UUID; |
|||
import org.junit.jupiter.api.Test; |
|||
import org.junit.jupiter.api.extension.ExtendWith; |
|||
import org.mockito.Mock; |
|||
import org.mockito.junit.jupiter.MockitoExtension; |
|||
import org.thingsboard.server.common.msg.queue.TopicPartitionInfo; |
|||
import org.thingsboard.server.queue.TbQueueAdmin; |
|||
import org.thingsboard.server.queue.TbQueueMsgDecoder; |
|||
import org.thingsboard.server.queue.common.DefaultTbQueueMsg; |
|||
|
|||
@ExtendWith(MockitoExtension.class) |
|||
class TbRabbitMqConsumerTemplateTest { |
|||
|
|||
private static final String TOPIC = "some-topic"; |
|||
|
|||
@Mock |
|||
private TbQueueAdmin admin; |
|||
|
|||
@Mock |
|||
private ConnectionFactory connectionFactory; |
|||
|
|||
@Mock |
|||
private TbQueueMsgDecoder<DefaultTbQueueMsg> decoder; |
|||
|
|||
@Mock |
|||
private Connection connection; |
|||
|
|||
@Mock |
|||
private Channel channel; |
|||
|
|||
@Mock |
|||
private TopicPartitionInfo partition; |
|||
|
|||
@Mock |
|||
private GetResponse getResponse; |
|||
|
|||
private TbRabbitMqConsumerTemplate<DefaultTbQueueMsg> consumer; |
|||
|
|||
private void setUpConsumerWithMaxPollMessages(int maxPollMessages) throws Exception { |
|||
when(connectionFactory.newConnection()).thenReturn(connection); |
|||
when(connection.createChannel()).thenReturn(channel); |
|||
TbRabbitMqSettings settings = new TbRabbitMqSettings(); |
|||
settings.setMaxPollMessages(maxPollMessages); |
|||
settings.setConnectionFactory(connectionFactory); |
|||
|
|||
consumer = new TbRabbitMqConsumerTemplate<>(admin, settings, TOPIC, decoder); |
|||
when(partition.getFullTopicName()).thenReturn(TOPIC); |
|||
consumer.subscribe(Set.of(partition)); |
|||
} |
|||
|
|||
@Test |
|||
void pollWithMax5PollMessagesReturnsEmptyListIfNoMessages() throws Exception { |
|||
setUpConsumerWithMaxPollMessages(5); |
|||
when(channel.basicGet(anyString(), anyBoolean())).thenReturn(null); |
|||
|
|||
assertThat(consumer.poll(0L)).isEmpty(); |
|||
|
|||
verify(channel).basicGet(anyString(), anyBoolean()); |
|||
} |
|||
|
|||
@Test |
|||
void pollWithMax5PollMessagesReturns5MessagesIfQueueContains5() throws Exception { |
|||
setUpConsumerWithMaxPollMessages(5); |
|||
when(getResponse.getBody()).thenReturn(newMessageBody()); |
|||
when(channel.basicGet(anyString(), anyBoolean())).thenReturn(getResponse); |
|||
|
|||
assertThat(consumer.poll(0L)).hasSize(5); |
|||
|
|||
verify(channel, times(5)).basicGet(anyString(), anyBoolean()); |
|||
} |
|||
|
|||
@Test |
|||
void pollWithMax1PollMessageReturns1MessageIfQueueContainsMore() throws Exception { |
|||
setUpConsumerWithMaxPollMessages(1); |
|||
when(getResponse.getBody()).thenReturn(newMessageBody()); |
|||
when(channel.basicGet(anyString(), anyBoolean())).thenReturn(getResponse); |
|||
|
|||
assertThat(consumer.poll(0L)).hasSize(1); |
|||
|
|||
verify(channel).basicGet(anyString(), anyBoolean()); |
|||
} |
|||
|
|||
@Test |
|||
void pollWithMax3PollMessagesReturns2MessagesIfQueueContains2() throws Exception { |
|||
setUpConsumerWithMaxPollMessages(3); |
|||
when(getResponse.getBody()).thenReturn(newMessageBody()); |
|||
when(channel.basicGet(anyString(), anyBoolean())).thenReturn(getResponse, getResponse, null); |
|||
|
|||
assertThat(consumer.poll(0L)).hasSize(2); |
|||
|
|||
verify(channel, times(3)).basicGet(anyString(), anyBoolean()); |
|||
} |
|||
|
|||
private byte[] newMessageBody() { |
|||
return ("{\"key\": \"" + UUID.randomUUID() + "\"}").getBytes(StandardCharsets.UTF_8); |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,95 @@ |
|||
/** |
|||
* Copyright © 2016-2024 The Thingsboard Authors |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
package org.thingsboard.server.queue.scheduler; |
|||
|
|||
import org.awaitility.Awaitility; |
|||
import org.junit.jupiter.api.AfterEach; |
|||
import org.junit.jupiter.api.BeforeEach; |
|||
import org.junit.jupiter.api.DisplayName; |
|||
import org.junit.jupiter.api.Test; |
|||
|
|||
import java.util.concurrent.ScheduledFuture; |
|||
import java.util.concurrent.TimeUnit; |
|||
import java.util.concurrent.atomic.AtomicBoolean; |
|||
|
|||
import static org.assertj.core.api.Assertions.assertThat; |
|||
|
|||
class DefaultSchedulerComponentTest { |
|||
|
|||
DefaultSchedulerComponent schedulerComponent; |
|||
|
|||
@BeforeEach |
|||
void setup() { |
|||
schedulerComponent = new DefaultSchedulerComponent(); |
|||
schedulerComponent.init(); |
|||
} |
|||
|
|||
@AfterEach |
|||
void cleanup() { |
|||
schedulerComponent.destroy(); |
|||
} |
|||
|
|||
@Test |
|||
@DisplayName("scheduleAtFixedRate() should continue periodic execution even if command throws exception") |
|||
void scheduleAtFixedRateShouldNotStopPeriodicExecutionWhenCommandThrowsException() { |
|||
// GIVEN
|
|||
var wasExecutedAtLeastOnce = new AtomicBoolean(false); |
|||
|
|||
Runnable exceptionThrowingCommand = () -> { |
|||
try { |
|||
throw new RuntimeException("Unexpected exception"); |
|||
} finally { |
|||
wasExecutedAtLeastOnce.set(true); |
|||
} |
|||
}; |
|||
|
|||
// WHEN
|
|||
ScheduledFuture<?> future = schedulerComponent.scheduleAtFixedRate(exceptionThrowingCommand, 0, 200, TimeUnit.MILLISECONDS); |
|||
|
|||
// THEN
|
|||
Awaitility.await().alias("Wait until command is executed at least once") |
|||
.atMost(5, TimeUnit.SECONDS) |
|||
.until(wasExecutedAtLeastOnce::get); |
|||
|
|||
assertThat(future.isDone()).as("Periodic execution should not stop after unhandled exception is thrown by the command").isFalse(); |
|||
} |
|||
|
|||
@Test |
|||
@DisplayName("scheduleWithFixedDelay() should continue periodic execution even if command throws exception") |
|||
void scheduleWithFixedDelayShouldNotStopPeriodicExecutionWhenCommandThrowsException() { |
|||
// GIVEN
|
|||
var wasExecutedAtLeastOnce = new AtomicBoolean(false); |
|||
|
|||
Runnable exceptionThrowingCommand = () -> { |
|||
try { |
|||
throw new RuntimeException("Unexpected exception"); |
|||
} finally { |
|||
wasExecutedAtLeastOnce.set(true); |
|||
} |
|||
}; |
|||
|
|||
// WHEN
|
|||
ScheduledFuture<?> future = schedulerComponent.scheduleWithFixedDelay(exceptionThrowingCommand, 0, 200, TimeUnit.MILLISECONDS); |
|||
|
|||
// THEN
|
|||
Awaitility.await().alias("Wait until command is executed at least once") |
|||
.atMost(5, TimeUnit.SECONDS) |
|||
.until(wasExecutedAtLeastOnce::get); |
|||
|
|||
assertThat(future.isDone()).as("Periodic execution should not stop after unhandled exception is thrown by the command").isFalse(); |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,81 @@ |
|||
/** |
|||
* Copyright © 2016-2024 The Thingsboard Authors |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
package org.thingsboard.server.dao.settings; |
|||
|
|||
import lombok.RequiredArgsConstructor; |
|||
import org.springframework.cache.annotation.CacheEvict; |
|||
import org.springframework.cache.annotation.Cacheable; |
|||
import org.springframework.stereotype.Service; |
|||
import org.thingsboard.common.util.JacksonUtil; |
|||
import org.thingsboard.server.common.data.AdminSettings; |
|||
import org.thingsboard.server.common.data.id.TenantId; |
|||
import org.thingsboard.server.common.data.security.model.SecuritySettings; |
|||
import org.thingsboard.server.common.data.security.model.UserPasswordPolicy; |
|||
import org.thingsboard.server.dao.service.ConstraintValidator; |
|||
|
|||
import static org.thingsboard.server.common.data.CacheConstants.SECURITY_SETTINGS_CACHE; |
|||
|
|||
@Service |
|||
@RequiredArgsConstructor |
|||
public class DefaultSecuritySettingsService implements SecuritySettingsService { |
|||
|
|||
private final AdminSettingsService adminSettingsService; |
|||
|
|||
public static final int DEFAULT_MOBILE_SECRET_KEY_LENGTH = 64; |
|||
|
|||
@Cacheable(cacheNames = SECURITY_SETTINGS_CACHE, key = "'securitySettings'") |
|||
@Override |
|||
public SecuritySettings getSecuritySettings() { |
|||
AdminSettings adminSettings = adminSettingsService.findAdminSettingsByKey(TenantId.SYS_TENANT_ID, "securitySettings"); |
|||
SecuritySettings securitySettings; |
|||
if (adminSettings != null) { |
|||
try { |
|||
securitySettings = JacksonUtil.convertValue(adminSettings.getJsonValue(), SecuritySettings.class); |
|||
} catch (Exception e) { |
|||
throw new RuntimeException("Failed to load security settings!", e); |
|||
} |
|||
} else { |
|||
securitySettings = new SecuritySettings(); |
|||
securitySettings.setPasswordPolicy(new UserPasswordPolicy()); |
|||
securitySettings.getPasswordPolicy().setMinimumLength(6); |
|||
securitySettings.getPasswordPolicy().setMaximumLength(72); |
|||
securitySettings.setMobileSecretKeyLength(DEFAULT_MOBILE_SECRET_KEY_LENGTH); |
|||
securitySettings.setPasswordResetTokenTtl(24); |
|||
securitySettings.setUserActivationTokenTtl(24); |
|||
} |
|||
return securitySettings; |
|||
} |
|||
|
|||
@CacheEvict(cacheNames = SECURITY_SETTINGS_CACHE, key = "'securitySettings'") |
|||
@Override |
|||
public SecuritySettings saveSecuritySettings(SecuritySettings securitySettings) { |
|||
ConstraintValidator.validateFields(securitySettings); |
|||
AdminSettings adminSettings = adminSettingsService.findAdminSettingsByKey(TenantId.SYS_TENANT_ID, "securitySettings"); |
|||
if (adminSettings == null) { |
|||
adminSettings = new AdminSettings(); |
|||
adminSettings.setTenantId(TenantId.SYS_TENANT_ID); |
|||
adminSettings.setKey("securitySettings"); |
|||
} |
|||
adminSettings.setJsonValue(JacksonUtil.valueToTree(securitySettings)); |
|||
AdminSettings savedAdminSettings = adminSettingsService.saveAdminSettings(TenantId.SYS_TENANT_ID, adminSettings); |
|||
try { |
|||
return JacksonUtil.convertValue(savedAdminSettings.getJsonValue(), SecuritySettings.class); |
|||
} catch (Exception e) { |
|||
throw new RuntimeException("Failed to load security settings!", e); |
|||
} |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,26 @@ |
|||
/** |
|||
* Copyright © 2016-2024 The Thingsboard Authors |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
package org.thingsboard.server.dao.settings; |
|||
|
|||
import org.thingsboard.server.common.data.security.model.SecuritySettings; |
|||
|
|||
public interface SecuritySettingsService { |
|||
|
|||
SecuritySettings getSecuritySettings(); |
|||
|
|||
SecuritySettings saveSecuritySettings(SecuritySettings securitySettings); |
|||
|
|||
} |
|||