in service/src/main/java/org/apache/fineract/cn/provisioner/internal/repository/ProvisionerInitializer.java [94:198]
private void initializeCassandra() throws Exception {
final Session session = this.cassandraSessionProvider.getAdminSession();
if (session.getCluster().getMetadata().getKeyspace(metaKeySpaceName).getTable(ConfigEntity.TABLE_NAME) == null) {
//create config family
final String createConfigTableStatement = SchemaBuilder.createTable(ConfigEntity.TABLE_NAME)
.addPartitionKey(ConfigEntity.NAME_COLUMN, DataType.text())
.addColumn(ConfigEntity.SECRET_COLUMN, DataType.blob())
.buildInternal();
session.execute(createConfigTableStatement);
final byte[] secret = this.saltGenerator.createRandomSalt();
final BoundStatement configBoundStatement = session.prepare("INSERT INTO config (name, secret) VALUES (?, ?)").bind();
configBoundStatement.setString("name", ProvisionerConstants.CONFIG_INTERNAL);
configBoundStatement.setBytes("secret", ByteBuffer.wrap(secret));
session.execute(configBoundStatement);
//create users family
final String createUsersTableStatement = SchemaBuilder.createTable(UserEntity.TABLE_NAME)
.addPartitionKey(UserEntity.NAME_COLUMN, DataType.text())
.addColumn(UserEntity.PASSWORD_COLUMN, DataType.blob())
.addColumn(UserEntity.SALT_COLUMN, DataType.blob())
.addColumn(UserEntity.ITERATION_COUNT_COLUMN, DataType.cint())
.addColumn(UserEntity.EXPIRES_IN_DAYS_COLUMN, DataType.cint())
.addColumn(UserEntity.PASSWORD_RESET_ON_COLUMN, DataType.timestamp())
.buildInternal();
session.execute(createUsersTableStatement);
final String username = ApiConstants.SYSTEM_SU;
final byte[] hashedPassword = Base64Utils.decodeFromString(ProvisionerConstants.INITIAL_PWD);
final byte[] variableSalt = this.saltGenerator.createRandomSalt();
final BoundStatement userBoundStatement =
session.prepare("INSERT INTO users (name, passwordWord, salt, iteration_count, password_reset_on) VALUES (?, ?, ?, ?, ?)").bind();
userBoundStatement.setString("name", username);
userBoundStatement.setBytes("passwordWord", ByteBuffer.wrap(
this.hashGenerator.hash(Base64Utils.encodeToString(hashedPassword), EncodingUtils.concatenate(variableSalt, secret),
ProvisionerConstants.ITERATION_COUNT, ProvisionerConstants.HASH_LENGTH)));
userBoundStatement.setBytes("salt", ByteBuffer.wrap(variableSalt));
userBoundStatement.setInt("iteration_count", ProvisionerConstants.ITERATION_COUNT);
userBoundStatement.setTimestamp("password_reset_on", new Date());
session.execute(userBoundStatement);
//create tenants family
final String createTenantsTableStatement = SchemaBuilder.createTable(TenantEntity.TABLE_NAME)
.addPartitionKey(TenantEntity.IDENTIFIER_COLUMN, DataType.text())
.addColumn(TenantEntity.CLUSTER_NAME_COLUMN, DataType.text())
.addColumn(TenantEntity.CONTACT_POINTS_COLUMN, DataType.text())
.addColumn(TenantEntity.KEYSPACE_NAME_COLUMN, DataType.text())
.addColumn(TenantEntity.REPLICATION_TYPE_COLUMN, DataType.text())
.addColumn(TenantEntity.REPLICAS_COLUMN, DataType.text())
.addColumn(TenantEntity.NAME_COLUMN, DataType.text())
.addColumn(TenantEntity.DESCRIPTION_COLUMN, DataType.text())
.addColumn(TenantEntity.IDENTITY_MANAGER_APPLICATION_NAME_COLUMN, DataType.text())
.addColumn(TenantEntity.IDENTITY_MANAGER_APPLICATION_URI_COLUMN, DataType.text())
.buildInternal();
session.execute(createTenantsTableStatement);
//create services family
final String createApplicationsTableStatement =
SchemaBuilder.createTable(ApplicationEntity.TABLE_NAME)
.addPartitionKey(ApplicationEntity.NAME_COLUMN, DataType.text())
.addColumn(ApplicationEntity.DESCRIPTION_COLUMN, DataType.text())
.addColumn(ApplicationEntity.VENDOR_COLUMN, DataType.text())
.addColumn(ApplicationEntity.HOMEPAGE_COLUMN, DataType.text())
.buildInternal();
session.execute(createApplicationsTableStatement);
//create org.apache.fineract.cn.provisioner.tenant services family
final String createTenantApplicationsTableStatement =
SchemaBuilder.createTable(TenantApplicationEntity.TABLE_NAME)
.addPartitionKey(TenantApplicationEntity.TENANT_IDENTIFIER_COLUMN, DataType.text())
.addColumn(TenantApplicationEntity.ASSIGNED_APPLICATIONS_COLUMN, DataType.set(DataType.text()))
.buildInternal();
session.execute(createTenantApplicationsTableStatement);
//create clients family
final String createClientsTableStatement =
SchemaBuilder.createTable(ClientEntity.TABLE_NAME)
.addPartitionKey(ClientEntity.NAME_COLUMN, DataType.text())
.addColumn(ClientEntity.DESCRIPTION_COLUMN, DataType.text())
.addColumn(ClientEntity.REDIRECT_URI_COLUMN, DataType.text())
.addColumn(ClientEntity.VENDOR_COLUMN, DataType.text())
.addColumn(ClientEntity.HOMEPAGE_COLUMN, DataType.text())
.buildInternal();
session.execute(createClientsTableStatement);
final String clientId = StringUtils.isEmpty(initialClientId) ? UUID.randomUUID().toString() : initialClientId;
this.logger.info(clientId);
final BoundStatement clientBoundStatement = session.prepare("INSERT INTO clients (name, description, vendor, homepage) VALUES (?, ?, ?, ?)").bind();
clientBoundStatement.setString("name", clientId);
clientBoundStatement.setString("description", "REST Console");
clientBoundStatement.setString("vendor", "The Apache Software Foundation");
clientBoundStatement.setString("homepage", "https://fineract.apache.org");
session.execute(clientBoundStatement);
}
}