diff --git a/docs/src/technik/development/index.md b/docs/src/technik/development/index.md index 426499445..7ed661c76 100644 --- a/docs/src/technik/development/index.md +++ b/docs/src/technik/development/index.md @@ -14,23 +14,38 @@ flowchart LR keycloak[Keycloak] keycloakDB[db-postgres-keycloak] keycloakInit[init-keycloak] + oracleDB[Oracle DB] end wlsService ---|OAuth2| keycloak + wlsService --->|persisting|oracleDB keycloak-->|persisting| keycloakDB keycloakInit-->|setup of| keycloak end ``` -## Benutzer +## Keycloak + +### Benutzer | Name | Passwort | Beschreibung | | --- | --- | --- | | keycloak_test | test | Ein Benutzer ohne weitere Rechte | | wls_all | test | Ein Benutzer mit allen Rechten | -## Beispiel-Requests +### Beispiel-Requests Im Soap-UI-Projekt (`DockerTest-soapui-project`) und `docker.keycloak.http` sind Beispielrequests vorhanden. -Es kann für den jeweiligen Nutzer ein Token geholt werden. Außerdem ist die Anfrage an den UserInfo-Endpoint hinterlegt. \ No newline at end of file +Es kann für den jeweiligen Nutzer ein Token geholt werden. Außerdem ist die Anfrage an den UserInfo-Endpoint hinterlegt. + +## Datenbank + +Jeder Service bekommt einen eigenen Benutzer für die Datenbank. Die Zugriffs-URL ist für alle Services gleich: +`jdbc:oracle:thin:@//localhost:1521/XEPDB1` + +Neben dem Standardbenutzer der auf alles zugreifen kann (siehe `docker-compose.yml`) müssen alle weiteren Benutzer über `stack/add-user-on-startup.sql` erstellt werden. + +Dabei sollte auf folgendes Schema geachtet werden: +- Benutzername: \ +- Passwort: secret \ No newline at end of file diff --git a/stack/docker-compose.yml b/stack/docker-compose.yml index 8277e5253..1313c8ff3 100644 --- a/stack/docker-compose.yml +++ b/stack/docker-compose.yml @@ -50,6 +50,21 @@ services: networks: - keycloak + wls-db-oracle: + container_name: wls-db-oracle + image: gvenzl/oracle-xe:21-faststart + ports: + - 1521:1521 + environment: + ORACLE_PASSWORD: secret + APP_USER: app_user + APP_USER_PASSWORD: secret + volumes: + - './oracle-database:/container-entrypoint-startdb.d' + networks: + - services + networks: internal: - keycloak: \ No newline at end of file + keycloak: + services: \ No newline at end of file diff --git a/stack/oracle-database/add-user-on-startup.sql b/stack/oracle-database/add-user-on-startup.sql new file mode 100644 index 000000000..27e6f56b2 --- /dev/null +++ b/stack/oracle-database/add-user-on-startup.sql @@ -0,0 +1,9 @@ +-- Switch to pluggable database +alter session set container=XEPDB1; + +-- produces ignorable error message `user name 'WLS_BROADCAST_SERVICE' conflicts with another ...` +-- when the user already exists + +-- add user for wls-broadcast-service +CREATE USER wls_broadcast_service IDENTIFIED BY secret QUOTA UNLIMITED ON USERS; +GRANT CONNECT, RESOURCE, CREATE SESSION TO wls_broadcast_service; \ No newline at end of file diff --git a/wls-broadcast-service/pom.xml b/wls-broadcast-service/pom.xml index 238304782..ef40df46c 100644 --- a/wls-broadcast-service/pom.xml +++ b/wls-broadcast-service/pom.xml @@ -133,6 +133,19 @@ org.hibernate.orm hibernate-core + + org.flywaydb + flyway-core + + + org.flywaydb + flyway-database-oracle + + + com.oracle.database.jdbc + ojdbc11 + 23.3.0.23.09 + org.hibernate.orm @@ -315,7 +328,7 @@ maven-surefire-plugin ${maven-surefire-plugin.version} - ${surefireArgLine} -Dfile.encoding=${project.build.sourceEncoding} + ${surefireArgLine} -Dfile.encoding=${project.build.sourceEncoding} @@ -335,10 +348,10 @@ prepare-agent - true - ${sonar.jacoco.reportPath} - - surefireArgLine + true + ${sonar.jacoco.reportPath} + + surefireArgLine diff --git a/wls-broadcast-service/src/main/resources/application-db-h2.yml b/wls-broadcast-service/src/main/resources/application-db-h2.yml new file mode 100644 index 000000000..a16613891 --- /dev/null +++ b/wls-broadcast-service/src/main/resources/application-db-h2.yml @@ -0,0 +1,17 @@ +spring: + h2.console.enabled: true + datasource: + username: sa + password: + url: jdbc:h2:mem:wls-broadcast-service + flyway: + enabled: true + jpa: + database: H2 + hibernate: + ddl-auto: validate + naming.physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl + properties: + hibernate: + format_sql: true + show-sql: true \ No newline at end of file diff --git a/wls-broadcast-service/src/main/resources/application-db-oracle.yml b/wls-broadcast-service/src/main/resources/application-db-oracle.yml new file mode 100644 index 000000000..e493ef934 --- /dev/null +++ b/wls-broadcast-service/src/main/resources/application-db-oracle.yml @@ -0,0 +1,16 @@ +spring: + datasource: + username: wls_broadcast_service + password: secret + url: jdbc:oracle:thin:@//localhost:1521/XEPDB1 + flyway: + enabled: true + jpa: + database: oracle + hibernate: + ddl-auto: validate + naming.physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl + properties: + hibernate: + format_sql: true + show-sql: true \ No newline at end of file diff --git a/wls-broadcast-service/src/main/resources/application-local.yml b/wls-broadcast-service/src/main/resources/application-local.yml index 00195fe90..6022850d2 100644 --- a/wls-broadcast-service/src/main/resources/application-local.yml +++ b/wls-broadcast-service/src/main/resources/application-local.yml @@ -3,21 +3,6 @@ server: spring: # Spring JPA - h2.console.enabled: true - jpa: - database: H2 - hibernate: - # always drop and create the db should be the best - # configuration for local (development) mode. this - # is also the default, that spring offers by convention. - # but here explicite: - ddl-auto: create-drop - naming.physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl - # Logging for database operation - show-sql: true - properties: - hibernate: - format_sql: true security: oauth2: resourceserver: diff --git a/wls-broadcast-service/src/main/resources/application.yml b/wls-broadcast-service/src/main/resources/application.yml index 3297bfb39..a3b1108ef 100644 --- a/wls-broadcast-service/src/main/resources/application.yml +++ b/wls-broadcast-service/src/main/resources/application.yml @@ -1,6 +1,14 @@ spring: application.name: @project.artifactId@ banner.location: banner.txt + profiles: + group: + local: + - db-oracle + flyway: + locations: + - classpath:db/migrations/{vendor} + h2.console.enabled: false server: shutdown: "graceful" diff --git a/wls-broadcast-service/src/main/resources/db/migrations/h2/V0_1__createTableTheEntity.sql b/wls-broadcast-service/src/main/resources/db/migrations/h2/V0_1__createTableTheEntity.sql new file mode 100644 index 000000000..1f2b83f72 --- /dev/null +++ b/wls-broadcast-service/src/main/resources/db/migrations/h2/V0_1__createTableTheEntity.sql @@ -0,0 +1,5 @@ +CREATE TABLE theEntity +( + id varchar2(36) NOT NULL primary key, + textAttribute varchar2(8) NOT NULL +) \ No newline at end of file diff --git a/wls-broadcast-service/src/main/resources/db/migrations/oracle/V0_1__createTableTheEntity.sql b/wls-broadcast-service/src/main/resources/db/migrations/oracle/V0_1__createTableTheEntity.sql new file mode 100644 index 000000000..1f2b83f72 --- /dev/null +++ b/wls-broadcast-service/src/main/resources/db/migrations/oracle/V0_1__createTableTheEntity.sql @@ -0,0 +1,5 @@ +CREATE TABLE theEntity +( + id varchar2(36) NOT NULL primary key, + textAttribute varchar2(8) NOT NULL +) \ No newline at end of file diff --git a/wls-broadcast-service/src/test/resources/http_requests/theEntityExamples.http b/wls-broadcast-service/src/test/resources/http_requests/theEntityExamples.http new file mode 100644 index 000000000..8ba3d32a8 --- /dev/null +++ b/wls-broadcast-service/src/test/resources/http_requests/theEntityExamples.http @@ -0,0 +1,10 @@ +### +POST http://localhost:39146/theEntities +Content-Type: application/json + +{ + "textAttribute": "my text" +} + +### +GET http://localhost:39146/theEntities \ No newline at end of file