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.

99 lines
3.5 KiB

3 years ago
  1. # wpdAuth
  2. The authenticator for the Waterproofing Data (WPD) Work Packages. The complete Swagger documentation is available [here](https://igsd-uow.github.io/wpdAuth/).
  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 SCHEMA auth;
  30. wpdauth=# \i db/ddl.sql
  31. wpdauth=# \i db/sys_config.sql
  32. wpdauth=# create user uwpdauth;
  33. wpdauth=# alter user uwpdauth with encrypted password '<your really secure password>';
  34. wpdauth=# GRANT USAGE ON SCHEMA auth TO uwpdauth;
  35. wpdauth=# GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA auth TO uwpdauth;
  36. wpdauth=# GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA auth TO uwpdauth;
  37. wpdauth=# \q
  38. ```
  39. - Make sure the load mode ran successfully as described in the [load folder](https://github.com/IGSD-UoW/wpdAuth/tree/main/load)
  40. - Install dependencies
  41. ```console
  42. $ mvn install
  43. ```
  44. - Run the project
  45. ```console
  46. $ mvn spring-boot:run
  47. ```
  48. # How to run this project
  49. 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.
  50. - 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.
  51. ```
  52. $ curl -X GET http://localhost:8080/users/me
  53. ```
  54. - Make a POST request to `/users/signin` with the default admin user we programatically created to get a valid JWT token
  55. ```
  56. $ curl -X POST 'http://localhost:8080/users/login?username=admin&password=admin'
  57. ```
  58. - Add the JWT token as a Header parameter and make the initial GET request to `/users/me` again
  59. ```
  60. $ curl -X GET http://localhost:8080/users/me -H 'Authorization: Bearer <JWT_TOKEN>'
  61. ```
  62. - You should get a similar response to this one, meaning that you're now authenticated
  63. ```javascript
  64. {
  65. "id": 1,
  66. "username": "admin",
  67. "email": "admin@email.com",
  68. "roles": [
  69. "ROLE_ADMIN"
  70. ]
  71. }
  72. ```