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.

97 lines
3.4 KiB

4 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=# \i db/ddl.sql
  30. wpdauth=# \i db/sys_config.sql
  31. wpdauth=# create user uwpdauth;
  32. wpdauth=# alter user uwpdauth with encrypted password '<your really secure password>';
  33. wpdauth=# GRANT USAGE ON SCHEMA public TO uwpdauth;
  34. wpdauth=# GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO uwpdauth;
  35. wpdauth=# GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public TO uwpdauth;
  36. wpdauth=# grant all privileges on database wpdauth to uwpdauth;
  37. wpdauth=# \q
  38. ```
  39. - Install dependencies
  40. ```console
  41. $ mvn install
  42. ```
  43. - Run the project
  44. ```console
  45. $ mvn spring-boot:run
  46. ```
  47. # How to run this project
  48. 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.
  49. - 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.
  50. ```
  51. $ curl -X GET http://localhost:8080/users/me
  52. ```
  53. - Make a POST request to `/users/signin` with the default admin user we programatically created to get a valid JWT token
  54. ```
  55. $ curl -X POST 'http://localhost:8080/users/signin?username=admin&password=admin'
  56. ```
  57. - Add the JWT token as a Header parameter and make the initial GET request to `/users/me` again
  58. ```
  59. $ curl -X GET http://localhost:8080/users/me -H 'Authorization: Bearer <JWT_TOKEN>'
  60. ```
  61. - You should get a similar response to this one, meaning that you're now authenticated
  62. ```javascript
  63. {
  64. "id": 1,
  65. "username": "admin",
  66. "email": "admin@email.com",
  67. "roles": [
  68. "ROLE_ADMIN"
  69. ]
  70. }
  71. ```