Skip to content

Commit

Permalink
Fix #141: User Data Store (for Liveness) (#154)
Browse files Browse the repository at this point in the history
  • Loading branch information
romanstrobl authored Jun 13, 2024
1 parent b3de958 commit 245b171
Show file tree
Hide file tree
Showing 82 changed files with 5,124 additions and 356 deletions.
2 changes: 1 addition & 1 deletion .run/UserDataStoreApplication.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<envs>
<env name="USER_DATA_STORE_DATASOURCE_URL" value="jdbc:postgresql://localhost:5432/powerauth" />
</envs>
<module name="user-data-store" />
<module name="user-data-store-server" />
<option name="SPRING_BOOT_MAIN_CLASS" value="com.wultra.security.userdatastore.UserDataStoreApplication" />
<option name="VM_PARAMETERS" value="-Dserver.port=8091" />
<method v="2">
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ RUN apt-get -y update \
COPY docs/db/changelog $LB_HOME/db/changelog

# Deploy and run applications
COPY target/user-data-store.war user-data-store.war
COPY user-data-store-server/target/user-data-store-server.war user-data-store-server.war

# Docker configuration
EXPOSE 8080
Expand Down
2 changes: 1 addition & 1 deletion deploy/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ liquibase --headless=true --log-level=INFO --changeLogFile=$LB_HOME/db/changelog
--url=$USER_DATA_STORE_DATASOURCE_URL \
update

java -jar user-data-store.war
java -jar user-data-store-server.war
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.9.xsd">

<changeSet id="1" author="Roman Strobl">
<preConditions onFail="MARK_RAN">
<not>
<tableExists tableName="uds_document"/>
</not>
</preConditions>
<createTable tableName="uds_document">
<column name="id" type="VARCHAR(36)">
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="user_id" type="VARCHAR(255)">
<constraints nullable="false"/>
</column>
<column name="document_type" type="VARCHAR(32)">
<constraints nullable="false"/>
</column>
<column name="data_type" type="VARCHAR(32)">
<constraints nullable="false"/>
</column>
<column name="document_data_id" type="VARCHAR(255)"/>
<column name="external_id" type="VARCHAR(255)"/>
<column name="document_data" type="TEXT">
<constraints nullable="false"/>
</column>
<column name="attributes" type="TEXT">
<constraints nullable="false"/>
</column>
<column name="encryption_mode" type="VARCHAR(255)" defaultValue="NO_ENCRYPTION">
<constraints nullable="false"/>
</column>
<column name="timestamp_created" type="TIMESTAMP WITHOUT TIME ZONE" defaultValueComputed="NOW()"/>
<column name="timestamp_last_updated" type="TIMESTAMP WITHOUT TIME ZONE"/>
</createTable>
</changeSet>

<changeSet id="2" author="Roman Strobl">
<preConditions onFail="MARK_RAN">
<not>
<tableExists tableName="uds_document_history"/>
</not>
</preConditions>
<createTable tableName="uds_document_history">
<column name="id" type="VARCHAR(36)">
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="document_id" type="VARCHAR(36)">
<constraints nullable="false"/>
</column>
<column name="user_id" type="VARCHAR(255)">
<constraints nullable="false"/>
</column>
<column name="document_type" type="VARCHAR(32)">
<constraints nullable="false"/>
</column>
<column name="data_type" type="VARCHAR(32)">
<constraints nullable="false"/>
</column>
<column name="document_data_id" type="VARCHAR(255)"/>
<column name="external_id" type="VARCHAR(255)"/>
<column name="document_data" type="TEXT">
<constraints nullable="false"/>
</column>
<column name="attributes" type="TEXT">
<constraints nullable="false"/>
</column>
<column name="encryption_mode" type="VARCHAR(255)" defaultValue="NO_ENCRYPTION">
<constraints nullable="false"/>
</column>
<column name="timestamp_created" type="TIMESTAMP WITHOUT TIME ZONE" defaultValueComputed="NOW()"/>
</createTable>
</changeSet>

<changeSet id="3" author="Roman Strobl">
<preConditions onFail="MARK_RAN">
<not>
<tableExists tableName="uds_photo"/>
</not>
</preConditions>
<createTable tableName="uds_photo">
<column name="id" type="VARCHAR(36)">
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="user_id" type="VARCHAR(255)">
<constraints nullable="false"/>
</column>
<column name="document_id" type="VARCHAR(255)">
<constraints nullable="false"/>
</column>
<column name="external_id" type="VARCHAR(255)"/>
<column name="photo_type" type="VARCHAR(32)">
<constraints nullable="false"/>
</column>
<column name="photo_data" type="TEXT">
<constraints nullable="false"/>
</column>
<column name="encryption_mode" type="VARCHAR(255)" defaultValue="NO_ENCRYPTION">
<constraints nullable="false"/>
</column>
<column name="timestamp_created" type="TIMESTAMP WITHOUT TIME ZONE" defaultValueComputed="NOW()"/>
<column name="timestamp_last_updated" type="TIMESTAMP WITHOUT TIME ZONE"/>
</createTable>
</changeSet>

<changeSet id="4" author="Roman Strobl">
<preConditions onFail="MARK_RAN">
<not>
<foreignKeyConstraintExists foreignKeyName="fk_uds_photo_document_id" />
</not>
</preConditions>
<addForeignKeyConstraint
baseTableName="uds_photo"
baseColumnNames="document_id"
constraintName="fk_uds_photo_document_id"
referencedTableName="uds_document"
referencedColumnNames="id"/>
</changeSet>

<changeSet id="5" author="Roman Strobl">
<preConditions onFail="MARK_RAN">
<not>
<tableExists tableName="uds_attachment"/>
</not>
</preConditions>
<createTable tableName="uds_attachment">
<column name="id" type="VARCHAR(36)">
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="user_id" type="VARCHAR(255)">
<constraints nullable="false"/>
</column>
<column name="document_id" type="VARCHAR(255)">
<constraints nullable="false"/>
</column>
<column name="external_id" type="VARCHAR(255)"/>
<column name="attachment_type" type="VARCHAR(32)">
<constraints nullable="false"/>
</column>
<column name="attachment_data" type="TEXT">
<constraints nullable="false"/>
</column>
<column name="encryption_mode" type="VARCHAR(255)" defaultValue="NO_ENCRYPTION">
<constraints nullable="false"/>
</column>
<column name="timestamp_created" type="TIMESTAMP WITHOUT TIME ZONE" defaultValueComputed="NOW()"/>
<column name="timestamp_last_updated" type="TIMESTAMP WITHOUT TIME ZONE"/>
</createTable>
</changeSet>

<changeSet id="6" author="Roman Strobl">
<preConditions onFail="MARK_RAN">
<not>
<foreignKeyConstraintExists foreignKeyName="fk_uds_attachment_document_id" />
</not>
</preConditions>
<addForeignKeyConstraint
baseTableName="uds_attachment"
baseColumnNames="document_id"
constraintName="fk_uds_attachment_document_id"
referencedTableName="uds_document"
referencedColumnNames="id"/>
</changeSet>

</databaseChangeLog>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.9.xsd">

<include file="20240514-refactor-uds-1.3.0.xml" relativeToChangelogFile="true" />

</databaseChangeLog>
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@

<include file="0.1.x/db.changelog-version.xml" relativeToChangelogFile="true" />
<include file="1.0.x/db.changelog-version.xml" relativeToChangelogFile="true" />
<include file="1.3.x/db.changelog-version.xml" relativeToChangelogFile="true" />

</databaseChangeLog>
139 changes: 78 additions & 61 deletions docs/sql/postgresql/create-schema.sql
Original file line number Diff line number Diff line change
@@ -1,61 +1,78 @@
CREATE TABLE uds_user_claims
(
user_id VARCHAR(255) NOT NULL,
claims TEXT NOT NULL,
encryption_mode VARCHAR(255) DEFAULT 'NO_ENCRYPTION' NOT NULL,
timestamp_created TIMESTAMP WITHOUT TIME ZONE DEFAULT NOW(),
timestamp_last_updated TIMESTAMP WITHOUT TIME ZONE,
CONSTRAINT uds_user_claims_pkey PRIMARY KEY (user_id)
);

-- Spring Security
CREATE TABLE uds_users
(
username VARCHAR(50) NOT NULL PRIMARY KEY,
password VARCHAR(500) NOT NULL,
enabled BOOLEAN NOT NULL
);

create table uds_authorities
(
username VARCHAR(50) NOT NULL,
authority VARCHAR(50) NOT NULL,
CONSTRAINT fk_authorities_users FOREIGN KEY (username) REFERENCES uds_users (username)
);

CREATE UNIQUE INDEX ix_auth_username ON uds_authorities (username, authority);

-- Create audit log table - https://github.com/wultra/lime-java-core#wultra-auditing-library
CREATE TABLE IF NOT EXISTS audit_log
(
audit_log_id VARCHAR(36) PRIMARY KEY,
application_name VARCHAR(256) NOT NULL,
audit_level VARCHAR(32) NOT NULL,
audit_type VARCHAR(256),
timestamp_created TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
message TEXT NOT NULL,
exception_message TEXT,
stack_trace TEXT,
param TEXT,
calling_class VARCHAR(256) NOT NULL,
thread_name VARCHAR(256) NOT NULL,
version VARCHAR(256),
build_time TIMESTAMP
);

CREATE TABLE IF NOT EXISTS audit_param
(
audit_log_id VARCHAR(36),
timestamp_created TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
param_key VARCHAR(256),
param_value VARCHAR(4000)
);

CREATE INDEX IF NOT EXISTS audit_log_timestamp ON audit_log (timestamp_created);
CREATE INDEX IF NOT EXISTS audit_log_application ON audit_log (application_name);
CREATE INDEX IF NOT EXISTS audit_log_level ON audit_log (audit_level);
CREATE INDEX IF NOT EXISTS audit_log_type ON audit_log (audit_type);
CREATE INDEX IF NOT EXISTS audit_param_log ON audit_param (audit_log_id);
CREATE INDEX IF NOT EXISTS audit_param_timestamp ON audit_param (timestamp_created);
CREATE INDEX IF NOT EXISTS audit_param_key ON audit_param (param_key);
CREATE INDEX IF NOT EXISTS audit_param_value ON audit_param (param_value);
-- Changeset user-data-store/0.1.x/20230220-initial-schema.xml::1::Lubos Racansky
-- Create a new table uds_user_claims
CREATE TABLE uds_user_claims (user_id VARCHAR(255) NOT NULL, claims TEXT NOT NULL, encryption_mode VARCHAR(255) DEFAULT 'NO_ENCRYPTION' NOT NULL, timestamp_created TIMESTAMP WITHOUT TIME ZONE DEFAULT NOW(), timestamp_last_updated TIMESTAMP WITHOUT TIME ZONE, CONSTRAINT uds_user_claims_pkey PRIMARY KEY (user_id));

-- Changeset user-data-store/0.1.x/20230220-initial-schema.xml::2::Lubos Racansky
-- Create a new table uds_users for spring security
CREATE TABLE uds_users (username VARCHAR(50) NOT NULL, password VARCHAR(500) NOT NULL, enabled BOOLEAN NOT NULL, CONSTRAINT uds_users_pkey PRIMARY KEY (username));

-- Changeset user-data-store/0.1.x/20230220-initial-schema.xml::3::Lubos Racansky
-- Create a new table uds_authorities for spring security
CREATE TABLE uds_authorities (username VARCHAR(50) NOT NULL, authority VARCHAR(50) NOT NULL, CONSTRAINT fk_authorities_users FOREIGN KEY (username) REFERENCES uds_users(username));

-- Changeset user-data-store/0.1.x/20230220-initial-schema.xml::4::Lubos Racansky
-- Create a new unique index on uds_authorities(username, authority)
CREATE UNIQUE INDEX ix_auth_username ON uds_authorities(username, authority);

-- Changeset user-data-store/0.1.x/20230224-audit.xml::1::Lubos Racansky
-- Create a new table audit_log
CREATE TABLE audit_log (audit_log_id VARCHAR(36) NOT NULL, application_name VARCHAR(256) NOT NULL, audit_level VARCHAR(32) NOT NULL, audit_type VARCHAR(256) NOT NULL, timestamp_created TIMESTAMP WITHOUT TIME ZONE DEFAULT NOW(), message TEXT NOT NULL, exception_message TEXT, stack_trace TEXT, param TEXT, calling_class VARCHAR(256) NOT NULL, thread_name VARCHAR(256) NOT NULL, version VARCHAR(256), build_time TIMESTAMP WITHOUT TIME ZONE, CONSTRAINT audit_log_pkey PRIMARY KEY (audit_log_id));

-- Changeset user-data-store/0.1.x/20230322-audit-param.xml::1::Zdenek Cerny
-- Create a new table audit_param
CREATE TABLE audit_param (audit_log_id VARCHAR(36) NOT NULL, param_key VARCHAR(256), param_value VARCHAR(4000), timestamp_created TIMESTAMP WITHOUT TIME ZONE DEFAULT NOW(), CONSTRAINT audit_param_pkey PRIMARY KEY (audit_log_id));

-- Changeset user-data-store/0.1.x/20230322-audit-indexes.xml::1::Lubos Racansky
-- Create a new index on audit_log(timestamp_created)
CREATE INDEX audit_log_timestamp ON audit_log(timestamp_created);

-- Changeset user-data-store/0.1.x/20230322-audit-indexes.xml::2::Lubos Racansky
-- Create a new index on audit_log(application_name)
CREATE INDEX audit_log_application ON audit_log(application_name);

-- Changeset user-data-store/0.1.x/20230322-audit-indexes.xml::3::Lubos Racansky
-- Create a new index on audit_log(audit_level)
CREATE INDEX audit_log_level ON audit_log(audit_level);

-- Changeset user-data-store/0.1.x/20230322-audit-indexes.xml::4::Lubos Racansky
-- Create a new index on audit_log(audit_type)
CREATE INDEX audit_log_type ON audit_log(audit_type);

-- Changeset user-data-store/0.1.x/20230322-audit-indexes.xml::5::Lubos Racansky
-- Create a new index on audit_param(audit_log_id)
CREATE INDEX audit_param_log ON audit_param(audit_log_id);

-- Changeset user-data-store/0.1.x/20230322-audit-indexes.xml::6::Lubos Racansky
-- Create a new index on audit_param(timestamp_created)
CREATE INDEX audit_param_timestamp ON audit_param(timestamp_created);

-- Changeset user-data-store/0.1.x/20230322-audit-indexes.xml::7::Lubos Racansky
-- Create a new index on audit_log(param_key)
CREATE INDEX audit_param_key ON audit_param(param_key);

-- Changeset user-data-store/0.1.x/20230322-audit-indexes.xml::8::Lubos Racansky
-- Create a new index on audit_log(param_value)
CREATE INDEX audit_param_value ON audit_param(param_value);

-- Changeset user-data-store/0.1.x/20231003-audit-type-nullable.xml::1::Lubos Racansky
-- Drop not null constraint for audit_log.audit_type
ALTER TABLE audit_log ALTER COLUMN audit_type DROP NOT NULL;

-- Changeset user-data-store/1.0.x/20231003-add-tag-1.0.0.xml::1::Lubos Racansky
-- Changeset docs/db/changelog/changesets/user-data-store/1.3.x/20240514-refactor-uds-1.3.0.xml::1::Roman Strobl
CREATE TABLE uds_document (id VARCHAR(36) NOT NULL, user_id VARCHAR(255) NOT NULL, document_type VARCHAR(32) NOT NULL, data_type VARCHAR(32) NOT NULL, document_data_id VARCHAR(255), external_id VARCHAR(255), document_data TEXT NOT NULL, attributes TEXT NOT NULL, encryption_mode VARCHAR(255) DEFAULT 'NO_ENCRYPTION' NOT NULL, timestamp_created TIMESTAMP WITHOUT TIME ZONE DEFAULT NOW(), timestamp_last_updated TIMESTAMP WITHOUT TIME ZONE, CONSTRAINT uds_document_pkey PRIMARY KEY (id));

-- Changeset docs/db/changelog/changesets/user-data-store/1.3.x/20240514-refactor-uds-1.3.0.xml::2::Roman Strobl
CREATE TABLE uds_document_history (id VARCHAR(36) NOT NULL, document_id VARCHAR(36) NOT NULL, user_id VARCHAR(255) NOT NULL, document_type VARCHAR(32) NOT NULL, data_type VARCHAR(32) NOT NULL, document_data_id VARCHAR(255), external_id VARCHAR(255), document_data TEXT NOT NULL, attributes TEXT NOT NULL, encryption_mode VARCHAR(255) DEFAULT 'NO_ENCRYPTION' NOT NULL, timestamp_created TIMESTAMP WITHOUT TIME ZONE DEFAULT NOW(), CONSTRAINT uds_document_history_pkey PRIMARY KEY (id));

-- Changeset docs/db/changelog/changesets/user-data-store/1.3.x/20240514-refactor-uds-1.3.0.xml::3::Roman Strobl
CREATE TABLE uds_photo (id VARCHAR(36) NOT NULL, document_id VARCHAR(255) NOT NULL, external_id VARCHAR(255), photo_type VARCHAR(32) NOT NULL, photo_data TEXT NOT NULL, encryption_mode VARCHAR(255) DEFAULT 'NO_ENCRYPTION' NOT NULL, timestamp_created TIMESTAMP WITHOUT TIME ZONE DEFAULT NOW(), timestamp_last_updated TIMESTAMP WITHOUT TIME ZONE, CONSTRAINT uds_photo_pkey PRIMARY KEY (id));

-- Changeset docs/db/changelog/changesets/user-data-store/1.3.x/20240514-refactor-uds-1.3.0.xml::4::Roman Strobl
ALTER TABLE uds_photo ADD CONSTRAINT fk_uds_photo_document_id FOREIGN KEY (document_id) REFERENCES uds_document (id);

-- Changeset docs/db/changelog/changesets/user-data-store/1.3.x/20240514-refactor-uds-1.3.0.xml::5::Roman Strobl
CREATE TABLE uds_attachment (id VARCHAR(36) NOT NULL, document_id VARCHAR(255) NOT NULL, external_id VARCHAR(255), attachment_type VARCHAR(32) NOT NULL, attachment_data TEXT NOT NULL, encryption_mode VARCHAR(255) DEFAULT 'NO_ENCRYPTION' NOT NULL, timestamp_created TIMESTAMP WITHOUT TIME ZONE DEFAULT NOW(), timestamp_last_updated TIMESTAMP WITHOUT TIME ZONE, CONSTRAINT uds_attachment_pkey PRIMARY KEY (id));

-- Changeset docs/db/changelog/changesets/user-data-store/1.3.x/20240514-refactor-uds-1.3.0.xml::6::Roman Strobl
ALTER TABLE uds_attachment ADD CONSTRAINT fk_uds_attachment_document_id FOREIGN KEY (document_id) REFERENCES uds_document (id);
Loading

0 comments on commit 245b171

Please sign in to comment.