Skip to content

Commit

Permalink
Rework security-jpa-quickstart
Browse files Browse the repository at this point in the history
Old version's readme didn't describe how to connect to postgres in JVM mode,
also old app was not able to properly connect to postgres.
Postgres' docker container was started in overcomplicated way.

Update dependencies.

Remove files, which are no longer necessary.
  • Loading branch information
mocenas committed Jul 26, 2023
1 parent 0fb9830 commit d696a79
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 34 deletions.
43 changes: 26 additions & 17 deletions security-jpa-quickstart/README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,40 @@
Quarkus Elytron Security with JPA
Quarkus Security with JPA
========================

This guide demonstrates how your Quarkus application can use a database and JPA to store your user identities.

## Start the database
## Run quickstart in developer mode

You need a database to store the user identities/roles. Here, we are using [PostgreSQL](https://www.postgresql.org).
To ease the setup, we have provided a `docker-compose.yml` file which start a PostgreSQL container, bind the network ports
and finally creates the users and their credentials by importing the `import.sql` file.
Quarkus provides developer mode, in which you can try this example. Just try:

The database can be started using:
```bash
docker-compose up
```
```bash
mvn quarkus:dev
```

Once the database is up you can start your Quarkus application.
Now the application will listen on `localhost:8080`.
In developer mode quarkus will also start its own postgres database.

Note you do not need to start the database when running your application in dev mode or testing. It will be started automatically as a Dev Service.
## Run quickstart in JVM mode

## Start the application
### Start the database

The application can be started using:
Now we need to start a [PostgreSQL](https://www.postgresql.org) database on our own.
To set it up with docker:

```bash
mvn compile quarkus:dev
docker run -it --rm=true --name quarkus_test -e POSTGRES_USER=quarkus -e POSTGRES_PASSWORD=quarkus -e POSTGRES_DB=quarkus -p 5432:5432 postgres:15.3
```

Once the database is up, you can start your Quarkus application.
Application will fill in the users and their credentials on `StartupEvent`.

### Start the application

The application can be build & started using:

```bash
mvn clean package
java -jar target/quarkus-app/quarkus-run.jar
```

## Test the application
Expand All @@ -34,7 +45,7 @@ The application exposes 3 endpoints:
* `/api/admin`
* `/api/users/me`

You can try these endpoints with an http client (`curl`, `HTTPie`, etc).
You can try these endpoints with a http client (`curl`, `HTTPie`, etc).
Here you have some examples to check the security configuration:

```bash
Expand All @@ -45,8 +56,6 @@ curl -i -X GET http://localhost:8080/api/users/me # 'unauthorized'
curl -i -X GET -u user:user http://localhost:8080/api/users/me # 'user'
```

_NOTE:_ Stop the database using: `docker-compose down; docker-compose rm`

### Integration testing

We have provided integration tests based on [Dev Services for PostgreSQL](https://quarkus.io/guides/dev-services#databases) to verify the security configuration in JVM and native modes. The test and dev modes containers will be launched automatically because all the PostgreSQL configuration properties are only enabled in production (`prod`) mode.
Expand Down
9 changes: 0 additions & 9 deletions security-jpa-quickstart/docker-compose.yml

This file was deleted.

5 changes: 0 additions & 5 deletions security-jpa-quickstart/init.sql

This file was deleted.

4 changes: 2 additions & 2 deletions security-jpa-quickstart/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
<quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id>
<quarkus.platform.group-id>io.quarkus</quarkus.platform.group-id>
<quarkus.platform.version>999-SNAPSHOT</quarkus.platform.version>
<compiler-plugin.version>3.8.1</compiler-plugin.version>
<surefire-plugin.version>3.0.0-M7</surefire-plugin.version>
<compiler-plugin.version>3.11.0</compiler-plugin.version>
<surefire-plugin.version>3.1.2</surefire-plugin.version>
<maven.compiler.target>11</maven.compiler.target>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.parameters>true</maven.compiler.parameters>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
%prod.quarkus.datasource.db-kind=postgresql
%prod.quarkus.datasource.username=quarkus
%prod.quarkus.datasource.password=quarkus
%prod.quarkus.datasource.jdbc.url=jdbc:postgresql:elytron_security_jpa
%prod.quarkus.datasource.jdbc.url=jdbc:postgresql://localhost/quarkus

quarkus.hibernate-orm.database.generation=drop-and-create

0 comments on commit d696a79

Please sign in to comment.