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.

106 lines
3.7 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/urbanbigdatacentre/WPD-Auth.git
  20. $ cd WPD-Auth
  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=# CREATE EXTENSION "uuid-ossp";
  31. wpdauth=# \i db/ddl.sql
  32. wpdauth=# \i db/sys_config.sql
  33. wpdauth=# create user uwpdauth;
  34. wpdauth=# alter user uwpdauth with encrypted password '<your really secure password>';
  35. wpdauth=# GRANT USAGE ON SCHEMA auth TO uwpdauth;
  36. wpdauth=# GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA auth TO uwpdauth;
  37. wpdauth=# GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA auth TO uwpdauth;
  38. wpdauth=# \q
  39. ```
  40. - Make sure the load mode ran successfully as described in the [load folder](https://github.com/IGSD-UoW/wpdAuth/tree/main/load)
  41. - Install dependencies
  42. ```console
  43. $ mvn install
  44. ```
  45. - Run the project
  46. ```console
  47. $ mvn spring-boot:run
  48. ```
  49. - Run the project as a service most likely in a production environment (mind the '&' character at the end)
  50. ```console
  51. $ mvn spring-boot:run &
  52. ```
  53. # How to run this project
  54. 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.
  55. - 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.
  56. ```
  57. $ curl -X GET http://localhost:8080/users/me
  58. ```
  59. - Make a POST request to `/users/signin` with the default admin user we programatically created to get a valid JWT token
  60. ```
  61. $ curl -X POST 'http://localhost:8080/users/login?username=admin&password=admin'
  62. ```
  63. - Add the JWT token as a Header parameter and make the initial GET request to `/users/me` again
  64. ```
  65. $ curl -X GET http://localhost:8080/users/me -H 'Authorization: Bearer <JWT_TOKEN>'
  66. ```
  67. - You should get a similar response to this one, meaning that you're now authenticated
  68. ```javascript
  69. {
  70. "id": 1,
  71. "username": "admin",
  72. "email": "admin@email.com",
  73. "roles": [
  74. "ROLE_ADMIN"
  75. ]
  76. }
  77. ```