Search in sources :

Example 1 with BasicCredentials

use of org.thingsboard.rule.engine.credentials.BasicCredentials 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 BasicCredentials

use of org.thingsboard.rule.engine.credentials.BasicCredentials 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

BasicCredentials (org.thingsboard.rule.engine.credentials.BasicCredentials)2 ClientCredentials (org.thingsboard.rule.engine.credentials.ClientCredentials)2 HttpHeaders (org.springframework.http.HttpHeaders)1