首页 > 解决方案 > 如何在 Corda 社区版中使用数据源类型 DB 建立 rpc 属性?

问题描述

要在社区版中建立 RPC 连接,我们需要指定 rpc 用户名、密码和权限,但是当我们集成外部数据库(如 MySQL)并将数据源类型从 INMEMORY 更改为“DB”时,它不允许提供用户属性。

这些是我在 node.conf 中使用的设置

security = {
  authService = {
    dataSource = {
        type = "DB"
        passwordEncryption = "SHIRO_1_CRYPT"
        connection = {
            jdbcUrl = "jdbc:mysql://localhost:3306"
            username = "root"
            password = "password"
            driverClassName = "com.mysql.jdbc.Driver"
        }
    }
    options = {
        cache = {
            expireAfterSecs = 120
            maxEntries = 10000
        }
    }
}

标签: databaserpccorda

解决方案


也许我不明白你的问题,但是数据库设置node.conf与 RPC 用户设置是分开的node.conf
数据库(在我的例子中是 PostGres)

extraConfig = [
        'dataSourceProperties.dataSourceClassName' : 'org.postgresql.ds.PGSimpleDataSource',
        'dataSourceProperties.dataSource.url' : 'jdbc:postgresql://localhost:5432/postgres',
        'dataSourceProperties.dataSource.user' : 'db_user',
        'dataSourceProperties.dataSource.password' : 'db_user_password',
        'database.transactionIsolationLevel' : 'READ_COMMITTED',
        'database.initialiseSchema' : 'true'
]

RPC 用户

rpcUsers = [[ user: "rpc_user", "password": "rpc_user_password", "permissions": ["ALL"]]]

好的,我正在添加我的节点node.config(它是 Corda TestNet 的一部分,并且部署在 Google Cloud 上):

baseDirectory = "."
compatibilityZoneURL = "https://netmap.testnet.r3.com"
emailAddress = "xxx"
jarDirs = [ "plugins", "cordapps" ]
sshd { port = 2222 }
myLegalName = "OU=xxx, O=TESTNET_xxx, L=London, C=GB"
keyStorePassword = "xxx"
trustStorePassword = "xxx"
crlCheckSoftFail = true
database = {
    transactionIsolationLevel = "READ_COMMITTED"
    initialiseSchema = "true"
}
dataSourceProperties {
    dataSourceClassName = "org.postgresql.ds.PGSimpleDataSource"
    dataSource.url = "jdbc:postgresql://xxx:xxx/postgres"
    dataSource.user = xxx
    dataSource.password = xxx
}
p2pAddress = "xxx:xxx"
rpcSettings {
    useSsl = false
    standAloneBroker = false
    address = "0.0.0.0:xxx"
    adminAddress = "0.0.0.0:xxx"
}
rpcUsers = [
    { username=cordazoneservice, password=xxx, permissions=[ ALL ] }
]
devMode = false
cordappSignerKeyFingerprintBlacklist = []
useTestClock = false

推荐阅读