Skip to content

Commit

Permalink
Merge pull request #79 from it-at-m/39-db-für-entwicklung-von-broadca…
Browse files Browse the repository at this point in the history
…st-service-bereitstellen

db in docker für entwicklung von broadcast service bereitstellen
  • Loading branch information
MrSebastian authored Apr 17, 2024
2 parents 57aa80f + 2aecaa4 commit fb19645
Show file tree
Hide file tree
Showing 11 changed files with 122 additions and 24 deletions.
21 changes: 18 additions & 3 deletions docs/src/technik/development/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
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: \<Name des Services\>
- Passwort: secret
17 changes: 16 additions & 1 deletion stack/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
keycloak:
services:
9 changes: 9 additions & 0 deletions stack/oracle-database/add-user-on-startup.sql
Original file line number Diff line number Diff line change
@@ -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;
23 changes: 18 additions & 5 deletions wls-broadcast-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,19 @@
<groupId>org.hibernate.orm</groupId>
<artifactId>hibernate-core</artifactId>
</dependency>
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
</dependency>
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-database-oracle</artifactId>
</dependency>
<dependency>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc11</artifactId>
<version>23.3.0.23.09</version>
</dependency>
<!-- Hibernate Model Gen for type safe criterias -->
<dependency>
<groupId>org.hibernate.orm</groupId>
Expand Down Expand Up @@ -315,7 +328,7 @@
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
<configuration>
<argLine>${surefireArgLine} -Dfile.encoding=${project.build.sourceEncoding}</argLine>
<argLine>${surefireArgLine} -Dfile.encoding=${project.build.sourceEncoding}</argLine>
</configuration>
</plugin>

Expand All @@ -335,10 +348,10 @@
<goal>prepare-agent</goal>
</goals>
<configuration>
<append>true</append>
<destFile>${sonar.jacoco.reportPath}</destFile>
<!-- Sets the VM argument line used when unit tests are run. -->
<propertyName>surefireArgLine</propertyName>
<append>true</append>
<destFile>${sonar.jacoco.reportPath}</destFile>
<!-- Sets the VM argument line used when unit tests are run. -->
<propertyName>surefireArgLine</propertyName>
</configuration>
</execution>
<execution>
Expand Down
17 changes: 17 additions & 0 deletions wls-broadcast-service/src/main/resources/application-db-h2.yml
Original file line number Diff line number Diff line change
@@ -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
16 changes: 16 additions & 0 deletions wls-broadcast-service/src/main/resources/application-db-oracle.yml
Original file line number Diff line number Diff line change
@@ -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
15 changes: 0 additions & 15 deletions wls-broadcast-service/src/main/resources/application-local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 8 additions & 0 deletions wls-broadcast-service/src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
CREATE TABLE theEntity
(
id varchar2(36) NOT NULL primary key,
textAttribute varchar2(8) NOT NULL
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
CREATE TABLE theEntity
(
id varchar2(36) NOT NULL primary key,
textAttribute varchar2(8) NOT NULL
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
###
POST http://localhost:39146/theEntities
Content-Type: application/json

{
"textAttribute": "my text"
}

###
GET http://localhost:39146/theEntities

0 comments on commit fb19645

Please sign in to comment.