Skip to content

Commit

Permalink
#39 - fixing liquibase
Browse files Browse the repository at this point in the history
  • Loading branch information
pveeckhout authored and Pieter Van Eeckhout committed Jun 27, 2023
1 parent b6e5eff commit e5aad69
Show file tree
Hide file tree
Showing 24 changed files with 112 additions and 53 deletions.
2 changes: 2 additions & 0 deletions boot/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ extraJavaModuleInfo {
automaticModule("mybatis-3.5.11.jar", "org.apache.ibatis")
automaticModule("swagger-ui-4.18.2.jar", "org.webjars.swagger.ui")

automaticModule("jjwt-0.9.1.jar", "io.jsonwebtoken")

automaticModule("simpleclient-0.16.0.jar","io.prometheus")
automaticModule("simpleclient_common-0.16.0.jar","io.prometheus")
automaticModule("simpleclient_tracer_common-0.16.0.jar","io.prometheus")
Expand Down
1 change: 1 addition & 0 deletions boot/src/main/java/io/edpn/backend/EDPNApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.PropertySource;

@SpringBootApplication
public class EDPNApplication {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import io.edpn.backend.user.application.controller.DefaultJwtAuthenticationController;
import io.edpn.backend.user.domain.service.JwtTokenService;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.web.bind.annotation.RestController;

@RestController
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package io.edpn.backend.configuration;

import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.annotation.PropertySources;

@Configuration("BootPropertyConfig")
@PropertySources({
@PropertySource("classpath:boot.properties"),
})
public class PropertyConfig {
}
2 changes: 2 additions & 0 deletions boot/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
requires spring.web;
requires spring.beans;
requires spring.boot.starter.security;
requires spring.security.crypto;
requires spring.security.core;

requires io.edpn.backend.trade;
requires io.edpn.backend.user;
Expand Down
6 changes: 4 additions & 2 deletions docker-compose-localdev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ services:
timeout: 5s
retries: 5

trademodule_postgres:
usermodule_postgres:
image: "postgres:15-alpine"
restart: on-failure
environment:
- POSTGRES_USER=edpn_usermodule
- POSTGRES_PASSWORD=MSDVq372rNk3AwRq
- POSTGRES_PASSWORD=hvWYDHqG3yXCKReH
- POSTGRES_DB=usermodule
volumes:
- "usermodule_postgres:/var/lib/postgresql/data"
Expand All @@ -79,3 +79,5 @@ volumes:
driver: local
trademodule_postgres:
driver: local
usermodule_postgres:
driver: local
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
package io.edpn.backend.user.application.model;

import io.edpn.backend.user.domain.model.EdpnUser;
import io.edpn.backend.user.domain.model.UserGrant;
import io.edpn.backend.user.domain.model.UserRole;
import lombok.Data;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.time.LocalDateTime;
import java.util.Collection;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import lombok.Data;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

@Data
@RequiredArgsConstructor
Expand All @@ -23,8 +25,8 @@ public class EdpnUserDetails implements UserDetails {
@Override
public Collection<? extends GrantedAuthority> getAuthorities() {
return Stream.concat(user.getRoles().stream().map(UserRole::getName).map("ROLE_"::concat),
Stream.concat(user.getRoles().stream().map(UserRole::getGrants).flatMap(Set::stream),
user.getGrants().stream().map("GRANT_"::concat)))
Stream.concat(user.getRoles().stream().map(UserRole::getGrants).flatMap(Set::stream).map(UserGrant::getName),
user.getGrants().stream().map(UserGrant::getName).map("GRANT_"::concat)))
.map(SimpleGrantedAuthority::new)
.collect(Collectors.toUnmodifiableSet());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package io.edpn.backend.user.configuration;

import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.annotation.PropertySources;

@Configuration("UserModulePropertyConfig")
@PropertySources({
@PropertySource("classpath:usermodule.properties"),
@PropertySource("classpath:usermodule-local.properties"),
})
public class PropertyConfig {
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

import static org.springframework.security.config.Customizer.withDefaults;

@Configuration
@Configuration("UserModuleSecurityConfig")
public class SecurityConfiguration {

@Bean
Expand Down
4 changes: 4 additions & 0 deletions user-module/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
requires io.github.bucket4j.core;
requires spring.security.core;
requires io.edpn.backend.mybatis.util;
requires spring.security.crypto;
requires spring.security.web;
requires spring.security.config;
requires spring.web;

exports io.edpn.backend.user.application.controller;
exports io.edpn.backend.user.application.dto;
Expand Down
12 changes: 0 additions & 12 deletions user-module/src/main/resources/db/changelog/changelog-master.xml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
</createTable>

<createIndex tableName="api_grant" indexName="idx_api_grant_name">
<column>name</column>
<column name="name" />
</createIndex>
</changeSet>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.3.xsd">

<changeSet id="create-api_key_api_rol_map-table" author="pveeckhout">
<createTable tableName="api_key_api_rol_map">
<changeSet id="create-api_key_api_role_map-table" author="pveeckhout">
<createTable tableName="api_key_api_role_map">
<column name="key" type="uuid">
<constraints nullable="false"/>
</column>
Expand All @@ -13,10 +13,10 @@
</column>
</createTable>

<addPrimaryKey tableName="api_key_api_rol_map" columnNames="key,rol"/>
<addForeignKeyConstraint baseTableName="api_key_api_rol_map" baseColumnNames="key" constraintName="fk_api_key_api_rol_map_key" referencedTableName="api_key"
<addPrimaryKey tableName="api_key_api_role_map" columnNames="key,rol"/>
<addForeignKeyConstraint baseTableName="api_key_api_role_map" baseColumnNames="key" constraintName="fk_api_key_api_role_map_key" referencedTableName="api_key"
referencedColumnNames="id" />
<addForeignKeyConstraint baseTableName="api_key_api_rol_map" baseColumnNames="rol" constraintName="fk_api_key_api_rol_map_rol" referencedTableName="api_rol"
<addForeignKeyConstraint baseTableName="api_key_api_role_map" baseColumnNames="rol" constraintName="fk_api_key_api_role_map_rol" referencedTableName="api_role"
referencedColumnNames="id" />
</changeSet>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,34 @@
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="prefix" type="varchar(255)">
<constraints nullable="false" />
<constraints nullable="false"/>
</column>
<column name="key_hash" type="varchar(255)">
<constraints nullable="false" />
<constraints nullable="false"/>
</column>
<column name="name" type="varchar(255)">
<constraints nullable="false" />
<constraints nullable="false"/>
</column>
<column name="expiry_timestamp" type="timestamp">
<constraints nullable="false" />
<constraints nullable="false"/>
</column>
<column name="enabled" type="boolean"/>
<column name="edpn_user" type="uuid">
<constraints nullable="false" />
<constraints nullable="false"/>
</column>
</createTable>

<addUniqueConstraint tableName="api_key" columnNames="prefix,key_hash" />
<addUniqueConstraint tableName="api_key" columnNames="prefix,key_hash"/>
<createIndex tableName="api_key" indexName="idx_prefix_key_hash">
<column>prefix</column>
<column>key_hash</column>
<column name="prefix"/>
<column name="key_hash"/>
</createIndex>

<addForeignKeyConstraint baseTableName="api_key" baseColumnNames="edpn_user" constraintName="fk_api_key_user" referencedTableName="edpn_user"
referencedColumnNames="id" />
<addForeignKeyConstraint baseTableName="api_key" baseColumnNames="edpn_user" constraintName="fk_api_key_user"
referencedTableName="edpn_user"
referencedColumnNames="id"/>
<createIndex tableName="api_key" indexName="idx_edpn_user">
<column>edpn_user</column>
<column name="edpn_user"/>
</createIndex>
</changeSet>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
</createTable>

<createIndex tableName="api_role" indexName="idx_api_role_name">
<column>name</column>
<column name="name" />
</createIndex>
</changeSet>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<addForeignKeyConstraint baseTableName="edpn_user" baseColumnNames="pricing_plan" constraintName="fk_edpn_user_pricing_plan" referencedTableName="pricing_plan"
referencedColumnNames="id" />
<createIndex tableName="pricing_plan" indexName="idx_pricing_plan">
<column>name</column>
<column name="name" />
</createIndex>
</changeSet>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@

<addPrimaryKey tableName="edpn_user_user_grant_map" columnNames="edpn_user,grant"/>
<addForeignKeyConstraint baseTableName="edpn_user_user_grant_map" baseColumnNames="edpn_user"
constraintName="fk_edpn_user_user_grant_map_user" referencedTableName="edn_user"
referencedColumnNames="edpn_user"/>
constraintName="fk_edpn_user_user_grant_map_user" referencedTableName="edpn_user"
referencedColumnNames="id"/>
<addForeignKeyConstraint baseTableName="edpn_user_user_grant_map" baseColumnNames="grant"
constraintName="fk_edpn_user_user_grant_map_grant" referencedTableName="user_grant"
referencedColumnNames="id"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
</column>
</createTable>

<addPrimaryKey tableName="edpn_user_user_role_map" columnNames="edpn_user,grant"/>
<addPrimaryKey tableName="edpn_user_user_role_map" columnNames="edpn_user,role"/>
<addForeignKeyConstraint baseTableName="edpn_user_user_role_map" baseColumnNames="edpn_user"
constraintName="fk_edpn_user_user_grant_map_edpn_user" referencedTableName="edpn_user"
constraintName="fk_edpn_user_user_role_map_edpn_user" referencedTableName="edpn_user"
referencedColumnNames="id"/>
<addForeignKeyConstraint baseTableName="edpn_user_user_role_map" baseColumnNames="role"
constraintName="fk_edpn_user_user_role_map_grant" referencedTableName="user_grant"
constraintName="fk_edpn_user_user_role_map_role" referencedTableName="user_role"
referencedColumnNames="id"/>
</changeSet>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
<column name="name" type="varchar(255)">
<constraints nullable="false" />
</column>
<column name="capacity_per_minute" type="long">
<column name="capacity_per_minute" type="bigint">
<constraints nullable="false" />
</column>

</createTable>

<createIndex tableName="pricing_plan" indexName="idx_pricing_plan_name">
<column>name</column>
<column name="name" />
</createIndex>
</changeSet>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
</createTable>

<createIndex tableName="user_grant" indexName="idx_user_grant_name">
<column>name</column>
<column name="name" />
</createIndex>
</changeSet>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
</createTable>

<createIndex tableName="user_role" indexName="idx_user_role_name">
<column>name</column>
<column name="name" />
</createIndex>
</changeSet>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?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-3.8.xsd">


<include file="db/changelog/create_api_grant_table.xml"/>
<include file="db/changelog/create_api_role_table.xml"/>
<include file="db/changelog/create_api_role_api_grant_map_table.xml"/>

<include file="db/changelog/create_user_grant_table.xml"/>
<include file="db/changelog/create_user_role_table.xml"/>
<include file="db/changelog/create_user_role_user_grant_map_table.xml"/>

<include file="db/changelog/create_pricing_plan_table.xml"/>

<include file="db/changelog/create_edpn_user_table.xml"/>
<include file="db/changelog/create_edpn_user_user_role_map_table.xml"/>
<include file="db/changelog/create_edpn_user_user_grant_map_table.xml"/>

<include file="db/changelog/create_api_key_table.xml"/>
<include file="db/changelog/create_api_key_api_grant_map_table.xml"/>
<include file="db/changelog/create_api_key_api_role_map_table.xml"/>

<!-- views always last as they might depend on new columns -->


</databaseChangeLog>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
spring.liquibase.enabled=true
spring.liquibase.change-log=classpath:db/changelog/changelog-master.xml
spring.liquibase.change-log=classpath:db/changelog/usermodule-changelog.xml

spring.datasource.url=jdbc:postgresql://localhost:54322/user
spring.datasource.url=jdbc:postgresql://localhost:54322/usermodule
spring.datasource.username=edpn_usermodule
spring.datasource.password=hvWYDHqG3yXCKReH
spring.datasource.driver-class-name=org.postgresql.Driver
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
spring.liquibase.enabled=true
spring.liquibase.change-log=classpath:db/changelog/changelog-master.xml
spring.liquibase.change-log=classpath:db/changelog/usermodule-changelog.xml

spring.datasource.url=${USERMODULE_DB_URL}
spring.datasource.username=${USERMODULE_DB_USERNAME}
Expand Down

0 comments on commit e5aad69

Please sign in to comment.