You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

92 lines
3.0 KiB

3 years ago
  1. # wpdAuth
  2. The authenticator for the Waterproofing Data (WPD) Work Packages
  3. ## How this project was created
  4. This project was initially created using the [spring initializr](https://start.spring.io/), together with the following dependencies:
  5. - [Lombok](https://projectlombok.org/). Java annotation library which helps to reduce boilerplate code.
  6. - [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.
  7. - [Spring Data JPA](https://spring.io/projects/spring-data-jpa). Persist data in SQL stores with Java Persistence API using Spring Data and Hibernate.
  8. - [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.
  9. - [Spring Security](https://spring.io/projects/spring-security). Highly customizable authentication and access-control framework for Spring applications.
  10. # Dependencies
  11. - [Maven Project](https://maven.apache.org/)
  12. - [Java 16](http://openjdk.java.net/projects/jdk/16/)
  13. - [Spring Boot 2.5.3](https://spring.io/projects/spring-boot/)
  14. - [PostgreSQL](https://www.postgresql.org/) via [Homebrew preferably](https://formulae.brew.sh/formula/postgresql)
  15. # How to setup this project
  16. Once the dependencies are properly installed, follow the steps below:
  17. - Clone the project locally
  18. ```console
  19. $ git clone https://github.com/IGSD-UoW/wpdAuth.git
  20. $ cd wpdAuth
  21. ```
  22. - Start the PostgreSQL and run the scripts to create the database and get the load data.
  23. ```console
  24. $ brew services start postgresql
  25. $ psql postgres
  26. postgres=# \conninfo
  27. postgres=# CREATE DATABASE wpdauth;
  28. postgres=# \c wpdauth
  29. wpdauth=# CREATE EXTENSION "uuid-ossp";
  30. wpdauth=# \i db/ddl.sql
  31. wpdauth=# \i db/sys_config.sql
  32. wpdauth=# \q
  33. ```
  34. - Install dependencies
  35. ```console
  36. $ mvn install
  37. ```
  38. - Run the project
  39. ```console
  40. $ mvn spring-boot:run
  41. ```
  42. # How to run this project
  43. 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.
  44. - 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.
  45. ```
  46. $ curl -X GET http://localhost:8080/users/me
  47. ```
  48. - Make a POST request to `/users/signin` with the default admin user we programatically created to get a valid JWT token
  49. ```
  50. $ curl -X POST 'http://localhost:8080/users/signin?username=admin&password=admin'
  51. ```
  52. - Add the JWT token as a Header parameter and make the initial GET request to `/users/me` again
  53. ```
  54. $ curl -X GET http://localhost:8080/users/me -H 'Authorization: Bearer <JWT_TOKEN>'
  55. ```
  56. - You should get a similar response to this one, meaning that you're now authenticated
  57. ```javascript
  58. {
  59. "id": 1,
  60. "username": "admin",
  61. "email": "admin@email.com",
  62. "roles": [
  63. "ROLE_ADMIN"
  64. ]
  65. }
  66. ```