Search in sources :

Example 1 with ClientCredentials

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;
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ClientCredentials(org.thingsboard.rule.engine.credentials.ClientCredentials) BasicCredentials(org.thingsboard.rule.engine.credentials.BasicCredentials)

Example 2 with ClientCredentials

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()));
    }
}
Also used : ClientCredentials(org.thingsboard.rule.engine.credentials.ClientCredentials)

Example 3 with ClientCredentials

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);
    }
}
Also used : CertPemCredentials(org.thingsboard.rule.engine.credentials.CertPemCredentials) TbMqttNodeConfiguration(org.thingsboard.rule.engine.mqtt.TbMqttNodeConfiguration) TbNodeException(org.thingsboard.rule.engine.api.TbNodeException) ClientCredentials(org.thingsboard.rule.engine.credentials.ClientCredentials) TbNodeException(org.thingsboard.rule.engine.api.TbNodeException) SSLException(javax.net.ssl.SSLException)

Example 4 with ClientCredentials

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());
    }
}
Also used : ClientCredentials(org.thingsboard.rule.engine.credentials.ClientCredentials) BasicCredentials(org.thingsboard.rule.engine.credentials.BasicCredentials)

Aggregations

ClientCredentials (org.thingsboard.rule.engine.credentials.ClientCredentials)4 BasicCredentials (org.thingsboard.rule.engine.credentials.BasicCredentials)2 SSLException (javax.net.ssl.SSLException)1 HttpHeaders (org.springframework.http.HttpHeaders)1 TbNodeException (org.thingsboard.rule.engine.api.TbNodeException)1 CertPemCredentials (org.thingsboard.rule.engine.credentials.CertPemCredentials)1 TbMqttNodeConfiguration (org.thingsboard.rule.engine.mqtt.TbMqttNodeConfiguration)1