use of org.thingsboard.rule.engine.credentials.ClientCredentials in project thingsboard by thingsboard.
the class TbHttpClient method prepareHeaders.
private HttpHeaders prepareHeaders(TbMsg msg) {
HttpHeaders headers = new HttpHeaders();
config.getHeaders().forEach((k, v) -> headers.add(TbNodeUtils.processPattern(k, msg), TbNodeUtils.processPattern(v, msg)));
ClientCredentials credentials = config.getCredentials();
if (CredentialsType.BASIC == credentials.getType()) {
BasicCredentials basicCredentials = (BasicCredentials) credentials;
String authString = basicCredentials.getUsername() + ":" + basicCredentials.getPassword();
String encodedAuthString = new String(Base64.encodeBase64(authString.getBytes(StandardCharsets.UTF_8)));
headers.add("Authorization", "Basic " + encodedAuthString);
}
return headers;
}
use of org.thingsboard.rule.engine.credentials.ClientCredentials in project thingsboard by thingsboard.
the class TbAzureIotHubNode method prepareMqttClientConfig.
protected void prepareMqttClientConfig(MqttClientConfig config) throws SSLException {
config.setProtocolVersion(MqttVersion.MQTT_3_1_1);
config.setUsername(AzureIotHubUtil.buildUsername(mqttNodeConfiguration.getHost(), config.getClientId()));
ClientCredentials credentials = mqttNodeConfiguration.getCredentials();
if (CredentialsType.SAS == credentials.getType()) {
config.setPassword(AzureIotHubUtil.buildSasToken(mqttNodeConfiguration.getHost(), ((AzureIotHubSasCredentials) credentials).getSasKey()));
}
}
use of org.thingsboard.rule.engine.credentials.ClientCredentials in project thingsboard by thingsboard.
the class TbAzureIotHubNode method init.
@Override
public void init(TbContext ctx, TbNodeConfiguration configuration) throws TbNodeException {
try {
this.mqttNodeConfiguration = TbNodeUtils.convert(configuration, TbMqttNodeConfiguration.class);
mqttNodeConfiguration.setPort(8883);
mqttNodeConfiguration.setCleanSession(true);
ClientCredentials credentials = mqttNodeConfiguration.getCredentials();
if (CredentialsType.CERT_PEM == credentials.getType()) {
CertPemCredentials pemCredentials = (CertPemCredentials) credentials;
if (pemCredentials.getCaCert() == null || pemCredentials.getCaCert().isEmpty()) {
pemCredentials.setCaCert(AzureIotHubUtil.getDefaultCaCert());
}
}
this.mqttClient = initClient(ctx);
} catch (Exception e) {
throw new TbNodeException(e);
}
}
use of org.thingsboard.rule.engine.credentials.ClientCredentials in project thingsboard by thingsboard.
the class TbMqttNode method prepareMqttClientConfig.
protected void prepareMqttClientConfig(MqttClientConfig config) throws SSLException {
ClientCredentials credentials = this.mqttNodeConfiguration.getCredentials();
if (credentials.getType() == CredentialsType.BASIC) {
BasicCredentials basicCredentials = (BasicCredentials) credentials;
config.setUsername(basicCredentials.getUsername());
config.setPassword(basicCredentials.getPassword());
}
}
Aggregations