From 8e27b74da9a7d8b551e3c7afd7d2a2573e31b61b Mon Sep 17 00:00:00 2001 From: ddangelorb Date: Fri, 13 Aug 2021 15:49:49 -0300 Subject: [PATCH] First version to repo --- .gitignore | 1 + README.md | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ pom.xml | 33 +++++++++++++++++++ 3 files changed, 129 insertions(+) diff --git a/.gitignore b/.gitignore index a1c2a23..c836fce 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,4 @@ # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml hs_err_pid* +/target/ diff --git a/README.md b/README.md index efbeda6..391fa3b 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,97 @@ # wpdAuth The authenticator for the Waterproofing Data (WPD) Work Packages + +## How this project was created + +This project was initially created using the [spring initializr](https://start.spring.io/), together with the following dependencies: + +- [Lombok](https://projectlombok.org/). Java annotation library which helps to reduce boilerplate code. +- [Spring Web](https://spring.io/guides/gs/serving-web-content/). Build web, including RESTful, applications using Spring MVC. Uses Apache Tomcat as the default embedded container. +- [Spring Data JPA](https://spring.io/projects/spring-data-jpa). Persist data in SQL stores with Java Persistence API using Spring Data and Hibernate. +- [PostgreSQL Driver](https://jdbc.postgresql.org/). A JDBC and R2DBC driver that allows Java programs to connect to a PostgreSQL database using standard, database independent Java code. +- [Spring Security](https://spring.io/projects/spring-security). Highly customizable authentication and access-control framework for Spring applications. + +# Dependencies + +- [Maven Project](https://maven.apache.org/) +- [Java 16](http://openjdk.java.net/projects/jdk/16/) +- [Spring Boot 2.5.3](https://spring.io/projects/spring-boot/) +- [PostgreSQL](https://www.postgresql.org/) via [Homebrew preferably](https://formulae.brew.sh/formula/postgresql) + +# How to setup this project + +Once the dependencies are properly installed, follow the steps below: + +- Clone the project locally + +```console + $ git clone https://github.com/IGSD-UoW/wpdAuth.git + $ cd wpdAuth +``` + +- Start the PostgreSQL and run the scripts to create the database and get the load data. + +```console + $ brew services start postgresql + $ psql postgres + postgres=# \conninfo + postgres=# CREATE DATABASE wpdauth; + postgres=# \c wpdauth + wpdauth=# \i db/ddl.sql + wpdauth=# \i db/sys_config.sql + wpdauth=# create user uwpdauth; + wpdauth=# alter user uwpdauth with encrypted password ''; + wpdauth=# GRANT USAGE ON SCHEMA public TO uwpdauth; + wpdauth=# GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO uwpdauth; + wpdauth=# GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public TO uwpdauth; + wpdauth=# grant all privileges on database wpdauth to uwpdauth; + wpdauth=# \q +``` + +- Install dependencies + +```console + $ mvn install +``` + +- Run the project + +```console + $ mvn spring-boot:run +``` + + +# How to run this project + +Navigate to `http://localhost:8080/swagger-ui.html` in your browser to check everything is working correctly. You can change the default port in the `application.properties` file. + +- Make a GET request to `/users/me` to check you're not authenticated. You should receive a response with a `403` with an `Access Denied` message since you haven't set your valid JWT token yet. + +``` +$ curl -X GET http://localhost:8080/users/me +``` + +- Make a POST request to `/users/signin` with the default admin user we programatically created to get a valid JWT token + +``` +$ curl -X POST 'http://localhost:8080/users/signin?username=admin&password=admin' +``` + +- Add the JWT token as a Header parameter and make the initial GET request to `/users/me` again + +``` +$ curl -X GET http://localhost:8080/users/me -H 'Authorization: Bearer ' +``` + +- You should get a similar response to this one, meaning that you're now authenticated + +```javascript +{ + "id": 1, + "username": "admin", + "email": "admin@email.com", + "roles": [ + "ROLE_ADMIN" + ] +} +``` diff --git a/pom.xml b/pom.xml index 05189cd..a1cdcb5 100644 --- a/pom.xml +++ b/pom.xml @@ -50,6 +50,39 @@ spring-security-test test + + + + io.springfox + springfox-swagger2 + 2.9.2 + + + + io.springfox + springfox-swagger-ui + 2.9.2 + + + + javax.validation + validation-api + 1.1.0.Final + + + + + io.jsonwebtoken + jjwt + 0.9.1 + + + + + org.modelmapper + modelmapper + 2.3.5 +