Skip to main content
1-Visitor
January 8, 2019
Solved

Set Things password from service

  • January 8, 2019
  • 1 reply
  • 2160 views

Hi,

 

i have many Things with "Database" as Thing Template and i would like to make a service which sets the password to the database automatically (on running the service). 

i looked into the snippets and found nothing so i thought it might be a security policy.

 

is it possible? Thanks 🙂

Best answer by CarlesColl

Hello,

 

Configuration section of a thing it's based on Configuration Tables, you should look on the services related to Configuration Tables in order to change any property shown on that section. Let's start:

 

  • GetConfigurationTables -->
    • ColumnAliases
    • ConnectionInfo
    • ConnectionMonitoring
  • From previous service we can infer that password will be on ConnectionInfo
  • GetConfigurationTable({ tableName: "ConnectionInfo"}) -> Infotable with the following columns
    • jDBCDriverClass, jDBCConnectionURL, connectionValidationString, MaxConnections, userName, password
  • Here we have the password value (but it's shown as ****), if you do it from a service you will see the real password (at least for TW 7.3.X )
  • Now you only need to Set the previous Configuration Table. the corresponding SetConfigurationTable or SetConfigurationTableRows in order to update the password accordingly.

Carles.

1 reply

1-Visitor
January 8, 2019

Hello,

 

Configuration section of a thing it's based on Configuration Tables, you should look on the services related to Configuration Tables in order to change any property shown on that section. Let's start:

 

  • GetConfigurationTables -->
    • ColumnAliases
    • ConnectionInfo
    • ConnectionMonitoring
  • From previous service we can infer that password will be on ConnectionInfo
  • GetConfigurationTable({ tableName: "ConnectionInfo"}) -> Infotable with the following columns
    • jDBCDriverClass, jDBCConnectionURL, connectionValidationString, MaxConnections, userName, password
  • Here we have the password value (but it's shown as ****), if you do it from a service you will see the real password (at least for TW 7.3.X )
  • Now you only need to Set the previous Configuration Table. the corresponding SetConfigurationTable or SetConfigurationTableRows in order to update the password accordingly.

Carles.

gabitudor1-VisitorAuthor
1-Visitor
January 10, 2019

Hi Charles,

 

thanks for the answer! I tried as you said but i am facing a problem.

 

// result: INFOTABLE dataShape: "EntityList"
var result = me.GetConfigurationTables();

// table: INFOTABLE dataShape: ""
var table = me.GetConfigurationTable({
tableName: "ConnectionInfo" /* STRING */
});

me.SetConfigurationTableRows({
values: undefined /* INFOTABLE */,
persistent: undefined /* BOOLEAN */,
tableName: undefined /* STRING */
});

 

Here, at SetConfigurationTableRows, what am i supposed to fill? i cannot see the connection to the password i would like to change. Thank you!

1-Visitor
January 10, 2019

Something like this should do the trick:

 

 

var newPassword ="newDesiredPassword";
var databaseName = "yourDataBaseName";
var tableName = "ConnectionInfo";
var actual = Things["PersistenceProviderSystemDatabase"].GetConfigurationTable({ tableName: tableName });
actual.rows[0].password = Resources["EncryptionServices"].EncryptPropertyValue({ data: newPassword });
Things[databaseName].SetConfigurationTable({
 configurationTable: tableName,
 persistent: true,
 tableName: tableName
});