├── .github └── FUNDING.yml ├── .gitignore ├── README.md ├── book-api ├── .mvn │ └── wrapper │ │ └── maven-wrapper.properties ├── mvnw ├── mvnw.cmd ├── pom.xml ├── src │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── ivanfranchin │ │ │ │ └── bookapi │ │ │ │ ├── BookApiApplication.java │ │ │ │ ├── book │ │ │ │ ├── Book.java │ │ │ │ ├── BookNotFoundException.java │ │ │ │ ├── BookRepository.java │ │ │ │ ├── BookService.java │ │ │ │ └── BookServiceImpl.java │ │ │ │ ├── config │ │ │ │ ├── ErrorAttributesConfig.java │ │ │ │ └── SwaggerConfig.java │ │ │ │ ├── rest │ │ │ │ ├── AuthController.java │ │ │ │ ├── BookController.java │ │ │ │ ├── PublicController.java │ │ │ │ ├── UserController.java │ │ │ │ └── dto │ │ │ │ │ ├── AuthResponse.java │ │ │ │ │ ├── BookDto.java │ │ │ │ │ ├── CreateBookRequest.java │ │ │ │ │ ├── LoginRequest.java │ │ │ │ │ ├── SignUpRequest.java │ │ │ │ │ └── UserDto.java │ │ │ │ ├── runner │ │ │ │ └── DatabaseInitializer.java │ │ │ │ ├── security │ │ │ │ ├── CorsConfig.java │ │ │ │ ├── CustomUserDetails.java │ │ │ │ ├── CustomUserDetailsService.java │ │ │ │ └── SecurityConfig.java │ │ │ │ └── user │ │ │ │ ├── DuplicatedUserInfoException.java │ │ │ │ ├── User.java │ │ │ │ ├── UserNotFoundException.java │ │ │ │ ├── UserRepository.java │ │ │ │ ├── UserService.java │ │ │ │ └── UserServiceImpl.java │ │ └── resources │ │ │ ├── application.yml │ │ │ └── banner.txt │ └── test │ │ └── java │ │ └── com │ │ └── ivanfranchin │ │ └── bookapi │ │ └── BookApiApplicationTests.java └── test-endpoints.sh ├── book-ui ├── package-lock.json ├── package.json ├── public │ ├── favicon.ico │ ├── index.html │ ├── manifest.json │ └── robots.txt └── src │ ├── App.js │ ├── Constants.js │ ├── components │ ├── admin │ │ ├── AdminPage.js │ │ ├── AdminTab.js │ │ ├── BookForm.js │ │ ├── BookTable.js │ │ └── UserTable.js │ ├── context │ │ └── AuthContext.js │ ├── home │ │ ├── Home.js │ │ ├── Login.js │ │ └── Signup.js │ ├── misc │ │ ├── BookApi.js │ │ ├── Helpers.js │ │ ├── Navbar.js │ │ └── PrivateRoute.js │ └── user │ │ ├── BookList.js │ │ └── UserPage.js │ ├── index.css │ ├── index.js │ ├── reportWebVitals.js │ └── setupTests.js ├── docker-compose.yml └── documentation ├── admin-login.gif ├── project-diagram.excalidraw ├── project-diagram.jpeg └── user-login.gif /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: ivangfr 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | !**/src/main/**/target/ 4 | !**/src/test/**/target/ 5 | 6 | ### STS ### 7 | .apt_generated 8 | .classpath 9 | .factorypath 10 | .project 11 | .settings 12 | .springBeans 13 | .sts4-cache 14 | 15 | ### IntelliJ IDEA ### 16 | .idea 17 | *.iws 18 | *.iml 19 | *.ipr 20 | 21 | ### NetBeans ### 22 | /nbproject/private/ 23 | /nbbuild/ 24 | /dist/ 25 | /nbdist/ 26 | /.nb-gradle/ 27 | build/ 28 | !**/src/main/**/build/ 29 | !**/src/test/**/build/ 30 | 31 | ### VS Code ### 32 | .vscode/ 33 | 34 | ## --- 35 | ## React project 36 | 37 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 38 | 39 | # dependencies 40 | node_modules/ 41 | /.pnp 42 | .pnp.js 43 | 44 | # testing 45 | coverage/ 46 | 47 | # production 48 | build/ 49 | 50 | # misc 51 | .env.local 52 | .env.development.local 53 | .env.test.local 54 | .env.production.local 55 | 56 | npm-debug.log* 57 | yarn-debug.log* 58 | yarn-error.log* 59 | 60 | .eslintcache 61 | 62 | ### MAC OS ### 63 | *.DS_Store 64 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # springboot-react-basic-auth 2 | 3 | The goal of this project is to implement an application called `book-app` to manage books. For it, we will implement a back-end [`Spring Boot`](https://docs.spring.io/spring-boot/index.html) application called `book-api` and a font-end [React](https://react.dev/) application called `book-ui`. Besides, we will use [`Basic Authentication`](https://en.wikipedia.org/wiki/Basic_access_authentication) to secure both applications. 4 | 5 | ## Proof-of-Concepts & Articles 6 | 7 | On [ivangfr.github.io](https://ivangfr.github.io), I have compiled my Proof-of-Concepts (PoCs) and articles. You can easily search for the technology you are interested in by using the filter. Who knows, perhaps I have already implemented a PoC or written an article about what you are looking for. 8 | 9 | ## Additional Readings 10 | 11 | - \[**Medium**\] [**Implementing A Full Stack Web App Using Spring-Boot and React**](https://medium.com/@ivangfr/implementing-a-full-stack-web-app-using-spring-boot-and-react-7db598df4452) 12 | - \[**Medium**\] [**Implementing Social Login in a Spring Boot and React App**](https://medium.com/@ivangfr/implementing-social-login-in-a-spring-boot-and-react-app-6ce073c9983c) 13 | - \[**Medium**\] [**Building a Web Chat with Social Login using Spring Boot: Introduction**](https://medium.com/@ivangfr/building-a-web-chat-with-social-login-using-spring-boot-introduction-644702e6be8e) 14 | - \[**Medium**\] [**Building a Single Spring Boot App with Keycloak or Okta as IdP: Introduction**](https://medium.com/@ivangfr/building-a-single-spring-boot-app-with-keycloak-or-okta-as-idp-introduction-2814a4829aed) 15 | 16 | ## Project Diagram 17 | 18 | ![project-diagram](documentation/project-diagram.jpeg) 19 | 20 | ## Applications 21 | 22 | - ### book-api 23 | 24 | `Spring Boot` Web Java backend application that exposes a Rest API to create, retrieve and delete books. If a user has `ADMIN` role he/she can also retrieve information of other users or delete them. 25 | 26 | The application's secured endpoints can only be accessed if a user has valid credentials (`username` and `password`) and has authorization roles for it. 27 | 28 | `book-api` stores its data in a [`Postgres`](https://www.postgresql.org/) database. 29 | 30 | `book-api` has the following endpoints: 31 | 32 | | Endpoint | Secured | Roles | 33 | | ------------------------------------------------------------- | ------- | --------------- | 34 | | `POST /auth/authenticate -d {"username","password"}` | No | | 35 | | `POST /auth/signup -d {"username","password","name","email"}` | No | | 36 | | `GET /public/numberOfUsers` | No | | 37 | | `GET /public/numberOfBooks` | No | | 38 | | `GET /api/users/me` | Yes | `ADMIN`, `USER` | 39 | | `GET /api/users` | Yes | `ADMIN` | 40 | | `GET /api/users/{username}` | Yes | `ADMIN` | 41 | | `DELETE /api/users/{username}` | Yes | `ADMIN` | 42 | | `GET /api/books [?text]` | Yes | `ADMIN`, `USER` | 43 | | `POST /api/books -d {"isbn","title"}` | Yes | `ADMIN` | 44 | | `DELETE /api/books/{isbn}` | Yes | `ADMIN` | 45 | 46 | - ### book-ui 47 | 48 | `React` frontend application where a user with role `USER` can retrieve the information of a specific book or a list of books. On the other hand, a user with role `ADMIN` has access to all secured endpoints. 49 | 50 | To log in, a `user` or `admin` must provide valid `username` and `password` credentials. `book-ui` communicates with `book-api` to get `books` and `users` data. 51 | 52 | `book-ui` uses [`Semantic UI React`](https://react.semantic-ui.com/) as CSS-styled framework. 53 | 54 | ## Prerequisites 55 | 56 | - [`npm`](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm) 57 | - [`Java 21`](https://www.oracle.com/java/technologies/downloads/#java21) or higher; 58 | - A containerization tool (e.g., [`Docker`](https://www.docker.com), [`Podman`](https://podman.io), etc.) 59 | 60 | ## Start Environment 61 | 62 | - In a terminal, make sure you are inside the `springboot-react-basic-auth` root folder; 63 | 64 | - Run the following command to start docker compose containers: 65 | ```bash 66 | docker compose up -d 67 | ``` 68 | 69 | ## Running book-app using Maven & Npm 70 | 71 | - **book-api** 72 | 73 | - Open a terminal and navigate to the `springboot-react-basic-auth/book-api` folder; 74 | 75 | - Run the following `Maven` command to start the application: 76 | ```bash 77 | ./mvnw clean spring-boot:run 78 | ``` 79 | 80 | - **book-ui** 81 | 82 | - Open another terminal and navigate to the `springboot-react-basic-auth/book-ui` folder; 83 | 84 | - Run the command below if you are running the application for the first time: 85 | ```bash 86 | npm install 87 | ``` 88 | 89 | - Run the `npm` command below to start the application: 90 | ```bash 91 | npm start 92 | ``` 93 | 94 | ## Applications URLs 95 | 96 | | Application | URL | Credentials | 97 | | ----------- | ------------------------------------- | --------------------------------------------------- | 98 | | book-api | http://localhost:8080/swagger-ui.html | | 99 | | book-ui | http://localhost:3000 | `admin/admin`, `user/user` or signing up a new user | 100 | 101 | > **Note**: the credentials shown in the table are the ones already pre-defined. You can signup new users. 102 | 103 | ## Demo 104 | 105 | - The gif below shows a `user` logging in: 106 | 107 | ![user-login](documentation/user-login.gif) 108 | 109 | - The gif below shows an `admin` logging in: 110 | 111 | ![admin-login](documentation/admin-login.gif) 112 | 113 | ## Testing book-api Endpoints 114 | 115 | - **Manual Endpoints Test using Swagger** 116 | 117 | - Open a browser and access http://localhost:8080/swagger-ui.html. All endpoints with the lock sign are secured. In order to access them, you need a valid `username` and `password` credentials; 118 | 119 | - Click `Authorize` button (white/green one, almost at the top of the page, right side); 120 | 121 | - In the `Basic authentication` form that will open, provide the `admin` credentials (`admin/admin`) or `user` ones (`user/user`). Then, click `Authorize` and, finally, click `Close` button; 122 | 123 | - Make some calls to the endpoints. 124 | 125 | - **Manual Endpoints Test using curl** 126 | 127 | - Open a terminal: 128 | 129 | - Call `GET /public/numberOfBooks`: 130 | ```bash 131 | curl -i localhost:8080/public/numberOfBooks 132 | ``` 133 | It should return 134 | ```text 135 | HTTP/1.1 200 136 | 70 137 | ``` 138 | 139 | - Call `GET /api/books` without credentials: 140 | ```bash 141 | curl -i localhost:8080/api/books 142 | ``` 143 | As this endpoint requires authentication, it should return: 144 | ```text 145 | HTTP/1.1 401 146 | { "timestamp": "...", "status": 401, "error": "Unauthorized", "message": "Unauthorized", "path": "/api/books" } 147 | ``` 148 | 149 | - Call again `GET /api/books` but now with `user` credentials: 150 | ```bash 151 | curl -i -u user:user localhost:8080/api/books 152 | ``` 153 | It should return: 154 | ```text 155 | HTTP/1.1 200 156 | [ 157 | {"isbn":"978-1-60309-445-0","title":"A Shining Beacon"}, 158 | {"isbn":"978-1-891830-85-3","title":"American Elf (Book 2)"}, 159 | ... 160 | ] 161 | ``` 162 | 163 | - Call `POST /api/books` with `user` credentials: 164 | ```bash 165 | curl -i -u user:user -X POST localhost:8080/api/books \ 166 | -H "Content-Type: application/json" -d '{"isbn": "9781617292545", "title": "Spring Boot in Action"}' 167 | ``` 168 | As `user` doesn't have the role `ADMIN`, it should return: 169 | ```text 170 | HTTP/1.1 403 171 | { "timestamp": "...", "status": 403, "error": "Forbidden", "message": "Forbidden", "path": "/api/books" } 172 | ``` 173 | 174 | - Call `POST /api/books` with `admin` credentials: 175 | ```bash 176 | curl -i -u admin:admin -X POST localhost:8080/api/books \ 177 | -H "Content-Type: application/json" -d '{"isbn": "9781617292545", "title": "Spring Boot in Action"}' 178 | ``` 179 | It should return: 180 | ```text 181 | HTTP/1.1 201 182 | { "isbn":"9781617292545","title":"Spring Boot in Action" } 183 | ``` 184 | 185 | - **Automatic Endpoints Test** 186 | 187 | - Open a terminal and make sure you are in the `springboot-react-basic-auth` root folder; 188 | 189 | - Run the following script: 190 | ```bash 191 | ./book-api/test-endpoints.sh 192 | ``` 193 | It should return something like the output below, where it shows the http code for different requests: 194 | ```text 195 | POST auth/authenticate 196 | ====================== 197 | admin Auth Resp: {"id":1,"name":"Admin","role":"ADMIN"} 198 | 199 | POST auth/authenticate 200 | ====================== 201 | user Auth Resp: {"id":2,"name":"User","role":"USER"} 202 | 203 | POST auth/signup 204 | ================ 205 | user2 Auth Resp: {"id":3,"name":"User2","role":"USER"} 206 | 207 | Authorization 208 | ============= 209 | Endpoints | without creds | user creds | admin creds | 210 | ------------------------- + ------------- + ----------- + ------------ | 211 | GET public/numberOfUsers | 200 | 200 | 200 | 212 | GET public/numberOfBooks | 200 | 200 | 200 | 213 | ......................... + ............. + ........... + ............ | 214 | GET /api/users/me | 401 | 200 | 200 | 215 | GET /api/users | 401 | 403 | 200 | 216 | GET /api/users/user2 | 401 | 403 | 200 | 217 | DELETE /api/users/user2 | 401 | 403 | 200 | 218 | ......................... + ............. + ........... + ............ | 219 | GET /api/books | 401 | 200 | 200 | 220 | POST /api/books | 401 | 403 | 201 | 221 | DELETE /api/books/abc | 401 | 403 | 200 | 222 | ------------------------------------------------------------------------ 223 | [200] Success - [201] Created - [401] Unauthorized - [403] Forbidden 224 | ``` 225 | 226 | ## Util Commands 227 | 228 | - **Postgres** 229 | ```bash 230 | docker exec -it postgres psql -U postgres -d bookdb 231 | \dt 232 | ``` 233 | 234 | ## Shutdown 235 | 236 | - To stop `book-api` and `book-ui`, go to the terminals where they are running and press `Ctrl+C`; 237 | 238 | - To stop and remove Docker Compose containers, network, and volumes, go to a terminal and, inside the `springboot-react-basic-auth` root folder, run the command below: 239 | ```bash 240 | docker compose down -v 241 | ``` 242 | 243 | ## How to upgrade book-ui dependencies to latest version 244 | 245 | - In a terminal, make sure you are in the `springboot-react-basic-auth/book-ui` folder; 246 | 247 | - Run the following commands: 248 | ```bash 249 | npm upgrade 250 | npm i -g npm-check-updates 251 | ncu -u 252 | npm install 253 | ``` 254 | 255 | ## References 256 | 257 | - https://www.taniarascia.com/using-context-api-in-react/ 258 | - https://medium.com/better-programming/building-basic-react-authentication-e20a574d5e71 259 | - https://jasonwatmore.com/post/2018/09/11/react-basic-http-authentication-tutorial-example 260 | -------------------------------------------------------------------------------- /book-api/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | wrapperVersion=3.3.2 18 | distributionType=only-script 19 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.9/apache-maven-3.9.9-bin.zip 20 | -------------------------------------------------------------------------------- /book-api/mvnw: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # ---------------------------------------------------------------------------- 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # ---------------------------------------------------------------------------- 20 | 21 | # ---------------------------------------------------------------------------- 22 | # Apache Maven Wrapper startup batch script, version 3.3.2 23 | # 24 | # Optional ENV vars 25 | # ----------------- 26 | # JAVA_HOME - location of a JDK home dir, required when download maven via java source 27 | # MVNW_REPOURL - repo url base for downloading maven distribution 28 | # MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven 29 | # MVNW_VERBOSE - true: enable verbose log; debug: trace the mvnw script; others: silence the output 30 | # ---------------------------------------------------------------------------- 31 | 32 | set -euf 33 | [ "${MVNW_VERBOSE-}" != debug ] || set -x 34 | 35 | # OS specific support. 36 | native_path() { printf %s\\n "$1"; } 37 | case "$(uname)" in 38 | CYGWIN* | MINGW*) 39 | [ -z "${JAVA_HOME-}" ] || JAVA_HOME="$(cygpath --unix "$JAVA_HOME")" 40 | native_path() { cygpath --path --windows "$1"; } 41 | ;; 42 | esac 43 | 44 | # set JAVACMD and JAVACCMD 45 | set_java_home() { 46 | # For Cygwin and MinGW, ensure paths are in Unix format before anything is touched 47 | if [ -n "${JAVA_HOME-}" ]; then 48 | if [ -x "$JAVA_HOME/jre/sh/java" ]; then 49 | # IBM's JDK on AIX uses strange locations for the executables 50 | JAVACMD="$JAVA_HOME/jre/sh/java" 51 | JAVACCMD="$JAVA_HOME/jre/sh/javac" 52 | else 53 | JAVACMD="$JAVA_HOME/bin/java" 54 | JAVACCMD="$JAVA_HOME/bin/javac" 55 | 56 | if [ ! -x "$JAVACMD" ] || [ ! -x "$JAVACCMD" ]; then 57 | echo "The JAVA_HOME environment variable is not defined correctly, so mvnw cannot run." >&2 58 | echo "JAVA_HOME is set to \"$JAVA_HOME\", but \"\$JAVA_HOME/bin/java\" or \"\$JAVA_HOME/bin/javac\" does not exist." >&2 59 | return 1 60 | fi 61 | fi 62 | else 63 | JAVACMD="$( 64 | 'set' +e 65 | 'unset' -f command 2>/dev/null 66 | 'command' -v java 67 | )" || : 68 | JAVACCMD="$( 69 | 'set' +e 70 | 'unset' -f command 2>/dev/null 71 | 'command' -v javac 72 | )" || : 73 | 74 | if [ ! -x "${JAVACMD-}" ] || [ ! -x "${JAVACCMD-}" ]; then 75 | echo "The java/javac command does not exist in PATH nor is JAVA_HOME set, so mvnw cannot run." >&2 76 | return 1 77 | fi 78 | fi 79 | } 80 | 81 | # hash string like Java String::hashCode 82 | hash_string() { 83 | str="${1:-}" h=0 84 | while [ -n "$str" ]; do 85 | char="${str%"${str#?}"}" 86 | h=$(((h * 31 + $(LC_CTYPE=C printf %d "'$char")) % 4294967296)) 87 | str="${str#?}" 88 | done 89 | printf %x\\n $h 90 | } 91 | 92 | verbose() { :; } 93 | [ "${MVNW_VERBOSE-}" != true ] || verbose() { printf %s\\n "${1-}"; } 94 | 95 | die() { 96 | printf %s\\n "$1" >&2 97 | exit 1 98 | } 99 | 100 | trim() { 101 | # MWRAPPER-139: 102 | # Trims trailing and leading whitespace, carriage returns, tabs, and linefeeds. 103 | # Needed for removing poorly interpreted newline sequences when running in more 104 | # exotic environments such as mingw bash on Windows. 105 | printf "%s" "${1}" | tr -d '[:space:]' 106 | } 107 | 108 | # parse distributionUrl and optional distributionSha256Sum, requires .mvn/wrapper/maven-wrapper.properties 109 | while IFS="=" read -r key value; do 110 | case "${key-}" in 111 | distributionUrl) distributionUrl=$(trim "${value-}") ;; 112 | distributionSha256Sum) distributionSha256Sum=$(trim "${value-}") ;; 113 | esac 114 | done <"${0%/*}/.mvn/wrapper/maven-wrapper.properties" 115 | [ -n "${distributionUrl-}" ] || die "cannot read distributionUrl property in ${0%/*}/.mvn/wrapper/maven-wrapper.properties" 116 | 117 | case "${distributionUrl##*/}" in 118 | maven-mvnd-*bin.*) 119 | MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ 120 | case "${PROCESSOR_ARCHITECTURE-}${PROCESSOR_ARCHITEW6432-}:$(uname -a)" in 121 | *AMD64:CYGWIN* | *AMD64:MINGW*) distributionPlatform=windows-amd64 ;; 122 | :Darwin*x86_64) distributionPlatform=darwin-amd64 ;; 123 | :Darwin*arm64) distributionPlatform=darwin-aarch64 ;; 124 | :Linux*x86_64*) distributionPlatform=linux-amd64 ;; 125 | *) 126 | echo "Cannot detect native platform for mvnd on $(uname)-$(uname -m), use pure java version" >&2 127 | distributionPlatform=linux-amd64 128 | ;; 129 | esac 130 | distributionUrl="${distributionUrl%-bin.*}-$distributionPlatform.zip" 131 | ;; 132 | maven-mvnd-*) MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ ;; 133 | *) MVN_CMD="mvn${0##*/mvnw}" _MVNW_REPO_PATTERN=/org/apache/maven/ ;; 134 | esac 135 | 136 | # apply MVNW_REPOURL and calculate MAVEN_HOME 137 | # maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/ 138 | [ -z "${MVNW_REPOURL-}" ] || distributionUrl="$MVNW_REPOURL$_MVNW_REPO_PATTERN${distributionUrl#*"$_MVNW_REPO_PATTERN"}" 139 | distributionUrlName="${distributionUrl##*/}" 140 | distributionUrlNameMain="${distributionUrlName%.*}" 141 | distributionUrlNameMain="${distributionUrlNameMain%-bin}" 142 | MAVEN_USER_HOME="${MAVEN_USER_HOME:-${HOME}/.m2}" 143 | MAVEN_HOME="${MAVEN_USER_HOME}/wrapper/dists/${distributionUrlNameMain-}/$(hash_string "$distributionUrl")" 144 | 145 | exec_maven() { 146 | unset MVNW_VERBOSE MVNW_USERNAME MVNW_PASSWORD MVNW_REPOURL || : 147 | exec "$MAVEN_HOME/bin/$MVN_CMD" "$@" || die "cannot exec $MAVEN_HOME/bin/$MVN_CMD" 148 | } 149 | 150 | if [ -d "$MAVEN_HOME" ]; then 151 | verbose "found existing MAVEN_HOME at $MAVEN_HOME" 152 | exec_maven "$@" 153 | fi 154 | 155 | case "${distributionUrl-}" in 156 | *?-bin.zip | *?maven-mvnd-?*-?*.zip) ;; 157 | *) die "distributionUrl is not valid, must match *-bin.zip or maven-mvnd-*.zip, but found '${distributionUrl-}'" ;; 158 | esac 159 | 160 | # prepare tmp dir 161 | if TMP_DOWNLOAD_DIR="$(mktemp -d)" && [ -d "$TMP_DOWNLOAD_DIR" ]; then 162 | clean() { rm -rf -- "$TMP_DOWNLOAD_DIR"; } 163 | trap clean HUP INT TERM EXIT 164 | else 165 | die "cannot create temp dir" 166 | fi 167 | 168 | mkdir -p -- "${MAVEN_HOME%/*}" 169 | 170 | # Download and Install Apache Maven 171 | verbose "Couldn't find MAVEN_HOME, downloading and installing it ..." 172 | verbose "Downloading from: $distributionUrl" 173 | verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName" 174 | 175 | # select .zip or .tar.gz 176 | if ! command -v unzip >/dev/null; then 177 | distributionUrl="${distributionUrl%.zip}.tar.gz" 178 | distributionUrlName="${distributionUrl##*/}" 179 | fi 180 | 181 | # verbose opt 182 | __MVNW_QUIET_WGET=--quiet __MVNW_QUIET_CURL=--silent __MVNW_QUIET_UNZIP=-q __MVNW_QUIET_TAR='' 183 | [ "${MVNW_VERBOSE-}" != true ] || __MVNW_QUIET_WGET='' __MVNW_QUIET_CURL='' __MVNW_QUIET_UNZIP='' __MVNW_QUIET_TAR=v 184 | 185 | # normalize http auth 186 | case "${MVNW_PASSWORD:+has-password}" in 187 | '') MVNW_USERNAME='' MVNW_PASSWORD='' ;; 188 | has-password) [ -n "${MVNW_USERNAME-}" ] || MVNW_USERNAME='' MVNW_PASSWORD='' ;; 189 | esac 190 | 191 | if [ -z "${MVNW_USERNAME-}" ] && command -v wget >/dev/null; then 192 | verbose "Found wget ... using wget" 193 | wget ${__MVNW_QUIET_WGET:+"$__MVNW_QUIET_WGET"} "$distributionUrl" -O "$TMP_DOWNLOAD_DIR/$distributionUrlName" || die "wget: Failed to fetch $distributionUrl" 194 | elif [ -z "${MVNW_USERNAME-}" ] && command -v curl >/dev/null; then 195 | verbose "Found curl ... using curl" 196 | curl ${__MVNW_QUIET_CURL:+"$__MVNW_QUIET_CURL"} -f -L -o "$TMP_DOWNLOAD_DIR/$distributionUrlName" "$distributionUrl" || die "curl: Failed to fetch $distributionUrl" 197 | elif set_java_home; then 198 | verbose "Falling back to use Java to download" 199 | javaSource="$TMP_DOWNLOAD_DIR/Downloader.java" 200 | targetZip="$TMP_DOWNLOAD_DIR/$distributionUrlName" 201 | cat >"$javaSource" <<-END 202 | public class Downloader extends java.net.Authenticator 203 | { 204 | protected java.net.PasswordAuthentication getPasswordAuthentication() 205 | { 206 | return new java.net.PasswordAuthentication( System.getenv( "MVNW_USERNAME" ), System.getenv( "MVNW_PASSWORD" ).toCharArray() ); 207 | } 208 | public static void main( String[] args ) throws Exception 209 | { 210 | setDefault( new Downloader() ); 211 | java.nio.file.Files.copy( java.net.URI.create( args[0] ).toURL().openStream(), java.nio.file.Paths.get( args[1] ).toAbsolutePath().normalize() ); 212 | } 213 | } 214 | END 215 | # For Cygwin/MinGW, switch paths to Windows format before running javac and java 216 | verbose " - Compiling Downloader.java ..." 217 | "$(native_path "$JAVACCMD")" "$(native_path "$javaSource")" || die "Failed to compile Downloader.java" 218 | verbose " - Running Downloader.java ..." 219 | "$(native_path "$JAVACMD")" -cp "$(native_path "$TMP_DOWNLOAD_DIR")" Downloader "$distributionUrl" "$(native_path "$targetZip")" 220 | fi 221 | 222 | # If specified, validate the SHA-256 sum of the Maven distribution zip file 223 | if [ -n "${distributionSha256Sum-}" ]; then 224 | distributionSha256Result=false 225 | if [ "$MVN_CMD" = mvnd.sh ]; then 226 | echo "Checksum validation is not supported for maven-mvnd." >&2 227 | echo "Please disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2 228 | exit 1 229 | elif command -v sha256sum >/dev/null; then 230 | if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | sha256sum -c >/dev/null 2>&1; then 231 | distributionSha256Result=true 232 | fi 233 | elif command -v shasum >/dev/null; then 234 | if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | shasum -a 256 -c >/dev/null 2>&1; then 235 | distributionSha256Result=true 236 | fi 237 | else 238 | echo "Checksum validation was requested but neither 'sha256sum' or 'shasum' are available." >&2 239 | echo "Please install either command, or disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2 240 | exit 1 241 | fi 242 | if [ $distributionSha256Result = false ]; then 243 | echo "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised." >&2 244 | echo "If you updated your Maven version, you need to update the specified distributionSha256Sum property." >&2 245 | exit 1 246 | fi 247 | fi 248 | 249 | # unzip and move 250 | if command -v unzip >/dev/null; then 251 | unzip ${__MVNW_QUIET_UNZIP:+"$__MVNW_QUIET_UNZIP"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -d "$TMP_DOWNLOAD_DIR" || die "failed to unzip" 252 | else 253 | tar xzf${__MVNW_QUIET_TAR:+"$__MVNW_QUIET_TAR"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -C "$TMP_DOWNLOAD_DIR" || die "failed to untar" 254 | fi 255 | printf %s\\n "$distributionUrl" >"$TMP_DOWNLOAD_DIR/$distributionUrlNameMain/mvnw.url" 256 | mv -- "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" "$MAVEN_HOME" || [ -d "$MAVEN_HOME" ] || die "fail to move MAVEN_HOME" 257 | 258 | clean || : 259 | exec_maven "$@" 260 | -------------------------------------------------------------------------------- /book-api/mvnw.cmd: -------------------------------------------------------------------------------- 1 | <# : batch portion 2 | @REM ---------------------------------------------------------------------------- 3 | @REM Licensed to the Apache Software Foundation (ASF) under one 4 | @REM or more contributor license agreements. See the NOTICE file 5 | @REM distributed with this work for additional information 6 | @REM regarding copyright ownership. The ASF licenses this file 7 | @REM to you under the Apache License, Version 2.0 (the 8 | @REM "License"); you may not use this file except in compliance 9 | @REM with the License. You may obtain a copy of the License at 10 | @REM 11 | @REM http://www.apache.org/licenses/LICENSE-2.0 12 | @REM 13 | @REM Unless required by applicable law or agreed to in writing, 14 | @REM software distributed under the License is distributed on an 15 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | @REM KIND, either express or implied. See the License for the 17 | @REM specific language governing permissions and limitations 18 | @REM under the License. 19 | @REM ---------------------------------------------------------------------------- 20 | 21 | @REM ---------------------------------------------------------------------------- 22 | @REM Apache Maven Wrapper startup batch script, version 3.3.2 23 | @REM 24 | @REM Optional ENV vars 25 | @REM MVNW_REPOURL - repo url base for downloading maven distribution 26 | @REM MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven 27 | @REM MVNW_VERBOSE - true: enable verbose log; others: silence the output 28 | @REM ---------------------------------------------------------------------------- 29 | 30 | @IF "%__MVNW_ARG0_NAME__%"=="" (SET __MVNW_ARG0_NAME__=%~nx0) 31 | @SET __MVNW_CMD__= 32 | @SET __MVNW_ERROR__= 33 | @SET __MVNW_PSMODULEP_SAVE=%PSModulePath% 34 | @SET PSModulePath= 35 | @FOR /F "usebackq tokens=1* delims==" %%A IN (`powershell -noprofile "& {$scriptDir='%~dp0'; $script='%__MVNW_ARG0_NAME__%'; icm -ScriptBlock ([Scriptblock]::Create((Get-Content -Raw '%~f0'))) -NoNewScope}"`) DO @( 36 | IF "%%A"=="MVN_CMD" (set __MVNW_CMD__=%%B) ELSE IF "%%B"=="" (echo %%A) ELSE (echo %%A=%%B) 37 | ) 38 | @SET PSModulePath=%__MVNW_PSMODULEP_SAVE% 39 | @SET __MVNW_PSMODULEP_SAVE= 40 | @SET __MVNW_ARG0_NAME__= 41 | @SET MVNW_USERNAME= 42 | @SET MVNW_PASSWORD= 43 | @IF NOT "%__MVNW_CMD__%"=="" (%__MVNW_CMD__% %*) 44 | @echo Cannot start maven from wrapper >&2 && exit /b 1 45 | @GOTO :EOF 46 | : end batch / begin powershell #> 47 | 48 | $ErrorActionPreference = "Stop" 49 | if ($env:MVNW_VERBOSE -eq "true") { 50 | $VerbosePreference = "Continue" 51 | } 52 | 53 | # calculate distributionUrl, requires .mvn/wrapper/maven-wrapper.properties 54 | $distributionUrl = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionUrl 55 | if (!$distributionUrl) { 56 | Write-Error "cannot read distributionUrl property in $scriptDir/.mvn/wrapper/maven-wrapper.properties" 57 | } 58 | 59 | switch -wildcard -casesensitive ( $($distributionUrl -replace '^.*/','') ) { 60 | "maven-mvnd-*" { 61 | $USE_MVND = $true 62 | $distributionUrl = $distributionUrl -replace '-bin\.[^.]*$',"-windows-amd64.zip" 63 | $MVN_CMD = "mvnd.cmd" 64 | break 65 | } 66 | default { 67 | $USE_MVND = $false 68 | $MVN_CMD = $script -replace '^mvnw','mvn' 69 | break 70 | } 71 | } 72 | 73 | # apply MVNW_REPOURL and calculate MAVEN_HOME 74 | # maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/ 75 | if ($env:MVNW_REPOURL) { 76 | $MVNW_REPO_PATTERN = if ($USE_MVND) { "/org/apache/maven/" } else { "/maven/mvnd/" } 77 | $distributionUrl = "$env:MVNW_REPOURL$MVNW_REPO_PATTERN$($distributionUrl -replace '^.*'+$MVNW_REPO_PATTERN,'')" 78 | } 79 | $distributionUrlName = $distributionUrl -replace '^.*/','' 80 | $distributionUrlNameMain = $distributionUrlName -replace '\.[^.]*$','' -replace '-bin$','' 81 | $MAVEN_HOME_PARENT = "$HOME/.m2/wrapper/dists/$distributionUrlNameMain" 82 | if ($env:MAVEN_USER_HOME) { 83 | $MAVEN_HOME_PARENT = "$env:MAVEN_USER_HOME/wrapper/dists/$distributionUrlNameMain" 84 | } 85 | $MAVEN_HOME_NAME = ([System.Security.Cryptography.MD5]::Create().ComputeHash([byte[]][char[]]$distributionUrl) | ForEach-Object {$_.ToString("x2")}) -join '' 86 | $MAVEN_HOME = "$MAVEN_HOME_PARENT/$MAVEN_HOME_NAME" 87 | 88 | if (Test-Path -Path "$MAVEN_HOME" -PathType Container) { 89 | Write-Verbose "found existing MAVEN_HOME at $MAVEN_HOME" 90 | Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD" 91 | exit $? 92 | } 93 | 94 | if (! $distributionUrlNameMain -or ($distributionUrlName -eq $distributionUrlNameMain)) { 95 | Write-Error "distributionUrl is not valid, must end with *-bin.zip, but found $distributionUrl" 96 | } 97 | 98 | # prepare tmp dir 99 | $TMP_DOWNLOAD_DIR_HOLDER = New-TemporaryFile 100 | $TMP_DOWNLOAD_DIR = New-Item -Itemtype Directory -Path "$TMP_DOWNLOAD_DIR_HOLDER.dir" 101 | $TMP_DOWNLOAD_DIR_HOLDER.Delete() | Out-Null 102 | trap { 103 | if ($TMP_DOWNLOAD_DIR.Exists) { 104 | try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null } 105 | catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" } 106 | } 107 | } 108 | 109 | New-Item -Itemtype Directory -Path "$MAVEN_HOME_PARENT" -Force | Out-Null 110 | 111 | # Download and Install Apache Maven 112 | Write-Verbose "Couldn't find MAVEN_HOME, downloading and installing it ..." 113 | Write-Verbose "Downloading from: $distributionUrl" 114 | Write-Verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName" 115 | 116 | $webclient = New-Object System.Net.WebClient 117 | if ($env:MVNW_USERNAME -and $env:MVNW_PASSWORD) { 118 | $webclient.Credentials = New-Object System.Net.NetworkCredential($env:MVNW_USERNAME, $env:MVNW_PASSWORD) 119 | } 120 | [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 121 | $webclient.DownloadFile($distributionUrl, "$TMP_DOWNLOAD_DIR/$distributionUrlName") | Out-Null 122 | 123 | # If specified, validate the SHA-256 sum of the Maven distribution zip file 124 | $distributionSha256Sum = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionSha256Sum 125 | if ($distributionSha256Sum) { 126 | if ($USE_MVND) { 127 | Write-Error "Checksum validation is not supported for maven-mvnd. `nPlease disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." 128 | } 129 | Import-Module $PSHOME\Modules\Microsoft.PowerShell.Utility -Function Get-FileHash 130 | if ((Get-FileHash "$TMP_DOWNLOAD_DIR/$distributionUrlName" -Algorithm SHA256).Hash.ToLower() -ne $distributionSha256Sum) { 131 | Write-Error "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised. If you updated your Maven version, you need to update the specified distributionSha256Sum property." 132 | } 133 | } 134 | 135 | # unzip and move 136 | Expand-Archive "$TMP_DOWNLOAD_DIR/$distributionUrlName" -DestinationPath "$TMP_DOWNLOAD_DIR" | Out-Null 137 | Rename-Item -Path "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" -NewName $MAVEN_HOME_NAME | Out-Null 138 | try { 139 | Move-Item -Path "$TMP_DOWNLOAD_DIR/$MAVEN_HOME_NAME" -Destination $MAVEN_HOME_PARENT | Out-Null 140 | } catch { 141 | if (! (Test-Path -Path "$MAVEN_HOME" -PathType Container)) { 142 | Write-Error "fail to move MAVEN_HOME" 143 | } 144 | } finally { 145 | try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null } 146 | catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" } 147 | } 148 | 149 | Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD" 150 | -------------------------------------------------------------------------------- /book-api/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 3.5.0 9 | 10 | 11 | com.ivanfranchin 12 | book-api 13 | 0.0.1-SNAPSHOT 14 | book-api 15 | Demo project for Spring Boot 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 21 31 | 2.8.8 32 | 33 | 34 | 35 | org.springframework.boot 36 | spring-boot-starter-data-jpa 37 | 38 | 39 | org.springframework.boot 40 | spring-boot-starter-security 41 | 42 | 43 | org.springframework.boot 44 | spring-boot-starter-validation 45 | 46 | 47 | org.springframework.boot 48 | spring-boot-starter-web 49 | 50 | 51 | 52 | 53 | org.springdoc 54 | springdoc-openapi-starter-webmvc-ui 55 | ${springdoc-openapi.version} 56 | 57 | 58 | 59 | org.postgresql 60 | postgresql 61 | runtime 62 | 63 | 64 | org.projectlombok 65 | lombok 66 | true 67 | 68 | 69 | org.springframework.boot 70 | spring-boot-starter-test 71 | test 72 | 73 | 74 | org.springframework.security 75 | spring-security-test 76 | test 77 | 78 | 79 | 80 | 81 | 82 | 83 | org.apache.maven.plugins 84 | maven-compiler-plugin 85 | 86 | 87 | 88 | org.projectlombok 89 | lombok 90 | 91 | 92 | 93 | 94 | 95 | org.springframework.boot 96 | spring-boot-maven-plugin 97 | 98 | 99 | 100 | org.projectlombok 101 | lombok 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | -------------------------------------------------------------------------------- /book-api/src/main/java/com/ivanfranchin/bookapi/BookApiApplication.java: -------------------------------------------------------------------------------- 1 | package com.ivanfranchin.bookapi; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class BookApiApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(BookApiApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /book-api/src/main/java/com/ivanfranchin/bookapi/book/Book.java: -------------------------------------------------------------------------------- 1 | package com.ivanfranchin.bookapi.book; 2 | 3 | import com.ivanfranchin.bookapi.rest.dto.CreateBookRequest; 4 | import jakarta.persistence.Entity; 5 | import jakarta.persistence.Id; 6 | import jakarta.persistence.Table; 7 | import lombok.AllArgsConstructor; 8 | import lombok.Data; 9 | import lombok.NoArgsConstructor; 10 | 11 | @Data 12 | @NoArgsConstructor 13 | @AllArgsConstructor 14 | @Entity 15 | @Table(name = "books") 16 | public class Book { 17 | 18 | @Id 19 | private String isbn; 20 | 21 | private String title; 22 | 23 | public static Book from(CreateBookRequest createBookRequest) { 24 | return new Book(createBookRequest.isbn(), createBookRequest.title()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /book-api/src/main/java/com/ivanfranchin/bookapi/book/BookNotFoundException.java: -------------------------------------------------------------------------------- 1 | package com.ivanfranchin.bookapi.book; 2 | 3 | import org.springframework.http.HttpStatus; 4 | import org.springframework.web.bind.annotation.ResponseStatus; 5 | 6 | @ResponseStatus(HttpStatus.NOT_FOUND) 7 | public class BookNotFoundException extends RuntimeException { 8 | 9 | public BookNotFoundException(String message) { 10 | super(message); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /book-api/src/main/java/com/ivanfranchin/bookapi/book/BookRepository.java: -------------------------------------------------------------------------------- 1 | package com.ivanfranchin.bookapi.book; 2 | 3 | import org.springframework.data.jpa.repository.JpaRepository; 4 | import org.springframework.stereotype.Repository; 5 | 6 | import java.util.List; 7 | 8 | @Repository 9 | public interface BookRepository extends JpaRepository { 10 | 11 | List findAllByOrderByTitle(); 12 | 13 | List findByIsbnContainingOrTitleContainingIgnoreCaseOrderByTitle(String isbn, String title); 14 | } 15 | -------------------------------------------------------------------------------- /book-api/src/main/java/com/ivanfranchin/bookapi/book/BookService.java: -------------------------------------------------------------------------------- 1 | package com.ivanfranchin.bookapi.book; 2 | 3 | import java.util.List; 4 | 5 | public interface BookService { 6 | 7 | List getBooks(); 8 | 9 | List getBooksContainingText(String text); 10 | 11 | Book validateAndGetBook(String isbn); 12 | 13 | Book saveBook(Book book); 14 | 15 | void deleteBook(Book book); 16 | } 17 | -------------------------------------------------------------------------------- /book-api/src/main/java/com/ivanfranchin/bookapi/book/BookServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.ivanfranchin.bookapi.book; 2 | 3 | import lombok.RequiredArgsConstructor; 4 | import org.springframework.stereotype.Service; 5 | 6 | import java.util.List; 7 | 8 | @RequiredArgsConstructor 9 | @Service 10 | public class BookServiceImpl implements BookService { 11 | 12 | private final BookRepository bookRepository; 13 | 14 | @Override 15 | public List getBooks() { 16 | return bookRepository.findAllByOrderByTitle(); 17 | } 18 | 19 | @Override 20 | public List getBooksContainingText(String text) { 21 | return bookRepository.findByIsbnContainingOrTitleContainingIgnoreCaseOrderByTitle(text, text); 22 | } 23 | 24 | @Override 25 | public Book validateAndGetBook(String isbn) { 26 | return bookRepository.findById(isbn) 27 | .orElseThrow(() -> new BookNotFoundException(String.format("Book with isbn %s not found", isbn))); 28 | } 29 | 30 | @Override 31 | public Book saveBook(Book book) { 32 | return bookRepository.save(book); 33 | } 34 | 35 | @Override 36 | public void deleteBook(Book book) { 37 | bookRepository.delete(book); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /book-api/src/main/java/com/ivanfranchin/bookapi/config/ErrorAttributesConfig.java: -------------------------------------------------------------------------------- 1 | package com.ivanfranchin.bookapi.config; 2 | 3 | import org.springframework.boot.web.error.ErrorAttributeOptions; 4 | import org.springframework.boot.web.error.ErrorAttributeOptions.Include; 5 | import org.springframework.boot.web.servlet.error.DefaultErrorAttributes; 6 | import org.springframework.boot.web.servlet.error.ErrorAttributes; 7 | import org.springframework.context.annotation.Bean; 8 | import org.springframework.context.annotation.Configuration; 9 | import org.springframework.web.context.request.WebRequest; 10 | 11 | import java.util.Map; 12 | 13 | @Configuration 14 | public class ErrorAttributesConfig { 15 | 16 | @Bean 17 | ErrorAttributes errorAttributes() { 18 | return new DefaultErrorAttributes() { 19 | @Override 20 | public Map getErrorAttributes(WebRequest webRequest, ErrorAttributeOptions options) { 21 | return super.getErrorAttributes(webRequest, options.including(Include.EXCEPTION, Include.MESSAGE, Include.BINDING_ERRORS)); 22 | } 23 | }; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /book-api/src/main/java/com/ivanfranchin/bookapi/config/SwaggerConfig.java: -------------------------------------------------------------------------------- 1 | package com.ivanfranchin.bookapi.config; 2 | 3 | import io.swagger.v3.oas.models.Components; 4 | import io.swagger.v3.oas.models.OpenAPI; 5 | import io.swagger.v3.oas.models.info.Info; 6 | import io.swagger.v3.oas.models.security.SecurityScheme; 7 | import org.springframework.beans.factory.annotation.Value; 8 | import org.springframework.context.annotation.Bean; 9 | import org.springframework.context.annotation.Configuration; 10 | 11 | @Configuration 12 | public class SwaggerConfig { 13 | 14 | @Value("${spring.application.name}") 15 | private String applicationName; 16 | 17 | @Bean 18 | OpenAPI customOpenAPI() { 19 | return new OpenAPI() 20 | .components( 21 | new Components().addSecuritySchemes(BASIC_AUTH_SECURITY_SCHEME, 22 | new SecurityScheme().type(SecurityScheme.Type.HTTP).scheme("basic"))) 23 | .info(new Info().title(applicationName)); 24 | } 25 | 26 | public static final String BASIC_AUTH_SECURITY_SCHEME = "basicAuth"; 27 | } 28 | -------------------------------------------------------------------------------- /book-api/src/main/java/com/ivanfranchin/bookapi/rest/AuthController.java: -------------------------------------------------------------------------------- 1 | package com.ivanfranchin.bookapi.rest; 2 | 3 | import com.ivanfranchin.bookapi.rest.dto.AuthResponse; 4 | import com.ivanfranchin.bookapi.rest.dto.LoginRequest; 5 | import com.ivanfranchin.bookapi.rest.dto.SignUpRequest; 6 | import com.ivanfranchin.bookapi.security.SecurityConfig; 7 | import com.ivanfranchin.bookapi.user.DuplicatedUserInfoException; 8 | import com.ivanfranchin.bookapi.user.User; 9 | import com.ivanfranchin.bookapi.user.UserService; 10 | import jakarta.validation.Valid; 11 | import lombok.RequiredArgsConstructor; 12 | import org.springframework.http.HttpStatus; 13 | import org.springframework.http.ResponseEntity; 14 | import org.springframework.security.crypto.password.PasswordEncoder; 15 | import org.springframework.web.bind.annotation.PostMapping; 16 | import org.springframework.web.bind.annotation.RequestBody; 17 | import org.springframework.web.bind.annotation.RequestMapping; 18 | import org.springframework.web.bind.annotation.ResponseStatus; 19 | import org.springframework.web.bind.annotation.RestController; 20 | 21 | import java.util.Optional; 22 | 23 | @RequiredArgsConstructor 24 | @RestController 25 | @RequestMapping("/auth") 26 | public class AuthController { 27 | 28 | private final UserService userService; 29 | private final PasswordEncoder passwordEncoder; 30 | 31 | @PostMapping("/authenticate") 32 | public ResponseEntity login(@Valid @RequestBody LoginRequest loginRequest) { 33 | Optional userOptional = userService.validUsernameAndPassword(loginRequest.username(), loginRequest.password()); 34 | if (userOptional.isPresent()) { 35 | User user = userOptional.get(); 36 | return ResponseEntity.ok(new AuthResponse(user.getId(), user.getName(), user.getRole())); 37 | } 38 | return ResponseEntity.status(HttpStatus.UNAUTHORIZED).build(); 39 | } 40 | 41 | @ResponseStatus(HttpStatus.CREATED) 42 | @PostMapping("/signup") 43 | public AuthResponse signUp(@Valid @RequestBody SignUpRequest signUpRequest) { 44 | if (userService.hasUserWithUsername(signUpRequest.username())) { 45 | throw new DuplicatedUserInfoException(String.format("Username %s is already been used", signUpRequest.username())); 46 | } 47 | if (userService.hasUserWithEmail(signUpRequest.email())) { 48 | throw new DuplicatedUserInfoException(String.format("Email %s is already been used", signUpRequest.email())); 49 | } 50 | 51 | User user = userService.saveUser(this.mapSignUpRequestToUser(signUpRequest)); 52 | return new AuthResponse(user.getId(), user.getName(), user.getRole()); 53 | } 54 | 55 | private User mapSignUpRequestToUser(SignUpRequest signUpRequest) { 56 | User user = new User(); 57 | user.setUsername(signUpRequest.username()); 58 | user.setPassword(passwordEncoder.encode(signUpRequest.password())); 59 | user.setName(signUpRequest.name()); 60 | user.setEmail(signUpRequest.email()); 61 | user.setRole(SecurityConfig.USER); 62 | return user; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /book-api/src/main/java/com/ivanfranchin/bookapi/rest/BookController.java: -------------------------------------------------------------------------------- 1 | package com.ivanfranchin.bookapi.rest; 2 | 3 | import com.ivanfranchin.bookapi.book.Book; 4 | import com.ivanfranchin.bookapi.rest.dto.BookDto; 5 | import com.ivanfranchin.bookapi.rest.dto.CreateBookRequest; 6 | import com.ivanfranchin.bookapi.book.BookService; 7 | import io.swagger.v3.oas.annotations.Operation; 8 | import io.swagger.v3.oas.annotations.security.SecurityRequirement; 9 | import jakarta.validation.Valid; 10 | import lombok.RequiredArgsConstructor; 11 | import org.springframework.http.HttpStatus; 12 | import org.springframework.web.bind.annotation.DeleteMapping; 13 | import org.springframework.web.bind.annotation.GetMapping; 14 | import org.springframework.web.bind.annotation.PathVariable; 15 | import org.springframework.web.bind.annotation.PostMapping; 16 | import org.springframework.web.bind.annotation.RequestBody; 17 | import org.springframework.web.bind.annotation.RequestMapping; 18 | import org.springframework.web.bind.annotation.RequestParam; 19 | import org.springframework.web.bind.annotation.ResponseStatus; 20 | import org.springframework.web.bind.annotation.RestController; 21 | 22 | import java.util.List; 23 | import java.util.stream.Collectors; 24 | 25 | import static com.ivanfranchin.bookapi.config.SwaggerConfig.BASIC_AUTH_SECURITY_SCHEME; 26 | 27 | @RequiredArgsConstructor 28 | @RestController 29 | @RequestMapping("/api/books") 30 | public class BookController { 31 | 32 | private final BookService bookService; 33 | 34 | @Operation(security = {@SecurityRequirement(name = BASIC_AUTH_SECURITY_SCHEME)}) 35 | @GetMapping 36 | public List getBooks(@RequestParam(value = "text", required = false) String text) { 37 | List books = (text == null) ? bookService.getBooks() : bookService.getBooksContainingText(text); 38 | return books.stream() 39 | .map(BookDto::from) 40 | .collect(Collectors.toList()); 41 | } 42 | 43 | @Operation(security = {@SecurityRequirement(name = BASIC_AUTH_SECURITY_SCHEME)}) 44 | @ResponseStatus(HttpStatus.CREATED) 45 | @PostMapping 46 | public BookDto createBook(@Valid @RequestBody CreateBookRequest createBookRequest) { 47 | Book book = Book.from(createBookRequest); 48 | return BookDto.from(bookService.saveBook(book)); 49 | } 50 | 51 | @Operation(security = {@SecurityRequirement(name = BASIC_AUTH_SECURITY_SCHEME)}) 52 | @DeleteMapping("/{isbn}") 53 | public BookDto deleteBook(@PathVariable String isbn) { 54 | Book book = bookService.validateAndGetBook(isbn); 55 | bookService.deleteBook(book); 56 | return BookDto.from(book); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /book-api/src/main/java/com/ivanfranchin/bookapi/rest/PublicController.java: -------------------------------------------------------------------------------- 1 | package com.ivanfranchin.bookapi.rest; 2 | 3 | import com.ivanfranchin.bookapi.book.BookService; 4 | import com.ivanfranchin.bookapi.user.UserService; 5 | import lombok.RequiredArgsConstructor; 6 | import org.springframework.web.bind.annotation.GetMapping; 7 | import org.springframework.web.bind.annotation.RequestMapping; 8 | import org.springframework.web.bind.annotation.RestController; 9 | 10 | @RequiredArgsConstructor 11 | @RestController 12 | @RequestMapping("/public") 13 | public class PublicController { 14 | 15 | private final UserService userService; 16 | private final BookService bookService; 17 | 18 | @GetMapping("/numberOfUsers") 19 | public Integer getNumberOfUsers() { 20 | return userService.getUsers().size(); 21 | } 22 | 23 | @GetMapping("/numberOfBooks") 24 | public Integer getNumberOfBooks() { 25 | return bookService.getBooks().size(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /book-api/src/main/java/com/ivanfranchin/bookapi/rest/UserController.java: -------------------------------------------------------------------------------- 1 | package com.ivanfranchin.bookapi.rest; 2 | 3 | import com.ivanfranchin.bookapi.user.User; 4 | import com.ivanfranchin.bookapi.rest.dto.UserDto; 5 | import com.ivanfranchin.bookapi.security.CustomUserDetails; 6 | import com.ivanfranchin.bookapi.user.UserService; 7 | import io.swagger.v3.oas.annotations.Operation; 8 | import io.swagger.v3.oas.annotations.security.SecurityRequirement; 9 | import lombok.RequiredArgsConstructor; 10 | import org.springframework.security.core.annotation.AuthenticationPrincipal; 11 | import org.springframework.web.bind.annotation.DeleteMapping; 12 | import org.springframework.web.bind.annotation.GetMapping; 13 | import org.springframework.web.bind.annotation.PathVariable; 14 | import org.springframework.web.bind.annotation.RequestMapping; 15 | import org.springframework.web.bind.annotation.RestController; 16 | 17 | import java.util.List; 18 | import java.util.stream.Collectors; 19 | 20 | import static com.ivanfranchin.bookapi.config.SwaggerConfig.BASIC_AUTH_SECURITY_SCHEME; 21 | 22 | @RequiredArgsConstructor 23 | @RestController 24 | @RequestMapping("/api/users") 25 | public class UserController { 26 | 27 | private final UserService userService; 28 | 29 | @Operation(security = {@SecurityRequirement(name = BASIC_AUTH_SECURITY_SCHEME)}) 30 | @GetMapping("/me") 31 | public UserDto getCurrentUser(@AuthenticationPrincipal CustomUserDetails currentUser) { 32 | return UserDto.from(userService.validateAndGetUserByUsername(currentUser.getUsername())); 33 | } 34 | 35 | @Operation(security = {@SecurityRequirement(name = BASIC_AUTH_SECURITY_SCHEME)}) 36 | @GetMapping 37 | public List getUsers() { 38 | return userService.getUsers().stream() 39 | .map(UserDto::from) 40 | .collect(Collectors.toList()); 41 | } 42 | 43 | @Operation(security = {@SecurityRequirement(name = BASIC_AUTH_SECURITY_SCHEME)}) 44 | @GetMapping("/{username}") 45 | public UserDto getUser(@PathVariable String username) { 46 | return UserDto.from(userService.validateAndGetUserByUsername(username)); 47 | } 48 | 49 | @Operation(security = {@SecurityRequirement(name = BASIC_AUTH_SECURITY_SCHEME)}) 50 | @DeleteMapping("/{username}") 51 | public UserDto deleteUser(@PathVariable String username) { 52 | User user = userService.validateAndGetUserByUsername(username); 53 | userService.deleteUser(user); 54 | return UserDto.from(user); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /book-api/src/main/java/com/ivanfranchin/bookapi/rest/dto/AuthResponse.java: -------------------------------------------------------------------------------- 1 | package com.ivanfranchin.bookapi.rest.dto; 2 | 3 | public record AuthResponse(Long id, String name, String role) { 4 | } 5 | -------------------------------------------------------------------------------- /book-api/src/main/java/com/ivanfranchin/bookapi/rest/dto/BookDto.java: -------------------------------------------------------------------------------- 1 | package com.ivanfranchin.bookapi.rest.dto; 2 | 3 | import com.ivanfranchin.bookapi.book.Book; 4 | 5 | public record BookDto(String isbn, String title) { 6 | 7 | public static BookDto from(Book book) { 8 | return new BookDto(book.getIsbn(), book.getTitle()); 9 | } 10 | } -------------------------------------------------------------------------------- /book-api/src/main/java/com/ivanfranchin/bookapi/rest/dto/CreateBookRequest.java: -------------------------------------------------------------------------------- 1 | package com.ivanfranchin.bookapi.rest.dto; 2 | 3 | import io.swagger.v3.oas.annotations.media.Schema; 4 | import jakarta.validation.constraints.NotBlank; 5 | 6 | public record CreateBookRequest( 7 | @Schema(example = "9781849518260") @NotBlank String isbn, 8 | @Schema(example = "Spring Security 3.1") @NotBlank String title) { 9 | } 10 | -------------------------------------------------------------------------------- /book-api/src/main/java/com/ivanfranchin/bookapi/rest/dto/LoginRequest.java: -------------------------------------------------------------------------------- 1 | package com.ivanfranchin.bookapi.rest.dto; 2 | 3 | import io.swagger.v3.oas.annotations.media.Schema; 4 | import jakarta.validation.constraints.NotBlank; 5 | 6 | public record LoginRequest( 7 | @Schema(example = "user") @NotBlank String username, 8 | @Schema(example = "user") @NotBlank String password) { 9 | } 10 | -------------------------------------------------------------------------------- /book-api/src/main/java/com/ivanfranchin/bookapi/rest/dto/SignUpRequest.java: -------------------------------------------------------------------------------- 1 | package com.ivanfranchin.bookapi.rest.dto; 2 | 3 | import io.swagger.v3.oas.annotations.media.Schema; 4 | import jakarta.validation.constraints.Email; 5 | import jakarta.validation.constraints.NotBlank; 6 | 7 | public record SignUpRequest( 8 | @Schema(example = "user3") @NotBlank String username, 9 | @Schema(example = "user3") @NotBlank String password, 10 | @Schema(example = "User3") @NotBlank String name, 11 | @Schema(example = "user3@mycompany.com") @Email String email) { 12 | } 13 | -------------------------------------------------------------------------------- /book-api/src/main/java/com/ivanfranchin/bookapi/rest/dto/UserDto.java: -------------------------------------------------------------------------------- 1 | package com.ivanfranchin.bookapi.rest.dto; 2 | 3 | import com.ivanfranchin.bookapi.user.User; 4 | 5 | public record UserDto(Long id, String username, String name, String email, String role) { 6 | 7 | public static UserDto from(User user) { 8 | return new UserDto( 9 | user.getId(), 10 | user.getUsername(), 11 | user.getName(), 12 | user.getEmail(), 13 | user.getRole() 14 | ); 15 | } 16 | } -------------------------------------------------------------------------------- /book-api/src/main/java/com/ivanfranchin/bookapi/runner/DatabaseInitializer.java: -------------------------------------------------------------------------------- 1 | package com.ivanfranchin.bookapi.runner; 2 | 3 | import com.ivanfranchin.bookapi.book.Book; 4 | import com.ivanfranchin.bookapi.user.User; 5 | import com.ivanfranchin.bookapi.security.SecurityConfig; 6 | import com.ivanfranchin.bookapi.book.BookService; 7 | import com.ivanfranchin.bookapi.user.UserService; 8 | import lombok.RequiredArgsConstructor; 9 | import lombok.extern.slf4j.Slf4j; 10 | import org.springframework.boot.CommandLineRunner; 11 | import org.springframework.security.crypto.password.PasswordEncoder; 12 | import org.springframework.stereotype.Component; 13 | 14 | import java.util.Arrays; 15 | import java.util.List; 16 | import java.util.stream.Collectors; 17 | 18 | @Slf4j 19 | @RequiredArgsConstructor 20 | @Component 21 | public class DatabaseInitializer implements CommandLineRunner { 22 | 23 | private final UserService userService; 24 | private final BookService bookService; 25 | private final PasswordEncoder passwordEncoder; 26 | 27 | @Override 28 | public void run(String... args) { 29 | if (!userService.getUsers().isEmpty()) { 30 | return; 31 | } 32 | USERS.forEach(user -> { 33 | user.setPassword(passwordEncoder.encode(user.getPassword())); 34 | userService.saveUser(user); 35 | }); 36 | getBooks().forEach(bookService::saveBook); 37 | log.info("Database initialized"); 38 | } 39 | 40 | private List getBooks() { 41 | return Arrays.stream(BOOKS_STR.split("\n")) 42 | .map(bookInfoStr -> bookInfoStr.split(";")) 43 | .map(bookInfoArr -> new Book(bookInfoArr[0], bookInfoArr[1])) 44 | .collect(Collectors.toList()); 45 | } 46 | 47 | private static final List USERS = Arrays.asList( 48 | new User("admin", "admin", "Admin", "admin@mycompany.com", SecurityConfig.ADMIN), 49 | new User("user", "user", "User", "user@mycompany.com", SecurityConfig.USER) 50 | ); 51 | 52 | private static final String BOOKS_STR = 53 | """ 54 | 9781603090773;Any Empire 55 | 9781603090698;August Moon 56 | 9781891830372;The Barefoot Serpent (softcover) by Scott Morse 57 | 9781603090292;BB Wolf and the 3 LP's 58 | 9781891830402;Beach Safari by Mawil 59 | 9781603094429;Belzebubs 60 | 9781891830563;Bighead by Jeffrey Brown 61 | 9781603094320;Bodycount 62 | 9781891830198;Box Office Poison 63 | 9780958578349;From Hell 64 | 9781603094221;Cat'n'Bat 65 | 9781603091008;Crater XV 66 | 9781891830815;Cry Yourself to Sleep by Jeremy Tinder 67 | 9781603092715;Dear Beloved Stranger 68 | 9781891830129;Dear Julia 69 | 9781891830921;Death by Chocolate - Redux 70 | 9781603090575;Dragon Puncher (Book 1) 71 | 9781603090858;Dragon Puncher (Book 2): Island 72 | 9781603093873;Eddie Campbell's Omnibox: The Complete ALEC and BACCHUS (3 Volume Slipcase) 73 | 9781603090360;Far Arden 74 | 9781603090537;Fingerprints 75 | 9781891830976;Fox Bunny Funny 76 | 9780958578349;From Hell 77 | 9781603093866;God Is Disappointed / Apocrypha Now — SLIPCASE SET 78 | 9781603090988;God Is Disappointed in You 79 | 9781603090087;Hieronymus B. 80 | 9781603094412;Highwayman 81 | 9781891830174;Hutch Owen (Vol 1): The Collected by Tom Hart 82 | 9781891830556;Hutch Owen (Vol 2): Unmarketable by Tom Hart 83 | 9781603090865;Hutch Owen (Vol 3): Let's Get Furious! 84 | 9781891830839;Infinite Kung Fu 85 | 9781891830655;The King by Rich Koslowski 86 | 9781603090001;The League of Extraordinary Gentlemen (Vol III): Century #1 - 1910 87 | 9781603090063;The League of Extraordinary Gentlemen (Vol III): Century #2 - 1969 88 | 9781603090070;The League of Extraordinary Gentlemen (Vol III): Century #3 - 2009 89 | 9781603094375;The League of Extraordinary Gentlemen (Vol III): Century 90 | 9781891830518;Less Than Heroes by David Yurkovich 91 | 9781603090704;Liar's Kiss 92 | 9781891830693;Lone Racer by Nicolas Mahler 93 | 9781603091527;The Lovely Horrible Stuff 94 | 9781603090094;Lower Regions 95 | 9781891830334;Magic Boy and the Robot Elf by James Kochalka 96 | 9781891830365;Monkey Vs. Robot (Vol 2): Crystal of Power by Koch. 97 | 9781603090759;Monster on the Hill (Book 1) 98 | 9781891830686;Mosquito by Dan James 99 | 9781603090490;Moving Pictures 100 | 9781603094092;Nate Powell's OMNIBOX 101 | 9781603090681;Okie Dokie Donuts (Story 1): Open for Business! 102 | 9781891830297;Pinky & Stinky by James Kochalka 103 | 9781603090711;Pirate Penguin vs Ninja Chicken (Book 1): Troublems with Frenemies 104 | 9781603093675;Pirate Penguin vs Ninja Chicken (Book 2): Escape from Skull-Fragment Island! 105 | 9781603094139;Return of the Dapper Men (Deluxe Edition) 106 | 9781603090896;Scene But Not Heard 107 | 9781603094450;A Shining Beacon 108 | 9781891830143;Speechless 109 | 9781891830501;Spiral-Bound by Aaron Renier 110 | 9781603090209;Sulk (Vol 1): Bighead and Friends 111 | 9781603090315;Sulk (Vol 2): Deadly Awesome 112 | 9781603090551;Sulk (Vol 3): The Kind of Strength... 113 | 9781891830969;Super Spy 114 | 9781603090438;Super Spy (Vol 2): The Lost Dossiers 115 | 9781603090339;Swallow Me Whole 116 | 9781603090056;That Salty Air 117 | 9781603094504;They Called Us Enemy 118 | 9781891830310;Three Fingers by Rich Koslowski 119 | 9781891830983;Too Cool to Be Forgotten 120 | 9781603090742;The Underwater Welder 121 | 9781603090889;Upside Down (Book 1): A Vampire Tale 122 | 9781603093712;Upside Down (Book 2): A Hat Full of Spells 123 | 9781891830723;Will You Still Love Me If I Wet the Bed by Liz Prince 124 | 9781603094405;Ye 125 | """; 126 | } 127 | -------------------------------------------------------------------------------- /book-api/src/main/java/com/ivanfranchin/bookapi/security/CorsConfig.java: -------------------------------------------------------------------------------- 1 | package com.ivanfranchin.bookapi.security; 2 | 3 | import org.springframework.beans.factory.annotation.Value; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.web.cors.CorsConfiguration; 7 | import org.springframework.web.cors.CorsConfigurationSource; 8 | import org.springframework.web.cors.UrlBasedCorsConfigurationSource; 9 | 10 | import java.util.List; 11 | 12 | @Configuration 13 | public class CorsConfig { 14 | 15 | @Bean 16 | CorsConfigurationSource corsConfigurationSource(@Value("${app.cors.allowed-origins}") List allowedOrigins) { 17 | CorsConfiguration configuration = new CorsConfiguration(); 18 | configuration.setAllowCredentials(true); 19 | configuration.setAllowedOrigins(allowedOrigins); 20 | configuration.addAllowedMethod("*"); 21 | configuration.addAllowedHeader("*"); 22 | UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); 23 | source.registerCorsConfiguration("/**", configuration); 24 | return source; 25 | } 26 | } -------------------------------------------------------------------------------- /book-api/src/main/java/com/ivanfranchin/bookapi/security/CustomUserDetails.java: -------------------------------------------------------------------------------- 1 | package com.ivanfranchin.bookapi.security; 2 | 3 | import lombok.Data; 4 | import org.springframework.security.core.GrantedAuthority; 5 | import org.springframework.security.core.userdetails.UserDetails; 6 | 7 | import java.util.Collection; 8 | 9 | @Data 10 | public class CustomUserDetails implements UserDetails { 11 | 12 | private Long id; 13 | private String username; 14 | private String password; 15 | private String name; 16 | private String email; 17 | private Collection authorities; 18 | 19 | @Override 20 | public Collection getAuthorities() { 21 | return authorities; 22 | } 23 | 24 | @Override 25 | public String getPassword() { 26 | return password; 27 | } 28 | 29 | @Override 30 | public String getUsername() { 31 | return username; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /book-api/src/main/java/com/ivanfranchin/bookapi/security/CustomUserDetailsService.java: -------------------------------------------------------------------------------- 1 | package com.ivanfranchin.bookapi.security; 2 | 3 | import com.ivanfranchin.bookapi.user.UserService; 4 | import com.ivanfranchin.bookapi.user.User; 5 | import lombok.RequiredArgsConstructor; 6 | import org.springframework.security.core.authority.SimpleGrantedAuthority; 7 | import org.springframework.security.core.userdetails.UserDetails; 8 | import org.springframework.security.core.userdetails.UserDetailsService; 9 | import org.springframework.security.core.userdetails.UsernameNotFoundException; 10 | import org.springframework.stereotype.Service; 11 | 12 | import java.util.Collections; 13 | import java.util.List; 14 | 15 | @RequiredArgsConstructor 16 | @Service 17 | public class CustomUserDetailsService implements UserDetailsService { 18 | 19 | private final UserService userService; 20 | 21 | @Override 22 | public UserDetails loadUserByUsername(String username) { 23 | User user = userService.getUserByUsername(username) 24 | .orElseThrow(() -> new UsernameNotFoundException(String.format("Username %s not found", username))); 25 | List authorities = Collections.singletonList(new SimpleGrantedAuthority(user.getRole())); 26 | return mapUserToCustomUserDetails(user, authorities); 27 | } 28 | 29 | private CustomUserDetails mapUserToCustomUserDetails(User user, List authorities) { 30 | CustomUserDetails customUserDetails = new CustomUserDetails(); 31 | customUserDetails.setId(user.getId()); 32 | customUserDetails.setUsername(user.getUsername()); 33 | customUserDetails.setPassword(user.getPassword()); 34 | customUserDetails.setName(user.getName()); 35 | customUserDetails.setEmail(user.getEmail()); 36 | customUserDetails.setAuthorities(authorities); 37 | return customUserDetails; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /book-api/src/main/java/com/ivanfranchin/bookapi/security/SecurityConfig.java: -------------------------------------------------------------------------------- 1 | package com.ivanfranchin.bookapi.security; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.http.HttpMethod; 6 | import org.springframework.security.config.Customizer; 7 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; 8 | import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer; 9 | import org.springframework.security.config.http.SessionCreationPolicy; 10 | import org.springframework.security.crypto.factory.PasswordEncoderFactories; 11 | import org.springframework.security.crypto.password.PasswordEncoder; 12 | import org.springframework.security.web.SecurityFilterChain; 13 | 14 | @Configuration 15 | public class SecurityConfig { 16 | 17 | @Bean 18 | SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { 19 | return http 20 | .authorizeHttpRequests(authorizeHttpRequests -> authorizeHttpRequests 21 | .requestMatchers(HttpMethod.GET, "/api/books", "/api/books/**").hasAnyAuthority(ADMIN, USER) 22 | .requestMatchers(HttpMethod.GET, "/api/users/me").hasAnyAuthority(ADMIN, USER) 23 | .requestMatchers("/api/books", "/api/books/**").hasAuthority(ADMIN) 24 | .requestMatchers("/api/users", "/api/users/**").hasAuthority(ADMIN) 25 | .requestMatchers("/public/**", "/auth/**").permitAll() 26 | .requestMatchers("/", "/error", "/csrf", "/swagger-ui.html", "/swagger-ui/**", "/v3/api-docs", "/v3/api-docs/**").permitAll() 27 | .anyRequest().authenticated()) 28 | .httpBasic(Customizer.withDefaults()) 29 | .sessionManagement(sessionManagement -> sessionManagement.sessionCreationPolicy(SessionCreationPolicy.STATELESS)) 30 | .csrf(AbstractHttpConfigurer::disable) 31 | .build(); 32 | } 33 | 34 | @Bean 35 | PasswordEncoder passwordEncoder() { 36 | return PasswordEncoderFactories.createDelegatingPasswordEncoder(); 37 | } 38 | 39 | public static final String ADMIN = "ADMIN"; 40 | public static final String USER = "USER"; 41 | } 42 | -------------------------------------------------------------------------------- /book-api/src/main/java/com/ivanfranchin/bookapi/user/DuplicatedUserInfoException.java: -------------------------------------------------------------------------------- 1 | package com.ivanfranchin.bookapi.user; 2 | 3 | import org.springframework.http.HttpStatus; 4 | import org.springframework.web.bind.annotation.ResponseStatus; 5 | 6 | @ResponseStatus(HttpStatus.CONFLICT) 7 | public class DuplicatedUserInfoException extends RuntimeException { 8 | 9 | public DuplicatedUserInfoException(String message) { 10 | super(message); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /book-api/src/main/java/com/ivanfranchin/bookapi/user/User.java: -------------------------------------------------------------------------------- 1 | package com.ivanfranchin.bookapi.user; 2 | 3 | import jakarta.persistence.Entity; 4 | import jakarta.persistence.GeneratedValue; 5 | import jakarta.persistence.GenerationType; 6 | import jakarta.persistence.Id; 7 | import jakarta.persistence.Table; 8 | import jakarta.persistence.UniqueConstraint; 9 | import lombok.Data; 10 | import lombok.NoArgsConstructor; 11 | 12 | @Data 13 | @NoArgsConstructor 14 | @Entity 15 | @Table(name = "users", uniqueConstraints = { 16 | @UniqueConstraint(columnNames = "username"), 17 | @UniqueConstraint(columnNames = "email") 18 | }) 19 | public class User { 20 | 21 | @Id 22 | @GeneratedValue(strategy = GenerationType.IDENTITY) 23 | private Long id; 24 | 25 | private String username; 26 | private String password; 27 | private String name; 28 | private String email; 29 | private String role; 30 | 31 | public User(String username, String password, String name, String email, String role) { 32 | this.username = username; 33 | this.password = password; 34 | this.name = name; 35 | this.email = email; 36 | this.role = role; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /book-api/src/main/java/com/ivanfranchin/bookapi/user/UserNotFoundException.java: -------------------------------------------------------------------------------- 1 | package com.ivanfranchin.bookapi.user; 2 | 3 | import org.springframework.http.HttpStatus; 4 | import org.springframework.web.bind.annotation.ResponseStatus; 5 | 6 | @ResponseStatus(HttpStatus.NOT_FOUND) 7 | public class UserNotFoundException extends RuntimeException { 8 | 9 | public UserNotFoundException(String message) { 10 | super(message); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /book-api/src/main/java/com/ivanfranchin/bookapi/user/UserRepository.java: -------------------------------------------------------------------------------- 1 | package com.ivanfranchin.bookapi.user; 2 | 3 | import org.springframework.data.jpa.repository.JpaRepository; 4 | import org.springframework.stereotype.Repository; 5 | 6 | import java.util.Optional; 7 | 8 | @Repository 9 | public interface UserRepository extends JpaRepository { 10 | 11 | Optional findByUsername(String username); 12 | 13 | boolean existsByUsername(String username); 14 | 15 | boolean existsByEmail(String email); 16 | } 17 | -------------------------------------------------------------------------------- /book-api/src/main/java/com/ivanfranchin/bookapi/user/UserService.java: -------------------------------------------------------------------------------- 1 | package com.ivanfranchin.bookapi.user; 2 | 3 | import java.util.List; 4 | import java.util.Optional; 5 | 6 | public interface UserService { 7 | 8 | List getUsers(); 9 | 10 | Optional getUserByUsername(String username); 11 | 12 | boolean hasUserWithUsername(String username); 13 | 14 | boolean hasUserWithEmail(String email); 15 | 16 | User validateAndGetUserByUsername(String username); 17 | 18 | User saveUser(User user); 19 | 20 | void deleteUser(User user); 21 | 22 | Optional validUsernameAndPassword(String username, String password); 23 | } 24 | -------------------------------------------------------------------------------- /book-api/src/main/java/com/ivanfranchin/bookapi/user/UserServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.ivanfranchin.bookapi.user; 2 | 3 | import lombok.RequiredArgsConstructor; 4 | import org.springframework.security.crypto.password.PasswordEncoder; 5 | import org.springframework.stereotype.Service; 6 | 7 | import java.util.List; 8 | import java.util.Optional; 9 | 10 | @RequiredArgsConstructor 11 | @Service 12 | public class UserServiceImpl implements UserService { 13 | 14 | private final UserRepository userRepository; 15 | private final PasswordEncoder passwordEncoder; 16 | 17 | @Override 18 | public List getUsers() { 19 | return userRepository.findAll(); 20 | } 21 | 22 | @Override 23 | public Optional getUserByUsername(String username) { 24 | return userRepository.findByUsername(username); 25 | } 26 | 27 | @Override 28 | public boolean hasUserWithUsername(String username) { 29 | return userRepository.existsByUsername(username); 30 | } 31 | 32 | @Override 33 | public boolean hasUserWithEmail(String email) { 34 | return userRepository.existsByEmail(email); 35 | } 36 | 37 | @Override 38 | public User validateAndGetUserByUsername(String username) { 39 | return getUserByUsername(username) 40 | .orElseThrow(() -> new UserNotFoundException(String.format("User with username %s not found", username))); 41 | } 42 | 43 | @Override 44 | public User saveUser(User user) { 45 | return userRepository.save(user); 46 | } 47 | 48 | @Override 49 | public void deleteUser(User user) { 50 | userRepository.delete(user); 51 | } 52 | 53 | @Override 54 | public Optional validUsernameAndPassword(String username, String password) { 55 | return getUserByUsername(username) 56 | .filter(user -> passwordEncoder.matches(password, user.getPassword())); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /book-api/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: book-api 4 | jpa: 5 | hibernate: 6 | ddl-auto: create 7 | datasource: 8 | url: jdbc:postgresql://localhost:5432/bookdb 9 | username: postgres 10 | password: postgres 11 | 12 | app: 13 | cors: 14 | allowed-origins: http://localhost:3000 15 | 16 | logging: 17 | level: 18 | org.springframework.security: DEBUG 19 | # org.hibernate.SQL: DEBUG 20 | -------------------------------------------------------------------------------- /book-api/src/main/resources/banner.txt: -------------------------------------------------------------------------------- 1 | _ _ _ 2 | | |__ ___ ___ | | __ __ _ _ __ (_) 3 | | '_ \ / _ \ / _ \| |/ /____ / _` | '_ \| | 4 | | |_) | (_) | (_) | <_____| (_| | |_) | | 5 | |_.__/ \___/ \___/|_|\_\ \__,_| .__/|_| 6 | |_| 7 | :: Spring Boot :: ${spring-boot.formatted-version} 8 | -------------------------------------------------------------------------------- /book-api/src/test/java/com/ivanfranchin/bookapi/BookApiApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.ivanfranchin.bookapi; 2 | 3 | import org.junit.jupiter.api.Disabled; 4 | import org.junit.jupiter.api.Test; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | 7 | @Disabled 8 | @SpringBootTest 9 | class BookApiApplicationTests { 10 | 11 | @Test 12 | void contextLoads() { 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /book-api/test-endpoints.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | declare -A auth_authenticate 4 | declare -A auth_signup 5 | 6 | declare -A public_number_of_users 7 | declare -A public_number_of_books 8 | 9 | declare -A user_get_me 10 | declare -A user_get_users 11 | declare -A user_get_user 12 | declare -A user_delete_user 13 | 14 | declare -A book_get_books 15 | declare -A book_create_book 16 | declare -A book_delete_book 17 | 18 | ADMIN_AUTH_RESP=$(curl -s -X POST localhost:8080/auth/authenticate -H 'Content-Type: application/json' -d '{"username": "admin", "password": "admin"}') 19 | USER_AUTH_RESP=$(curl -s -X POST localhost:8080/auth/authenticate -H 'Content-Type: application/json' -d '{"username": "user", "password": "user"}') 20 | 21 | USER2_AUTH_RESP=$(curl -s -X POST localhost:8080/auth/signup -H 'Content-Type: application/json' -d '{"username": "user2", "password": "user2", "name": "User2", "email": "user2@mycompany.com"}') 22 | 23 | public_number_of_users[without_creds]=$(curl -w %{http_code} -s -o /dev/null localhost:8080/public/numberOfUsers) 24 | public_number_of_users[user_creds]=$(curl -w %{http_code} -s -o /dev/null -u user:user localhost:8080/public/numberOfUsers) 25 | public_number_of_users[admin_creds]=$(curl -w %{http_code} -s -o /dev/null -u admin:admin localhost:8080/public/numberOfUsers) 26 | 27 | public_number_of_books[without_creds]=$(curl -w %{http_code} -s -o /dev/null localhost:8080/public/numberOfBooks) 28 | public_number_of_books[user_creds]=$(curl -w %{http_code} -s -o /dev/null -u user:user localhost:8080/public/numberOfBooks) 29 | public_number_of_books[admin_creds]=$(curl -w %{http_code} -s -o /dev/null -u admin:admin localhost:8080/public/numberOfBooks) 30 | 31 | user_get_me[without_creds]=$(curl -w %{http_code} -s -o /dev/null localhost:8080/api/users/me) 32 | user_get_me[user_creds]=$(curl -w %{http_code} -s -o /dev/null -u user:user localhost:8080/api/users/me) 33 | user_get_me[admin_creds]=$(curl -w %{http_code} -s -o /dev/null -u admin:admin localhost:8080/api/users/me) 34 | 35 | user_get_users[without_creds]=$(curl -w %{http_code} -s -o /dev/null localhost:8080/api/users) 36 | user_get_users[user_creds]=$(curl -w %{http_code} -s -o /dev/null -u user:user localhost:8080/api/users) 37 | user_get_users[admin_creds]=$(curl -w %{http_code} -s -o /dev/null -u admin:admin localhost:8080/api/users) 38 | 39 | user_get_user[without_creds]=$(curl -w %{http_code} -s -o /dev/null localhost:8080/api/users/user) 40 | user_get_user[user_creds]=$(curl -w %{http_code} -s -o /dev/null -u user:user localhost:8080/api/users/user) 41 | user_get_user[admin_creds]=$(curl -w %{http_code} -s -o /dev/null -u admin:admin localhost:8080/api/users/user) 42 | 43 | user_delete_user[without_creds]=$(curl -w %{http_code} -s -o /dev/null -X DELETE localhost:8080/api/users/user2) 44 | user_delete_user[user_creds]=$(curl -w %{http_code} -s -o /dev/null -u user:user -X DELETE localhost:8080/api/users/user2) 45 | user_delete_user[admin_creds]=$(curl -w %{http_code} -s -o /dev/null -u admin:admin -X DELETE localhost:8080/api/users/user2) 46 | 47 | book_get_books[without_creds]=$(curl -w %{http_code} -s -o /dev/null localhost:8080/api/books) 48 | book_get_books[user_creds]=$(curl -w %{http_code} -s -o /dev/null -u user:user localhost:8080/api/books) 49 | book_get_books[admin_creds]=$(curl -w %{http_code} -s -o /dev/null -u admin:admin localhost:8080/api/books) 50 | 51 | book_create_book[without_creds]=$(curl -w %{http_code} -s -o /dev/null -X POST localhost:8080/api/books -H "Content-Type: application/json" -d '{"isbn": "abc", "title": "java 8"}') 52 | book_create_book[user_creds]=$(curl -w %{http_code} -s -o /dev/null -u user:user -X POST localhost:8080/api/books -H "Content-Type: application/json" -d '{"isbn": "abc", "title": "java 8"}') 53 | book_create_book[admin_creds]=$(curl -w %{http_code} -s -o /dev/null -u admin:admin -X POST localhost:8080/api/books -H "Content-Type: application/json" -d '{"isbn": "abc", "title": "java 8"}') 54 | 55 | book_delete_book[without_creds]=$(curl -w %{http_code} -s -o /dev/null -X DELETE localhost:8080/api/books/abc) 56 | book_delete_book[user_creds]=$(curl -w %{http_code} -s -o /dev/null -u user:user -X DELETE localhost:8080/api/books/abc) 57 | book_delete_book[admin_creds]=$(curl -w %{http_code} -s -o /dev/null -u admin:admin -X DELETE localhost:8080/api/books/abc) 58 | 59 | printf "\n" 60 | printf "%s\n" "POST auth/authenticate" 61 | printf "%s\n" "======================" 62 | printf "%s\n" "admin Auth Resp: ${ADMIN_AUTH_RESP}" 63 | printf "\n" 64 | printf "%s\n" "POST auth/authenticate" 65 | printf "%s\n" "======================" 66 | printf "%s\n" "user Auth Resp: ${USER_AUTH_RESP}" 67 | printf "\n" 68 | printf "%s\n" "POST auth/signup" 69 | printf "%s\n" "================" 70 | printf "%s\n" "user2 Auth Resp: ${USER2_AUTH_RESP}" 71 | printf "\n" 72 | printf "%s\n" "Authorization" 73 | printf "%s\n" "=============" 74 | printf "%25s | %13s | %11s | %12s |\n" "Endpoints" "without creds" "user creds" "admin creds" 75 | printf "%25s + %13s + %11s + %12s |\n" "-------------------------" "-------------" "-----------" "------------" 76 | printf "%25s | %13s | %11s | %12s |\n" "GET public/numberOfUsers" ${public_number_of_users[without_creds]} ${public_number_of_users[user_creds]} ${public_number_of_users[admin_creds]} 77 | printf "%25s | %13s | %11s | %12s |\n" "GET public/numberOfBooks" ${public_number_of_books[without_creds]} ${public_number_of_books[user_creds]} ${public_number_of_books[admin_creds]} 78 | printf "%25s + %13s + %11s + %12s |\n" "........................." "............." "..........." "............" 79 | printf "%25s | %13s | %11s | %12s |\n" "GET /api/users/me" ${user_get_me[without_creds]} ${user_get_me[user_creds]} ${user_get_me[admin_creds]} 80 | printf "%25s | %13s | %11s | %12s |\n" "GET /api/users" ${user_get_users[without_creds]} ${user_get_users[user_creds]} ${user_get_users[admin_creds]} 81 | printf "%25s | %13s | %11s | %12s |\n" "GET /api/users/user2" ${user_get_user[without_creds]} ${user_get_user[user_creds]} ${user_get_user[admin_creds]} 82 | printf "%25s | %13s | %11s | %12s |\n" "DELETE /api/users/user2" ${user_delete_user[without_creds]} ${user_delete_user[user_creds]} ${user_delete_user[admin_creds]} 83 | printf "%25s + %13s + %11s + %12s |\n" "........................." "............." "..........." "............" 84 | printf "%25s | %13s | %11s | %12s |\n" "GET /api/books" ${book_get_books[without_creds]} ${book_get_books[user_creds]} ${book_get_books[admin_creds]} 85 | printf "%25s | %13s | %11s | %12s |\n" "POST /api/books" ${book_create_book[without_creds]} ${book_create_book[user_creds]} ${book_create_book[admin_creds]} 86 | printf "%25s | %13s | %11s | %12s |\n" "DELETE /api/books/abc" ${book_delete_book[without_creds]} ${book_delete_book[user_creds]} ${book_delete_book[admin_creds]} 87 | printf "%72s\n" "------------------------------------------------------------------------" 88 | printf " [200] Success - [201] Created - [401] Unauthorized - [403] Forbidden" 89 | printf "\n" -------------------------------------------------------------------------------- /book-ui/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "book-ui", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@testing-library/jest-dom": "^6.6.3", 7 | "@testing-library/react": "^16.3.0", 8 | "@testing-library/user-event": "^14.6.1", 9 | "react": "^18.3.1", 10 | "react-dom": "^18.3.1", 11 | "react-scripts": "5.0.1", 12 | "web-vitals": "^5.0.2", 13 | "axios": "^1.9.0", 14 | "react-router-dom": "^7.6.2", 15 | "semantic-ui-react": "^2.1.5" 16 | }, 17 | "scripts": { 18 | "start": "react-scripts start", 19 | "build": "react-scripts build", 20 | "test": "react-scripts test", 21 | "eject": "react-scripts eject" 22 | }, 23 | "eslintConfig": { 24 | "extends": [ 25 | "react-app", 26 | "react-app/jest" 27 | ] 28 | }, 29 | "browserslist": { 30 | "production": [ 31 | ">0.2%", 32 | "not dead", 33 | "not op_mini all" 34 | ], 35 | "development": [ 36 | "last 1 chrome version", 37 | "last 1 firefox version", 38 | "last 1 safari version" 39 | ] 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /book-ui/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ivangfr/springboot-react-basic-auth/471752eee16d0117380134dc1db3e01bacfc0838/book-ui/public/favicon.ico -------------------------------------------------------------------------------- /book-ui/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 16 | 17 | 26 | 27 | book-ui 28 | 29 | 30 | 31 |
32 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /book-ui/public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | } 10 | ], 11 | "start_url": ".", 12 | "display": "standalone", 13 | "theme_color": "#000000", 14 | "background_color": "#ffffff" 15 | } 16 | -------------------------------------------------------------------------------- /book-ui/public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /book-ui/src/App.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import { BrowserRouter as Router, Routes, Route, Navigate } from 'react-router-dom' 3 | import { AuthProvider } from './components/context/AuthContext' 4 | import PrivateRoute from './components/misc/PrivateRoute' 5 | import Navbar from './components/misc/Navbar' 6 | import Home from './components/home/Home' 7 | import Login from './components/home/Login' 8 | import Signup from './components/home/Signup' 9 | import AdminPage from './components/admin/AdminPage' 10 | import UserPage from './components/user/UserPage' 11 | 12 | function App() { 13 | return ( 14 | 15 | 16 | 17 | 18 | } /> 19 | } /> 20 | } /> 21 | } /> 22 | } /> 23 | } /> 24 | 25 | 26 | 27 | ) 28 | } 29 | 30 | export default App 31 | -------------------------------------------------------------------------------- /book-ui/src/Constants.js: -------------------------------------------------------------------------------- 1 | const prod = { 2 | url: { 3 | API_BASE_URL: 'https://myapp.herokuapp.com', 4 | } 5 | } 6 | 7 | const dev = { 8 | url: { 9 | API_BASE_URL: 'http://localhost:8080' 10 | } 11 | } 12 | 13 | export const config = process.env.NODE_ENV === 'development' ? dev : prod -------------------------------------------------------------------------------- /book-ui/src/components/admin/AdminPage.js: -------------------------------------------------------------------------------- 1 | import React, { useEffect, useState } from 'react' 2 | import { Navigate } from 'react-router-dom' 3 | import { Container } from 'semantic-ui-react' 4 | import { useAuth } from '../context/AuthContext' 5 | import { bookApi } from '../misc/BookApi' 6 | import AdminTab from './AdminTab' 7 | import { handleLogError } from '../misc/Helpers' 8 | 9 | function AdminPage() { 10 | const Auth = useAuth() 11 | const user = Auth.getUser() 12 | const isAdmin = user.role === 'ADMIN' 13 | 14 | const [users, setUsers] = useState([]) 15 | const [userUsernameSearch, setUserUsernameSearch] = useState('') 16 | const [isUsersLoading, setIsUsersLoading] = useState(false) 17 | 18 | const [books, setBooks] = useState([]) 19 | const [bookIsbn, setBookIsbn] = useState('') 20 | const [bookTitle, setBookTitle] = useState('') 21 | const [bookTextSearch, setBookTextSearch] = useState('') 22 | const [isBooksLoading, setIsBooksLoading] = useState(false) 23 | 24 | useEffect(() => { 25 | handleGetUsers() 26 | handleGetBooks() 27 | }, []) 28 | 29 | const handleInputChange = (e, { name, value }) => { 30 | if (name === 'userUsernameSearch') { 31 | setUserUsernameSearch(value) 32 | } else if (name === 'bookIsbn') { 33 | setBookIsbn(value) 34 | } else if (name === 'bookTitle') { 35 | setBookTitle(value) 36 | } else if (name === 'bookTextSearch') { 37 | setBookTextSearch(value) 38 | } 39 | } 40 | 41 | const handleGetUsers = async () => { 42 | try { 43 | setIsUsersLoading(true) 44 | const response = await bookApi.getUsers(user) 45 | const users = response.data 46 | setUsers(users) 47 | } catch (error) { 48 | handleLogError(error) 49 | } finally { 50 | setIsUsersLoading(false) 51 | } 52 | } 53 | 54 | const handleDeleteUser = async (username) => { 55 | try { 56 | await bookApi.deleteUser(user, username) 57 | await handleGetUsers() 58 | } catch (error) { 59 | handleLogError(error) 60 | } 61 | } 62 | 63 | const handleSearchUser = async () => { 64 | try { 65 | const response = await bookApi.getUsers(user, userUsernameSearch) 66 | const data = response.data 67 | const users = data instanceof Array ? data : [data] 68 | setUsers(users) 69 | } catch (error) { 70 | handleLogError(error) 71 | setUsers([]) 72 | } 73 | } 74 | 75 | const handleGetBooks = async () => { 76 | try { 77 | setIsBooksLoading(true) 78 | const response = await bookApi.getBooks(user) 79 | setBooks(response.data) 80 | } catch (error) { 81 | handleLogError(error) 82 | } finally { 83 | setIsBooksLoading(false) 84 | } 85 | } 86 | 87 | const handleDeleteBook = async (isbn) => { 88 | try { 89 | await bookApi.deleteBook(user, isbn) 90 | await handleGetBooks() 91 | } catch (error) { 92 | handleLogError(error) 93 | } 94 | } 95 | 96 | const handleAddBook = async () => { 97 | try { 98 | const book = { isbn: bookIsbn.trim(), title: bookTitle.trim() } 99 | if (!(book.isbn && book.title)) { 100 | return 101 | } 102 | await bookApi.addBook(user, book) 103 | clearBookForm() 104 | await handleGetBooks() 105 | } catch (error) { 106 | handleLogError(error) 107 | } 108 | } 109 | 110 | const handleSearchBook = async () => { 111 | try { 112 | const response = await bookApi.getBooks(user, bookTextSearch) 113 | const books = response.data 114 | setBooks(books) 115 | } catch (error) { 116 | handleLogError(error) 117 | setBooks([]) 118 | } 119 | } 120 | 121 | const clearBookForm = () => { 122 | setBookIsbn('') 123 | setBookTitle('') 124 | } 125 | 126 | if (!isAdmin) { 127 | return 128 | } 129 | 130 | return ( 131 | 132 | 148 | 149 | ) 150 | } 151 | 152 | export default AdminPage -------------------------------------------------------------------------------- /book-ui/src/components/admin/AdminTab.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import { Tab } from 'semantic-ui-react' 3 | import UserTable from './UserTable' 4 | import BookTable from './BookTable' 5 | 6 | function AdminTab(props) { 7 | const { handleInputChange } = props 8 | const { isUsersLoading, users, userUsernameSearch, handleDeleteUser, handleSearchUser } = props 9 | const { isBooksLoading, books, bookIsbn, bookTitle, bookTextSearch, handleAddBook, handleDeleteBook, handleSearchBook } = props 10 | 11 | const panes = [ 12 | { 13 | menuItem: { key: 'users', icon: 'users', content: 'Users' }, 14 | render: () => ( 15 | 16 | 23 | 24 | ) 25 | }, 26 | { 27 | menuItem: { key: 'books', icon: 'book', content: 'Books' }, 28 | render: () => ( 29 | 30 | 40 | 41 | ) 42 | } 43 | ] 44 | 45 | return ( 46 | 47 | ) 48 | } 49 | 50 | export default AdminTab -------------------------------------------------------------------------------- /book-ui/src/components/admin/BookForm.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import { Button, Form, Icon } from 'semantic-ui-react' 3 | 4 | function BookForm({ bookIsbn, bookTitle, handleInputChange, handleAddBook }) { 5 | const createBtnDisabled = bookIsbn.trim() === '' || bookTitle.trim() === '' 6 | return ( 7 |
8 | 9 | 15 | 21 | 24 | 25 |
26 | ) 27 | } 28 | 29 | export default BookForm -------------------------------------------------------------------------------- /book-ui/src/components/admin/BookTable.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import { Button, Form, Grid, Image, Input, Table } from 'semantic-ui-react' 3 | import BookForm from './BookForm' 4 | 5 | function BookTable({ books, bookIsbn, bookTitle, bookTextSearch, handleInputChange, handleAddBook, handleDeleteBook, handleSearchBook }) { 6 | let bookList 7 | if (books.length === 0) { 8 | bookList = ( 9 | 10 | No book 11 | 12 | ) 13 | } else { 14 | bookList = books.map(book => { 15 | return ( 16 | 17 | 18 | 79 | 80 | 81 | {`Don't have already an account? `} 82 | Sign Up 83 | 84 | {isError && The username or password provided are incorrect!} 85 | 86 | 87 | ) 88 | } 89 | 90 | export default Login -------------------------------------------------------------------------------- /book-ui/src/components/home/Signup.js: -------------------------------------------------------------------------------- 1 | import React, { useState } from 'react' 2 | import { NavLink, Navigate } from 'react-router-dom' 3 | import { Button, Form, Grid, Segment, Message } from 'semantic-ui-react' 4 | import { useAuth } from '../context/AuthContext' 5 | import { bookApi } from '../misc/BookApi' 6 | import { handleLogError } from '../misc/Helpers' 7 | 8 | function Signup() { 9 | const Auth = useAuth() 10 | const isLoggedIn = Auth.userIsAuthenticated() 11 | 12 | const [username, setUsername] = useState('') 13 | const [password, setPassword] = useState('') 14 | const [name, setName] = useState('') 15 | const [email, setEmail] = useState('') 16 | const [isError, setIsError] = useState(false) 17 | const [errorMessage, setErrorMessage] = useState('') 18 | 19 | const handleInputChange = (e, { name, value }) => { 20 | if (name === 'username') { 21 | setUsername(value) 22 | } else if (name === 'password') { 23 | setPassword(value) 24 | } else if (name === 'name') { 25 | setName(value) 26 | } else if (name === 'email') { 27 | setEmail(value) 28 | } 29 | } 30 | 31 | const handleSubmit = async (e) => { 32 | e.preventDefault() 33 | 34 | if (!(username && password && name && email)) { 35 | setIsError(true) 36 | setErrorMessage('Please, inform all fields!') 37 | return 38 | } 39 | 40 | const user = { username, password, name, email } 41 | 42 | try { 43 | const response = await bookApi.signup(user) 44 | const { id, name, role } = response.data 45 | const authdata = window.btoa(username + ':' + password) 46 | const authenticatedUser = { id, name, role, authdata } 47 | 48 | Auth.userLogin(authenticatedUser) 49 | 50 | setUsername('') 51 | setPassword('') 52 | setName('') 53 | setEmail('') 54 | setIsError(false) 55 | setErrorMessage('') 56 | } catch (error) { 57 | handleLogError(error) 58 | if (error.response && error.response.data) { 59 | const errorData = error.response.data 60 | let errorMessage = 'Invalid fields' 61 | if (errorData.status === 409) { 62 | errorMessage = errorData.message 63 | } else if (errorData.status === 400) { 64 | errorMessage = errorData.errors[0].defaultMessage 65 | } 66 | setIsError(true) 67 | setErrorMessage(errorMessage) 68 | } 69 | } 70 | } 71 | 72 | if (isLoggedIn) { 73 | return 74 | } 75 | 76 | return ( 77 | 78 | 79 |
80 | 81 | 91 | 101 | 110 | 119 | 120 | 121 |
122 | {`Already have an account? `} 123 | Login 124 | 125 | {isError && {errorMessage}} 126 |
127 |
128 | ) 129 | } 130 | 131 | export default Signup -------------------------------------------------------------------------------- /book-ui/src/components/misc/BookApi.js: -------------------------------------------------------------------------------- 1 | import axios from 'axios' 2 | import { config } from '../../Constants' 3 | 4 | export const bookApi = { 5 | authenticate, 6 | signup, 7 | numberOfUsers, 8 | numberOfBooks, 9 | getUsers, 10 | deleteUser, 11 | getBooks, 12 | deleteBook, 13 | addBook 14 | } 15 | 16 | function authenticate(username, password) { 17 | return instance.post('/auth/authenticate', { username, password }, { 18 | headers: { 'Content-type': 'application/json' } 19 | }) 20 | } 21 | 22 | function signup(user) { 23 | return instance.post('/auth/signup', user, { 24 | headers: { 'Content-type': 'application/json' } 25 | }) 26 | } 27 | 28 | function numberOfUsers() { 29 | return instance.get('/public/numberOfUsers') 30 | } 31 | 32 | function numberOfBooks() { 33 | return instance.get('/public/numberOfBooks') 34 | } 35 | 36 | function getUsers(user, username) { 37 | const url = username ? `/api/users/${username}` : '/api/users' 38 | return instance.get(url, { 39 | headers: { 'Authorization': basicAuth(user) } 40 | }) 41 | } 42 | 43 | function deleteUser(user, username) { 44 | return instance.delete(`/api/users/${username}`, { 45 | headers: { 'Authorization': basicAuth(user) } 46 | }) 47 | } 48 | 49 | function getBooks(user, text) { 50 | const url = text ? `/api/books?text=${text}` : '/api/books' 51 | return instance.get(url, { 52 | headers: { 'Authorization': basicAuth(user) } 53 | }) 54 | } 55 | 56 | function deleteBook(user, isbn) { 57 | return instance.delete(`/api/books/${isbn}`, { 58 | headers: { 'Authorization': basicAuth(user) } 59 | }) 60 | } 61 | 62 | function addBook(user, book) { 63 | return instance.post('/api/books', book, { 64 | headers: { 65 | 'Content-type': 'application/json', 66 | 'Authorization': basicAuth(user) 67 | } 68 | }) 69 | } 70 | 71 | // -- Axios 72 | 73 | const instance = axios.create({ 74 | baseURL: config.url.API_BASE_URL 75 | }) 76 | 77 | // -- Helper functions 78 | 79 | function basicAuth(user) { 80 | return `Basic ${user.authdata}` 81 | } -------------------------------------------------------------------------------- /book-ui/src/components/misc/Helpers.js: -------------------------------------------------------------------------------- 1 | export const handleLogError = (error) => { 2 | if (error.response) { 3 | console.log(error.response.data) 4 | } else if (error.request) { 5 | console.log(error.request) 6 | } else { 7 | console.log(error.message) 8 | } 9 | } -------------------------------------------------------------------------------- /book-ui/src/components/misc/Navbar.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import { Link } from 'react-router-dom' 3 | import { Container, Menu } from 'semantic-ui-react' 4 | import { useAuth } from '../context/AuthContext' 5 | 6 | function Navbar() { 7 | const { getUser, userIsAuthenticated, userLogout } = useAuth() 8 | 9 | const logout = () => { 10 | userLogout() 11 | } 12 | 13 | const enterMenuStyle = () => { 14 | return userIsAuthenticated() ? { "display": "none" } : { "display": "block" } 15 | } 16 | 17 | const logoutMenuStyle = () => { 18 | return userIsAuthenticated() ? { "display": "block" } : { "display": "none" } 19 | } 20 | 21 | const adminPageStyle = () => { 22 | const user = getUser() 23 | return user && user.role === 'ADMIN' ? { "display": "block" } : { "display": "none" } 24 | } 25 | 26 | const userPageStyle = () => { 27 | const user = getUser() 28 | return user && user.role === 'USER' ? { "display": "block" } : { "display": "none" } 29 | } 30 | 31 | const getUserName = () => { 32 | const user = getUser() 33 | return user ? user.name : '' 34 | } 35 | 36 | return ( 37 | 38 | 39 | Book-UI 40 | Home 41 | AdminPage 42 | UserPage 43 | 44 | Login 45 | Sign Up 46 | {`Hi ${getUserName()}`} 47 | Logout 48 | 49 | 50 | 51 | ) 52 | } 53 | 54 | export default Navbar 55 | -------------------------------------------------------------------------------- /book-ui/src/components/misc/PrivateRoute.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import { Navigate } from 'react-router-dom' 3 | import { useAuth } from '../context/AuthContext' 4 | 5 | function PrivateRoute({ children }) { 6 | const { userIsAuthenticated } = useAuth() 7 | return userIsAuthenticated() ? children : 8 | } 9 | 10 | export default PrivateRoute -------------------------------------------------------------------------------- /book-ui/src/components/user/BookList.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import { Grid, Header, Form, Icon, Image, Input, Item, Segment } from 'semantic-ui-react' 3 | 4 | function BookList({ isBooksLoading, bookTextSearch, books, handleInputChange, handleSearchBook }) { 5 | let bookList 6 | if (books.length === 0) { 7 | bookList = No book 8 | } else { 9 | bookList = books.map(book => { 10 | return ( 11 | 12 | 13 | 14 | {book.title} 15 | {book.isbn} 16 | 17 | 18 | 19 | 20 | 21 | ) 22 | }) 23 | } 24 | 25 | return ( 26 | 27 | 28 | 29 | 30 |
31 | 32 | Books 33 |
34 |
35 | 36 |
37 | 44 |
45 |
46 |
47 |
48 | 49 | {bookList} 50 | 51 |
52 | ) 53 | } 54 | 55 | export default BookList -------------------------------------------------------------------------------- /book-ui/src/components/user/UserPage.js: -------------------------------------------------------------------------------- 1 | import React, { useEffect, useState } from 'react' 2 | import { Navigate } from 'react-router-dom' 3 | import { Container } from 'semantic-ui-react' 4 | import BookList from './BookList' 5 | import { useAuth } from '../context/AuthContext' 6 | import { bookApi } from '../misc/BookApi' 7 | import { handleLogError } from '../misc/Helpers' 8 | 9 | function UserPage() { 10 | const Auth = useAuth() 11 | const user = Auth.getUser() 12 | const isUser = user.role === 'USER' 13 | 14 | const [books, setBooks] = useState([]) 15 | const [bookTextSearch, setBookTextSearch] = useState('') 16 | const [isBooksLoading, setIsBooksLoading] = useState(false) 17 | 18 | useEffect(() => { 19 | handleGetBooks() 20 | }, []) 21 | 22 | const handleInputChange = (e, { name, value }) => { 23 | if (name === 'bookTextSearch') { 24 | setBookTextSearch(value) 25 | } 26 | } 27 | 28 | const handleGetBooks = async () => { 29 | try { 30 | setIsBooksLoading(true) 31 | const response = await bookApi.getBooks(user) 32 | setBooks(response.data) 33 | } catch (error) { 34 | handleLogError(error) 35 | } finally { 36 | setIsBooksLoading(false) 37 | } 38 | } 39 | 40 | const handleSearchBook = async () => { 41 | try { 42 | const response = await bookApi.getBooks(user, bookTextSearch) 43 | const books = response.data 44 | setBooks(books) 45 | } catch (error) { 46 | handleLogError(error) 47 | setBooks([]) 48 | } 49 | } 50 | 51 | if (!isUser) { 52 | return 53 | } 54 | 55 | return ( 56 | 57 | 64 | 65 | ) 66 | } 67 | 68 | export default UserPage -------------------------------------------------------------------------------- /book-ui/src/index.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 4 | 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', 5 | sans-serif; 6 | -webkit-font-smoothing: antialiased; 7 | -moz-osx-font-smoothing: grayscale; 8 | } 9 | 10 | code { 11 | font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', 12 | monospace; 13 | } 14 | -------------------------------------------------------------------------------- /book-ui/src/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import ReactDOM from 'react-dom/client' 3 | import './index.css' 4 | import App from './App' 5 | import reportWebVitals from './reportWebVitals' 6 | 7 | const root = ReactDOM.createRoot(document.getElementById('root')) 8 | root.render( 9 | // 10 | 11 | // 12 | ) 13 | 14 | // If you want to start measuring performance in your app, pass a function 15 | // to log results (for example: reportWebVitals(console.log)) 16 | // or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals 17 | reportWebVitals() 18 | -------------------------------------------------------------------------------- /book-ui/src/reportWebVitals.js: -------------------------------------------------------------------------------- 1 | const reportWebVitals = onPerfEntry => { 2 | if (onPerfEntry && onPerfEntry instanceof Function) { 3 | import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => { 4 | getCLS(onPerfEntry); 5 | getFID(onPerfEntry); 6 | getFCP(onPerfEntry); 7 | getLCP(onPerfEntry); 8 | getTTFB(onPerfEntry); 9 | }); 10 | } 11 | }; 12 | 13 | export default reportWebVitals; 14 | -------------------------------------------------------------------------------- /book-ui/src/setupTests.js: -------------------------------------------------------------------------------- 1 | // jest-dom adds custom jest matchers for asserting on DOM nodes. 2 | // allows you to do things like: 3 | // expect(element).toHaveTextContent(/react/i) 4 | // learn more: https://github.com/testing-library/jest-dom 5 | import '@testing-library/jest-dom'; 6 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | services: 2 | 3 | postgres: 4 | image: 'postgres:17.2' 5 | container_name: 'postgres' 6 | ports: 7 | - '5432:5432' 8 | environment: 9 | - 'POSTGRES_DB=bookdb' 10 | - 'POSTGRES_PASSWORD=postgres' 11 | - 'POSTGRES_USER=postgres' 12 | healthcheck: 13 | test: 'pg_isready -U postgres' 14 | -------------------------------------------------------------------------------- /documentation/admin-login.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ivangfr/springboot-react-basic-auth/471752eee16d0117380134dc1db3e01bacfc0838/documentation/admin-login.gif -------------------------------------------------------------------------------- /documentation/project-diagram.excalidraw: -------------------------------------------------------------------------------- 1 | { 2 | "type": "excalidraw", 3 | "version": 2, 4 | "source": "https://excalidraw.com", 5 | "elements": [ 6 | { 7 | "type": "rectangle", 8 | "version": 3082, 9 | "versionNonce": 257655844, 10 | "isDeleted": false, 11 | "id": "NKmNZxYxWMCKh3prRiPwX", 12 | "fillStyle": "hachure", 13 | "strokeWidth": 1, 14 | "strokeStyle": "solid", 15 | "roughness": 1, 16 | "opacity": 100, 17 | "angle": 0, 18 | "x": 204.0044730329074, 19 | "y": -169.55636328992398, 20 | "strokeColor": "#000000", 21 | "backgroundColor": "#7950f2", 22 | "width": 209.18356323242188, 23 | "height": 99.67071533203125, 24 | "seed": 2037781404, 25 | "groupIds": [], 26 | "roundness": { 27 | "type": 3 28 | }, 29 | "boundElements": [ 30 | { 31 | "type": "text", 32 | "id": "GrVT2PZuYu1cRv3sXwFoI" 33 | }, 34 | { 35 | "id": "wMakVUD8b1mxxc7dx4nWH", 36 | "type": "arrow" 37 | }, 38 | { 39 | "id": "OK4rrYWkk6F__xTpXxo_B", 40 | "type": "arrow" 41 | }, 42 | { 43 | "id": "1Cz_VJKLix4EmY5n45ZII", 44 | "type": "arrow" 45 | }, 46 | { 47 | "id": "6RBbs6PMcioF6JZngXvvZ", 48 | "type": "arrow" 49 | }, 50 | { 51 | "id": "3YCJny2YM0ehaW_k6SbTh", 52 | "type": "arrow" 53 | }, 54 | { 55 | "id": "qH8MuHg48He9PZpz433J9", 56 | "type": "arrow" 57 | } 58 | ], 59 | "updated": 1678784322077, 60 | "link": null, 61 | "locked": false 62 | }, 63 | { 64 | "type": "text", 65 | "version": 2049, 66 | "versionNonce": 456434802, 67 | "isDeleted": false, 68 | "id": "GrVT2PZuYu1cRv3sXwFoI", 69 | "fillStyle": "hachure", 70 | "strokeWidth": 1, 71 | "strokeStyle": "solid", 72 | "roughness": 0, 73 | "opacity": 100, 74 | "angle": 0, 75 | "x": 254.0942862653293, 76 | "y": -136.52100562390837, 77 | "strokeColor": "#000000", 78 | "backgroundColor": "transparent", 79 | "width": 109.00393676757812, 80 | "height": 33.6, 81 | "seed": 294979727, 82 | "groupIds": [], 83 | "roundness": null, 84 | "boundElements": [], 85 | "updated": 1678291105990, 86 | "link": null, 87 | "locked": false, 88 | "fontSize": 28, 89 | "fontFamily": 1, 90 | "text": "book-api", 91 | "textAlign": "center", 92 | "verticalAlign": "middle", 93 | "containerId": "NKmNZxYxWMCKh3prRiPwX", 94 | "originalText": "book-api" 95 | }, 96 | { 97 | "type": "ellipse", 98 | "version": 2084, 99 | "versionNonce": 689921956, 100 | "isDeleted": false, 101 | "id": "zYllgBlgP7S7-phqNnnEr", 102 | "fillStyle": "hachure", 103 | "strokeWidth": 2, 104 | "strokeStyle": "solid", 105 | "roughness": 1, 106 | "opacity": 100, 107 | "angle": 6.272333650882224, 108 | "x": -386.56345433848367, 109 | "y": -171.0095932940548, 110 | "strokeColor": "#000000", 111 | "backgroundColor": "transparent", 112 | "width": 26.930389404296875, 113 | "height": 27.545562744140625, 114 | "seed": 1227440156, 115 | "groupIds": [ 116 | "4D1ojplACrlVIaNZ7P0FH" 117 | ], 118 | "roundness": { 119 | "type": 2 120 | }, 121 | "boundElements": [], 122 | "updated": 1678784322077, 123 | "link": null, 124 | "locked": false 125 | }, 126 | { 127 | "type": "line", 128 | "version": 2102, 129 | "versionNonce": 618384164, 130 | "isDeleted": false, 131 | "id": "iW_3iMfYwsgECYYtnEK33", 132 | "fillStyle": "hachure", 133 | "strokeWidth": 2, 134 | "strokeStyle": "solid", 135 | "roughness": 1, 136 | "opacity": 100, 137 | "angle": 6.272333650882224, 138 | "x": -374.75206279522524, 139 | "y": -142.98641015922834, 140 | "strokeColor": "#000000", 141 | "backgroundColor": "transparent", 142 | "width": 0.473419189453125, 143 | "height": 40.3687744140625, 144 | "seed": 46324892, 145 | "groupIds": [ 146 | "4D1ojplACrlVIaNZ7P0FH" 147 | ], 148 | "roundness": { 149 | "type": 2 150 | }, 151 | "boundElements": [], 152 | "updated": 1678784322077, 153 | "link": null, 154 | "locked": false, 155 | "startBinding": null, 156 | "endBinding": null, 157 | "lastCommittedPoint": null, 158 | "startArrowhead": null, 159 | "endArrowhead": null, 160 | "points": [ 161 | [ 162 | 0, 163 | 0 164 | ], 165 | [ 166 | -0.473419189453125, 167 | 40.3687744140625 168 | ] 169 | ] 170 | }, 171 | { 172 | "type": "line", 173 | "version": 2053, 174 | "versionNonce": 1425983140, 175 | "isDeleted": false, 176 | "id": "8JTNvN86yjteIVYunsqxA", 177 | "fillStyle": "hachure", 178 | "strokeWidth": 2, 179 | "strokeStyle": "solid", 180 | "roughness": 1, 181 | "opacity": 100, 182 | "angle": 6.272333650882224, 183 | "x": -374.6284461437564, 184 | "y": -101.0909962747977, 185 | "strokeColor": "#000000", 186 | "backgroundColor": "transparent", 187 | "width": 17.21380615234375, 188 | "height": 33.91400146484375, 189 | "seed": 2146756892, 190 | "groupIds": [ 191 | "4D1ojplACrlVIaNZ7P0FH" 192 | ], 193 | "roundness": { 194 | "type": 2 195 | }, 196 | "boundElements": [], 197 | "updated": 1678784322077, 198 | "link": null, 199 | "locked": false, 200 | "startBinding": null, 201 | "endBinding": null, 202 | "lastCommittedPoint": null, 203 | "startArrowhead": null, 204 | "endArrowhead": null, 205 | "points": [ 206 | [ 207 | 0, 208 | 0 209 | ], 210 | [ 211 | -17.21380615234375, 212 | 33.91400146484375 213 | ] 214 | ] 215 | }, 216 | { 217 | "type": "line", 218 | "version": 2072, 219 | "versionNonce": 238440996, 220 | "isDeleted": false, 221 | "id": "hMliKg9HCYu-lEplUg1Y6", 222 | "fillStyle": "hachure", 223 | "strokeWidth": 2, 224 | "strokeStyle": "solid", 225 | "roughness": 1, 226 | "opacity": 100, 227 | "angle": 6.272333650882224, 228 | "x": -374.5054037920221, 229 | "y": -101.13573746737603, 230 | "strokeColor": "#000000", 231 | "backgroundColor": "transparent", 232 | "width": 12.9422607421875, 233 | "height": 35.16510009765625, 234 | "seed": 338781596, 235 | "groupIds": [ 236 | "4D1ojplACrlVIaNZ7P0FH" 237 | ], 238 | "roundness": { 239 | "type": 2 240 | }, 241 | "boundElements": [], 242 | "updated": 1678784322077, 243 | "link": null, 244 | "locked": false, 245 | "startBinding": null, 246 | "endBinding": null, 247 | "lastCommittedPoint": null, 248 | "startArrowhead": null, 249 | "endArrowhead": null, 250 | "points": [ 251 | [ 252 | 0, 253 | 0 254 | ], 255 | [ 256 | 12.9422607421875, 257 | 35.16510009765625 258 | ] 259 | ] 260 | }, 261 | { 262 | "type": "line", 263 | "version": 2088, 264 | "versionNonce": 1601203620, 265 | "isDeleted": false, 266 | "id": "pnA0DA25tJxDKgaSQnlkY", 267 | "fillStyle": "hachure", 268 | "strokeWidth": 2, 269 | "strokeStyle": "solid", 270 | "roughness": 1, 271 | "opacity": 100, 272 | "angle": 6.272333650882224, 273 | "x": -373.87986759573437, 274 | "y": -125.66100538125949, 275 | "strokeColor": "#000000", 276 | "backgroundColor": "transparent", 277 | "width": 29.445220947265625, 278 | "height": 20.990234375, 279 | "seed": 1420448284, 280 | "groupIds": [ 281 | "4D1ojplACrlVIaNZ7P0FH" 282 | ], 283 | "roundness": { 284 | "type": 2 285 | }, 286 | "boundElements": [], 287 | "updated": 1678784322077, 288 | "link": null, 289 | "locked": false, 290 | "startBinding": null, 291 | "endBinding": null, 292 | "lastCommittedPoint": null, 293 | "startArrowhead": null, 294 | "endArrowhead": null, 295 | "points": [ 296 | [ 297 | 0, 298 | 0 299 | ], 300 | [ 301 | 29.445220947265625, 302 | -20.990234375 303 | ] 304 | ] 305 | }, 306 | { 307 | "type": "line", 308 | "version": 2127, 309 | "versionNonce": 1239095588, 310 | "isDeleted": false, 311 | "id": "HhvpXqS4JXS1iu_1aiVep", 312 | "fillStyle": "hachure", 313 | "strokeWidth": 2, 314 | "strokeStyle": "solid", 315 | "roughness": 1, 316 | "opacity": 100, 317 | "angle": 6.272333650882224, 318 | "x": -374.7166237844051, 319 | "y": -126.08411903827829, 320 | "strokeColor": "#000000", 321 | "backgroundColor": "transparent", 322 | "width": 25.4169921875, 323 | "height": 9.85821533203125, 324 | "seed": 1615965852, 325 | "groupIds": [ 326 | "4D1ojplACrlVIaNZ7P0FH" 327 | ], 328 | "roundness": { 329 | "type": 2 330 | }, 331 | "boundElements": [], 332 | "updated": 1678784322077, 333 | "link": null, 334 | "locked": false, 335 | "startBinding": null, 336 | "endBinding": null, 337 | "lastCommittedPoint": null, 338 | "startArrowhead": null, 339 | "endArrowhead": null, 340 | "points": [ 341 | [ 342 | 0, 343 | 0 344 | ], 345 | [ 346 | -25.4169921875, 347 | -9.85821533203125 348 | ] 349 | ] 350 | }, 351 | { 352 | "type": "text", 353 | "version": 2205, 354 | "versionNonce": 2028229796, 355 | "isDeleted": false, 356 | "id": "T0m-48lm7wA_Uw99BXSmk", 357 | "fillStyle": "hachure", 358 | "strokeWidth": 2, 359 | "strokeStyle": "solid", 360 | "roughness": 1, 361 | "opacity": 100, 362 | "angle": 6.272333650882224, 363 | "x": -399.56602362354784, 364 | "y": -224.07537806484228, 365 | "strokeColor": "#000000", 366 | "backgroundColor": "transparent", 367 | "width": 70.87995910644531, 368 | "height": 48, 369 | "seed": 668564252, 370 | "groupIds": [ 371 | "4D1ojplACrlVIaNZ7P0FH" 372 | ], 373 | "roundness": null, 374 | "boundElements": [], 375 | "updated": 1678784322077, 376 | "link": null, 377 | "locked": false, 378 | "fontSize": 20, 379 | "fontFamily": 1, 380 | "text": "Admin /\nUser", 381 | "textAlign": "left", 382 | "verticalAlign": "top", 383 | "containerId": null, 384 | "originalText": "Admin /\nUser" 385 | }, 386 | { 387 | "type": "rectangle", 388 | "version": 3145, 389 | "versionNonce": 2050629668, 390 | "isDeleted": false, 391 | "id": "D1l-2El2Gpsr55PhX9Msm", 392 | "fillStyle": "hachure", 393 | "strokeWidth": 1, 394 | "strokeStyle": "solid", 395 | "roughness": 1, 396 | "opacity": 100, 397 | "angle": 0, 398 | "x": -225.53199811175386, 399 | "y": -168.29568213758023, 400 | "strokeColor": "#000000", 401 | "backgroundColor": "#228be6", 402 | "width": 209.18356323242188, 403 | "height": 99.67071533203125, 404 | "seed": 900970396, 405 | "groupIds": [], 406 | "roundness": { 407 | "type": 3 408 | }, 409 | "boundElements": [ 410 | { 411 | "type": "text", 412 | "id": "Hr9npzlHGUYC828WZTRBC" 413 | }, 414 | { 415 | "id": "OK4rrYWkk6F__xTpXxo_B", 416 | "type": "arrow" 417 | }, 418 | { 419 | "id": "7ZHeB_svF5YPuNu0CndOh", 420 | "type": "arrow" 421 | }, 422 | { 423 | "id": "3YCJny2YM0ehaW_k6SbTh", 424 | "type": "arrow" 425 | }, 426 | { 427 | "id": "ZE5SJf-9sD79ItE-Y4ZgZ", 428 | "type": "arrow" 429 | } 430 | ], 431 | "updated": 1678784322077, 432 | "link": null, 433 | "locked": false 434 | }, 435 | { 436 | "type": "text", 437 | "version": 2122, 438 | "versionNonce": 1113055982, 439 | "isDeleted": false, 440 | "id": "Hr9npzlHGUYC828WZTRBC", 441 | "fillStyle": "hachure", 442 | "strokeWidth": 1, 443 | "strokeStyle": "solid", 444 | "roughness": 0, 445 | "opacity": 100, 446 | "angle": 0, 447 | "x": -167.15419049456636, 448 | "y": -135.26032447156462, 449 | "strokeColor": "#000000", 450 | "backgroundColor": "transparent", 451 | "width": 92.42794799804688, 452 | "height": 33.6, 453 | "seed": 68814578, 454 | "groupIds": [], 455 | "roundness": null, 456 | "boundElements": [], 457 | "updated": 1678291082859, 458 | "link": null, 459 | "locked": false, 460 | "fontSize": 28, 461 | "fontFamily": 1, 462 | "text": "book-ui", 463 | "textAlign": "center", 464 | "verticalAlign": "middle", 465 | "containerId": "D1l-2El2Gpsr55PhX9Msm", 466 | "originalText": "book-ui" 467 | }, 468 | { 469 | "type": "rectangle", 470 | "version": 968, 471 | "versionNonce": 1976204196, 472 | "isDeleted": false, 473 | "id": "0tFsB5XswcFk43y4cu2nN", 474 | "fillStyle": "hachure", 475 | "strokeWidth": 1, 476 | "strokeStyle": "solid", 477 | "roughness": 1, 478 | "opacity": 100, 479 | "angle": 0, 480 | "x": 535.8107497507344, 481 | "y": -187.73431128797085, 482 | "strokeColor": "#000000", 483 | "backgroundColor": "#ced4da", 484 | "width": 297, 485 | "height": 138, 486 | "seed": 1980916764, 487 | "groupIds": [ 488 | "VYxzlFTCd547xQKFY-Zwf" 489 | ], 490 | "roundness": { 491 | "type": 3 492 | }, 493 | "boundElements": [ 494 | { 495 | "type": "text", 496 | "id": "0-UtAJfoU5Uba-J7Vn9NQ" 497 | }, 498 | { 499 | "id": "wMakVUD8b1mxxc7dx4nWH", 500 | "type": "arrow" 501 | } 502 | ], 503 | "updated": 1678784322077, 504 | "link": null, 505 | "locked": false 506 | }, 507 | { 508 | "type": "text", 509 | "version": 302, 510 | "versionNonce": 1707304740, 511 | "isDeleted": false, 512 | "id": "0-UtAJfoU5Uba-J7Vn9NQ", 513 | "fillStyle": "hachure", 514 | "strokeWidth": 1, 515 | "strokeStyle": "solid", 516 | "roughness": 1, 517 | "opacity": 100, 518 | "angle": 0, 519 | "x": 623.4947707468282, 520 | "y": -152.33431128797085, 521 | "strokeColor": "#000000", 522 | "backgroundColor": "transparent", 523 | "width": 121.6319580078125, 524 | "height": 67.2, 525 | "seed": 2129100956, 526 | "groupIds": [ 527 | "VYxzlFTCd547xQKFY-Zwf" 528 | ], 529 | "roundness": null, 530 | "boundElements": [], 531 | "updated": 1678784322077, 532 | "link": null, 533 | "locked": false, 534 | "fontSize": 28, 535 | "fontFamily": 1, 536 | "text": "Postgres\n", 537 | "textAlign": "center", 538 | "verticalAlign": "middle", 539 | "containerId": "0tFsB5XswcFk43y4cu2nN", 540 | "originalText": "Postgres\n" 541 | }, 542 | { 543 | "type": "rectangle", 544 | "version": 2925, 545 | "versionNonce": 1318249124, 546 | "isDeleted": false, 547 | "id": "c-x7JT7lJ2rumNaXMLIlM", 548 | "fillStyle": "hachure", 549 | "strokeWidth": 1, 550 | "strokeStyle": "solid", 551 | "roughness": 1, 552 | "opacity": 100, 553 | "angle": 0, 554 | "x": 551.0673392918711, 555 | "y": -113.7574665003732, 556 | "strokeColor": "#000000", 557 | "backgroundColor": "#fab005", 558 | "width": 125.44757690429688, 559 | "height": 53.381947618849736, 560 | "seed": 1474628892, 561 | "groupIds": [ 562 | "Bg-OWi1IAZwQFqZ6y7Dkp", 563 | "VYxzlFTCd547xQKFY-Zwf" 564 | ], 565 | "roundness": { 566 | "type": 3 567 | }, 568 | "boundElements": [ 569 | { 570 | "type": "text", 571 | "id": "bZz1uQCoDc1O5J5lJDsL-" 572 | }, 573 | { 574 | "id": "6RBbs6PMcioF6JZngXvvZ", 575 | "type": "arrow" 576 | } 577 | ], 578 | "updated": 1678784322077, 579 | "link": null, 580 | "locked": false 581 | }, 582 | { 583 | "type": "text", 584 | "version": 2349, 585 | "versionNonce": 1994845732, 586 | "isDeleted": false, 587 | "id": "bZz1uQCoDc1O5J5lJDsL-", 588 | "fillStyle": "hachure", 589 | "strokeWidth": 1, 590 | "strokeStyle": "solid", 591 | "roughness": 1, 592 | "opacity": 100, 593 | "angle": 0, 594 | "x": 587.3311591771251, 595 | "y": -99.06649269094834, 596 | "strokeColor": "#000000", 597 | "backgroundColor": "transparent", 598 | "width": 52.91993713378906, 599 | "height": 24, 600 | "seed": 1115490716, 601 | "groupIds": [ 602 | "Bg-OWi1IAZwQFqZ6y7Dkp", 603 | "VYxzlFTCd547xQKFY-Zwf" 604 | ], 605 | "roundness": null, 606 | "boundElements": [], 607 | "updated": 1678784322077, 608 | "link": null, 609 | "locked": false, 610 | "fontSize": 20, 611 | "fontFamily": 1, 612 | "text": "books", 613 | "textAlign": "center", 614 | "verticalAlign": "middle", 615 | "containerId": "c-x7JT7lJ2rumNaXMLIlM", 616 | "originalText": "books" 617 | }, 618 | { 619 | "type": "rectangle", 620 | "version": 2966, 621 | "versionNonce": 531466660, 622 | "isDeleted": false, 623 | "id": "wjrXRaCE6Yj-C4HcYMJ9q", 624 | "fillStyle": "hachure", 625 | "strokeWidth": 1, 626 | "strokeStyle": "solid", 627 | "roughness": 1, 628 | "opacity": 100, 629 | "angle": 0, 630 | "x": 696.6193812827773, 631 | "y": -115.87744301902461, 632 | "strokeColor": "#000000", 633 | "backgroundColor": "#fab005", 634 | "width": 125.44757690429688, 635 | "height": 53.381947618849736, 636 | "seed": 31553052, 637 | "groupIds": [ 638 | "wAK919OTmyvqIKDdj1YZy", 639 | "VYxzlFTCd547xQKFY-Zwf" 640 | ], 641 | "roundness": { 642 | "type": 3 643 | }, 644 | "boundElements": [ 645 | { 646 | "type": "text", 647 | "id": "eONTCMsXWPVZu9wq9FMro" 648 | }, 649 | { 650 | "id": "wMakVUD8b1mxxc7dx4nWH", 651 | "type": "arrow" 652 | } 653 | ], 654 | "updated": 1678784322077, 655 | "link": null, 656 | "locked": false 657 | }, 658 | { 659 | "type": "text", 660 | "version": 2394, 661 | "versionNonce": 1007990052, 662 | "isDeleted": false, 663 | "id": "eONTCMsXWPVZu9wq9FMro", 664 | "fillStyle": "hachure", 665 | "strokeWidth": 1, 666 | "strokeStyle": "solid", 667 | "roughness": 1, 668 | "opacity": 100, 669 | "angle": 0, 670 | "x": 733.0332026939102, 671 | "y": -101.18646920959975, 672 | "strokeColor": "#000000", 673 | "backgroundColor": "transparent", 674 | "width": 52.61993408203125, 675 | "height": 24, 676 | "seed": 587485852, 677 | "groupIds": [ 678 | "wAK919OTmyvqIKDdj1YZy", 679 | "VYxzlFTCd547xQKFY-Zwf" 680 | ], 681 | "roundness": null, 682 | "boundElements": [], 683 | "updated": 1678784322077, 684 | "link": null, 685 | "locked": false, 686 | "fontSize": 20, 687 | "fontFamily": 1, 688 | "text": "users", 689 | "textAlign": "center", 690 | "verticalAlign": "middle", 691 | "containerId": "wjrXRaCE6Yj-C4HcYMJ9q", 692 | "originalText": "users" 693 | }, 694 | { 695 | "type": "arrow", 696 | "version": 494, 697 | "versionNonce": 1843469678, 698 | "isDeleted": false, 699 | "id": "wMakVUD8b1mxxc7dx4nWH", 700 | "fillStyle": "hachure", 701 | "strokeWidth": 1, 702 | "strokeStyle": "solid", 703 | "roughness": 1, 704 | "opacity": 100, 705 | "angle": 0, 706 | "x": 422.9042659263321, 707 | "y": -101.39150489636839, 708 | "strokeColor": "#000000", 709 | "backgroundColor": "transparent", 710 | "width": 334.7559814453125, 711 | "height": 87.61696669836434, 712 | "seed": 294319406, 713 | "groupIds": [], 714 | "roundness": { 715 | "type": 2 716 | }, 717 | "boundElements": [ 718 | { 719 | "type": "text", 720 | "id": "_rNYE2UpkpewKRRsL2NQY" 721 | } 722 | ], 723 | "updated": 1678291114911, 724 | "link": null, 725 | "locked": false, 726 | "startBinding": { 727 | "elementId": "NKmNZxYxWMCKh3prRiPwX", 728 | "focus": -0.5416187830852912, 729 | "gap": 9.716229661002785 730 | }, 731 | "endBinding": { 732 | "elementId": "wjrXRaCE6Yj-C4HcYMJ9q", 733 | "focus": -0.9246393232716618, 734 | "gap": 8.688394946311455 735 | }, 736 | "lastCommittedPoint": null, 737 | "startArrowhead": "arrow", 738 | "endArrowhead": "arrow", 739 | "points": [ 740 | [ 741 | 0, 742 | 0 743 | ], 744 | [ 745 | 111.46905517578125, 746 | 87.61696669836434 747 | ], 748 | [ 749 | 334.7559814453125, 750 | 47.58440444250496 751 | ] 752 | ] 753 | }, 754 | { 755 | "type": "text", 756 | "version": 45, 757 | "versionNonce": 1150787356, 758 | "isDeleted": false, 759 | "id": "_rNYE2UpkpewKRRsL2NQY", 760 | "fillStyle": "hachure", 761 | "strokeWidth": 1, 762 | "strokeStyle": "solid", 763 | "roughness": 1, 764 | "opacity": 100, 765 | "angle": 0, 766 | "x": 468.2933803062149, 767 | "y": -37.77453819800405, 768 | "strokeColor": "#000000", 769 | "backgroundColor": "transparent", 770 | "width": 132.15988159179688, 771 | "height": 48, 772 | "seed": 454937906, 773 | "groupIds": [], 774 | "roundness": null, 775 | "boundElements": [], 776 | "updated": 1678784357584, 777 | "link": null, 778 | "locked": false, 779 | "fontSize": 20, 780 | "fontFamily": 1, 781 | "text": "validate user\ncredentials", 782 | "textAlign": "center", 783 | "verticalAlign": "middle", 784 | "containerId": "wMakVUD8b1mxxc7dx4nWH", 785 | "originalText": "validate user\ncredentials" 786 | }, 787 | { 788 | "type": "arrow", 789 | "version": 421, 790 | "versionNonce": 1950196594, 791 | "isDeleted": false, 792 | "id": "OK4rrYWkk6F__xTpXxo_B", 793 | "fillStyle": "hachure", 794 | "strokeWidth": 1, 795 | "strokeStyle": "solid", 796 | "roughness": 1, 797 | "opacity": 100, 798 | "angle": 0, 799 | "x": -7.727081729917913, 800 | "y": -114.42750437012981, 801 | "strokeColor": "#c92a2a", 802 | "backgroundColor": "transparent", 803 | "width": 209.65014648437494, 804 | "height": 19.46782240209299, 805 | "seed": 1912426158, 806 | "groupIds": [], 807 | "roundness": { 808 | "type": 2 809 | }, 810 | "boundElements": [ 811 | { 812 | "type": "text", 813 | "id": "pbmjFkZW23WHV9cf3PVFI" 814 | } 815 | ], 816 | "updated": 1678291559542, 817 | "link": null, 818 | "locked": false, 819 | "startBinding": { 820 | "elementId": "D1l-2El2Gpsr55PhX9Msm", 821 | "focus": 0.38274981497285765, 822 | "gap": 8.621353149414077 823 | }, 824 | "endBinding": { 825 | "elementId": "NKmNZxYxWMCKh3prRiPwX", 826 | "focus": -0.2962075030930993, 827 | "gap": 2.0814082784503967 828 | }, 829 | "lastCommittedPoint": null, 830 | "startArrowhead": null, 831 | "endArrowhead": "arrow", 832 | "points": [ 833 | [ 834 | 0, 835 | 0 836 | ], 837 | [ 838 | 94.71484374999999, 839 | -19.46782240209299 840 | ], 841 | [ 842 | 209.65014648437494, 843 | -2.0214544099642637 844 | ] 845 | ] 846 | }, 847 | { 848 | "type": "text", 849 | "version": 49, 850 | "versionNonce": 1233668210, 851 | "isDeleted": false, 852 | "id": "pbmjFkZW23WHV9cf3PVFI", 853 | "fillStyle": "hachure", 854 | "strokeWidth": 1, 855 | "strokeStyle": "solid", 856 | "roughness": 1, 857 | "opacity": 100, 858 | "angle": 0, 859 | "x": 18.10781054303129, 860 | "y": -157.8953267722228, 861 | "strokeColor": "#c92a2a", 862 | "backgroundColor": "#228be6", 863 | "width": 137.75990295410156, 864 | "height": 48, 865 | "seed": 51819570, 866 | "groupIds": [], 867 | "roundness": null, 868 | "boundElements": [], 869 | "updated": 1678291571341, 870 | "link": null, 871 | "locked": false, 872 | "fontSize": 20, 873 | "fontFamily": 1, 874 | "text": "2. username /\npassword", 875 | "textAlign": "center", 876 | "verticalAlign": "middle", 877 | "containerId": "OK4rrYWkk6F__xTpXxo_B", 878 | "originalText": "2. username /\npassword" 879 | }, 880 | { 881 | "type": "arrow", 882 | "version": 453, 883 | "versionNonce": 1532781874, 884 | "isDeleted": false, 885 | "id": "7ZHeB_svF5YPuNu0CndOh", 886 | "fillStyle": "hachure", 887 | "strokeWidth": 1, 888 | "strokeStyle": "solid", 889 | "roughness": 1, 890 | "opacity": 100, 891 | "angle": 0, 892 | "x": -354.3360294838242, 893 | "y": -102.08554283667593, 894 | "strokeColor": "#c92a2a", 895 | "backgroundColor": "transparent", 896 | "width": 209.53756941599426, 897 | "height": 71.99673461914062, 898 | "seed": 142027186, 899 | "groupIds": [], 900 | "roundness": { 901 | "type": 2 902 | }, 903 | "boundElements": [ 904 | { 905 | "type": "text", 906 | "id": "40yx8P5DPlaDDpwK10QeS" 907 | } 908 | ], 909 | "updated": 1678291559542, 910 | "link": null, 911 | "locked": false, 912 | "startBinding": null, 913 | "endBinding": { 914 | "elementId": "D1l-2El2Gpsr55PhX9Msm", 915 | "focus": -0.6354823632336648, 916 | "gap": 6.878748920044927 917 | }, 918 | "lastCommittedPoint": null, 919 | "startArrowhead": null, 920 | "endArrowhead": "arrow", 921 | "points": [ 922 | [ 923 | 0, 924 | 0 925 | ], 926 | [ 927 | 95.36376953125, 928 | 71.99673461914062 929 | ], 930 | [ 931 | 209.53756941599426, 932 | 40.339324951171875 933 | ] 934 | ] 935 | }, 936 | { 937 | "type": "text", 938 | "version": 37, 939 | "versionNonce": 2091749746, 940 | "isDeleted": false, 941 | "id": "40yx8P5DPlaDDpwK10QeS", 942 | "fillStyle": "hachure", 943 | "strokeWidth": 1, 944 | "strokeStyle": "solid", 945 | "roughness": 1, 946 | "opacity": 100, 947 | "angle": 0, 948 | "x": -323.4422153969101, 949 | "y": -54.0888082175353, 950 | "strokeColor": "#c92a2a", 951 | "backgroundColor": "transparent", 952 | "width": 128.93991088867188, 953 | "height": 48, 954 | "seed": 287977906, 955 | "groupIds": [], 956 | "roundness": null, 957 | "boundElements": [], 958 | "updated": 1678291566556, 959 | "link": null, 960 | "locked": false, 961 | "fontSize": 20, 962 | "fontFamily": 1, 963 | "text": "1. username /\npassword", 964 | "textAlign": "center", 965 | "verticalAlign": "middle", 966 | "containerId": "7ZHeB_svF5YPuNu0CndOh", 967 | "originalText": "1. username /\npassword" 968 | }, 969 | { 970 | "type": "arrow", 971 | "version": 295, 972 | "versionNonce": 650744498, 973 | "isDeleted": false, 974 | "id": "1Cz_VJKLix4EmY5n45ZII", 975 | "fillStyle": "hachure", 976 | "strokeWidth": 1, 977 | "strokeStyle": "solid", 978 | "roughness": 1, 979 | "opacity": 100, 980 | "angle": 0, 981 | "x": -347.0024723549179, 982 | "y": -134.3574849753478, 983 | "strokeColor": "#0b7285", 984 | "backgroundColor": "transparent", 985 | "width": 543.63037109375, 986 | "height": 76.808837890625, 987 | "seed": 1910303598, 988 | "groupIds": [], 989 | "roundness": { 990 | "type": 2 991 | }, 992 | "boundElements": [ 993 | { 994 | "type": "text", 995 | "id": "GaGrnTXdoKPDyBaQ1RDdF" 996 | } 997 | ], 998 | "updated": 1678291541020, 999 | "link": null, 1000 | "locked": false, 1001 | "startBinding": null, 1002 | "endBinding": { 1003 | "elementId": "NKmNZxYxWMCKh3prRiPwX", 1004 | "focus": 0.12536741860437922, 1005 | "gap": 7.37657429407534 1006 | }, 1007 | "lastCommittedPoint": null, 1008 | "startArrowhead": null, 1009 | "endArrowhead": "arrow", 1010 | "points": [ 1011 | [ 1012 | 0, 1013 | 0 1014 | ], 1015 | [ 1016 | 232.83929443359375, 1017 | -76.808837890625 1018 | ], 1019 | [ 1020 | 543.63037109375, 1021 | -16.06013209565924 1022 | ] 1023 | ] 1024 | }, 1025 | { 1026 | "type": "text", 1027 | "version": 30, 1028 | "versionNonce": 844343662, 1029 | "isDeleted": false, 1030 | "id": "GaGrnTXdoKPDyBaQ1RDdF", 1031 | "fillStyle": "hachure", 1032 | "strokeWidth": 1, 1033 | "strokeStyle": "solid", 1034 | "roughness": 1, 1035 | "opacity": 100, 1036 | "angle": 0, 1037 | "x": -178.63313336566011, 1038 | "y": -235.1663228659728, 1039 | "strokeColor": "#0b7285", 1040 | "backgroundColor": "transparent", 1041 | "width": 128.93991088867188, 1042 | "height": 48, 1043 | "seed": 855114222, 1044 | "groupIds": [], 1045 | "roundness": null, 1046 | "boundElements": [], 1047 | "updated": 1678291541020, 1048 | "link": null, 1049 | "locked": false, 1050 | "fontSize": 20, 1051 | "fontFamily": 1, 1052 | "text": "1. username /\npassword", 1053 | "textAlign": "center", 1054 | "verticalAlign": "middle", 1055 | "containerId": "1Cz_VJKLix4EmY5n45ZII", 1056 | "originalText": "1. username /\npassword" 1057 | }, 1058 | { 1059 | "type": "arrow", 1060 | "version": 388, 1061 | "versionNonce": 2107266606, 1062 | "isDeleted": false, 1063 | "id": "6RBbs6PMcioF6JZngXvvZ", 1064 | "fillStyle": "hachure", 1065 | "strokeWidth": 1, 1066 | "strokeStyle": "solid", 1067 | "roughness": 1, 1068 | "opacity": 100, 1069 | "angle": 0, 1070 | "x": 422.49117144095754, 1071 | "y": -125.04049523199942, 1072 | "strokeColor": "#000000", 1073 | "backgroundColor": "transparent", 1074 | "width": 169.09644409474953, 1075 | "height": 61.88470458984376, 1076 | "seed": 1502029166, 1077 | "groupIds": [], 1078 | "roundness": { 1079 | "type": 2 1080 | }, 1081 | "boundElements": [ 1082 | { 1083 | "type": "text", 1084 | "id": "FWdrtotwnAY6Lz1OmD-Ie" 1085 | } 1086 | ], 1087 | "updated": 1678291111791, 1088 | "link": null, 1089 | "locked": false, 1090 | "startBinding": { 1091 | "elementId": "NKmNZxYxWMCKh3prRiPwX", 1092 | "focus": 0.5835799151203056, 1093 | "gap": 9.303135175628256 1094 | }, 1095 | "endBinding": { 1096 | "elementId": "c-x7JT7lJ2rumNaXMLIlM", 1097 | "focus": 0.21990874704058386, 1098 | "gap": 6.620190594115705 1099 | }, 1100 | "lastCommittedPoint": null, 1101 | "startArrowhead": "arrow", 1102 | "endArrowhead": "arrow", 1103 | "points": [ 1104 | [ 1105 | 0, 1106 | 0 1107 | ], 1108 | [ 1109 | 87.9180061856793, 1110 | -57.221866452333245 1111 | ], 1112 | [ 1113 | 169.09644409474953, 1114 | 4.662838137510512 1115 | ] 1116 | ] 1117 | }, 1118 | { 1119 | "type": "text", 1120 | "version": 8, 1121 | "versionNonce": 696938660, 1122 | "isDeleted": false, 1123 | "id": "FWdrtotwnAY6Lz1OmD-Ie", 1124 | "fillStyle": "hachure", 1125 | "strokeWidth": 1, 1126 | "strokeStyle": "solid", 1127 | "roughness": 1, 1128 | "opacity": 100, 1129 | "angle": 0, 1130 | "x": 482.24918922331653, 1131 | "y": -194.26236168433266, 1132 | "strokeColor": "#000000", 1133 | "backgroundColor": "transparent", 1134 | "width": 56.319976806640625, 1135 | "height": 24, 1136 | "seed": 1788055726, 1137 | "groupIds": [], 1138 | "roundness": null, 1139 | "boundElements": [], 1140 | "updated": 1678784357585, 1141 | "link": null, 1142 | "locked": false, 1143 | "fontSize": 20, 1144 | "fontFamily": 1, 1145 | "text": "CRUD", 1146 | "textAlign": "center", 1147 | "verticalAlign": "middle", 1148 | "containerId": "6RBbs6PMcioF6JZngXvvZ", 1149 | "originalText": "CRUD" 1150 | }, 1151 | { 1152 | "type": "arrow", 1153 | "version": 115, 1154 | "versionNonce": 2092756722, 1155 | "isDeleted": false, 1156 | "id": "3YCJny2YM0ehaW_k6SbTh", 1157 | "fillStyle": "hachure", 1158 | "strokeWidth": 1, 1159 | "strokeStyle": "solid", 1160 | "roughness": 1, 1161 | "opacity": 100, 1162 | "angle": 0, 1163 | "x": 194.13827471539457, 1164 | "y": -95.48571983862905, 1165 | "strokeColor": "#c92a2a", 1166 | "backgroundColor": "#228be6", 1167 | "width": 202.8658447265625, 1168 | "height": 9.685333251953125, 1169 | "seed": 970301618, 1170 | "groupIds": [], 1171 | "roundness": { 1172 | "type": 2 1173 | }, 1174 | "boundElements": [ 1175 | { 1176 | "type": "text", 1177 | "id": "TdtrD1cY0uAKUlxGuRtne" 1178 | } 1179 | ], 1180 | "updated": 1678291559542, 1181 | "link": null, 1182 | "locked": false, 1183 | "startBinding": { 1184 | "elementId": "NKmNZxYxWMCKh3prRiPwX", 1185 | "focus": -0.23603208638818188, 1186 | "gap": 9.86619831751284 1187 | }, 1188 | "endBinding": { 1189 | "elementId": "D1l-2El2Gpsr55PhX9Msm", 1190 | "focus": 0.3683606651113619, 1191 | "gap": 7.6208648681640625 1192 | }, 1193 | "lastCommittedPoint": null, 1194 | "startArrowhead": null, 1195 | "endArrowhead": "arrow", 1196 | "points": [ 1197 | [ 1198 | 0, 1199 | 0 1200 | ], 1201 | [ 1202 | -108.05059814453125, 1203 | 9.685333251953125 1204 | ], 1205 | [ 1206 | -202.8658447265625, 1207 | 4.162750244140625 1208 | ] 1209 | ] 1210 | }, 1211 | { 1212 | "type": "text", 1213 | "version": 15, 1214 | "versionNonce": 295110066, 1215 | "isDeleted": false, 1216 | "id": "TdtrD1cY0uAKUlxGuRtne", 1217 | "fillStyle": "hachure", 1218 | "strokeWidth": 1, 1219 | "strokeStyle": "solid", 1220 | "roughness": 1, 1221 | "opacity": 100, 1222 | "angle": 0, 1223 | "x": 51.40770678326567, 1224 | "y": -97.80038658667593, 1225 | "strokeColor": "#c92a2a", 1226 | "backgroundColor": "#228be6", 1227 | "width": 69.35993957519531, 1228 | "height": 24, 1229 | "seed": 1966107886, 1230 | "groupIds": [], 1231 | "roundness": null, 1232 | "boundElements": [], 1233 | "updated": 1678291574582, 1234 | "link": null, 1235 | "locked": false, 1236 | "fontSize": 20, 1237 | "fontFamily": 1, 1238 | "text": "3. resp", 1239 | "textAlign": "center", 1240 | "verticalAlign": "middle", 1241 | "containerId": "3YCJny2YM0ehaW_k6SbTh", 1242 | "originalText": "3. resp" 1243 | }, 1244 | { 1245 | "type": "arrow", 1246 | "version": 191, 1247 | "versionNonce": 154684334, 1248 | "isDeleted": false, 1249 | "id": "qH8MuHg48He9PZpz433J9", 1250 | "fillStyle": "hachure", 1251 | "strokeWidth": 1, 1252 | "strokeStyle": "solid", 1253 | "roughness": 1, 1254 | "opacity": 100, 1255 | "angle": 0, 1256 | "x": 205.13394121930082, 1257 | "y": -173.89575401831655, 1258 | "strokeColor": "#0b7285", 1259 | "backgroundColor": "#228be6", 1260 | "width": 542.8289794921875, 1261 | "height": 90.85546875, 1262 | "seed": 1366180462, 1263 | "groupIds": [], 1264 | "roundness": { 1265 | "type": 2 1266 | }, 1267 | "boundElements": [ 1268 | { 1269 | "type": "text", 1270 | "id": "ONLOk19kNx7Hkzqfx2ICx" 1271 | } 1272 | ], 1273 | "updated": 1678291546746, 1274 | "link": null, 1275 | "locked": false, 1276 | "startBinding": { 1277 | "elementId": "NKmNZxYxWMCKh3prRiPwX", 1278 | "focus": 0.4051315448223847, 1279 | "gap": 4.339390728392573 1280 | }, 1281 | "endBinding": null, 1282 | "lastCommittedPoint": null, 1283 | "startArrowhead": null, 1284 | "endArrowhead": "arrow", 1285 | "points": [ 1286 | [ 1287 | 0, 1288 | 0 1289 | ], 1290 | [ 1291 | -319.03668212890625, 1292 | -74.3468017578125 1293 | ], 1294 | [ 1295 | -542.8289794921875, 1296 | 16.5086669921875 1297 | ] 1298 | ] 1299 | }, 1300 | { 1301 | "type": "text", 1302 | "version": 11, 1303 | "versionNonce": 2114326066, 1304 | "isDeleted": false, 1305 | "id": "ONLOk19kNx7Hkzqfx2ICx", 1306 | "fillStyle": "hachure", 1307 | "strokeWidth": 1, 1308 | "strokeStyle": "solid", 1309 | "roughness": 1, 1310 | "opacity": 100, 1311 | "angle": 0, 1312 | "x": -148.89270825579683, 1313 | "y": -260.24255577612905, 1314 | "strokeColor": "#0b7285", 1315 | "backgroundColor": "#228be6", 1316 | "width": 69.97993469238281, 1317 | "height": 24, 1318 | "seed": 136559406, 1319 | "groupIds": [], 1320 | "roundness": null, 1321 | "boundElements": [], 1322 | "updated": 1678291546746, 1323 | "link": null, 1324 | "locked": false, 1325 | "fontSize": 20, 1326 | "fontFamily": 1, 1327 | "text": "2. resp", 1328 | "textAlign": "center", 1329 | "verticalAlign": "middle", 1330 | "containerId": "qH8MuHg48He9PZpz433J9", 1331 | "originalText": "2. resp" 1332 | }, 1333 | { 1334 | "type": "arrow", 1335 | "version": 212, 1336 | "versionNonce": 208517678, 1337 | "isDeleted": false, 1338 | "id": "ZE5SJf-9sD79ItE-Y4ZgZ", 1339 | "fillStyle": "hachure", 1340 | "strokeWidth": 1, 1341 | "strokeStyle": "solid", 1342 | "roughness": 1, 1343 | "opacity": 100, 1344 | "angle": 0, 1345 | "x": -89.11160321429293, 1346 | "y": -55.91794029761343, 1347 | "strokeColor": "#c92a2a", 1348 | "backgroundColor": "#228be6", 1349 | "width": 267.8072509765625, 1350 | "height": 74.50341796875, 1351 | "seed": 365296878, 1352 | "groupIds": [], 1353 | "roundness": { 1354 | "type": 2 1355 | }, 1356 | "boundElements": [ 1357 | { 1358 | "type": "text", 1359 | "id": "0nd5llgESbpEYXc_BaexR" 1360 | } 1361 | ], 1362 | "updated": 1678291596668, 1363 | "link": null, 1364 | "locked": false, 1365 | "startBinding": { 1366 | "elementId": "D1l-2El2Gpsr55PhX9Msm", 1367 | "focus": -0.8187052986717684, 1368 | "gap": 12.707026507935552 1369 | }, 1370 | "endBinding": null, 1371 | "lastCommittedPoint": null, 1372 | "startArrowhead": null, 1373 | "endArrowhead": "arrow", 1374 | "points": [ 1375 | [ 1376 | 0, 1377 | 0 1378 | ], 1379 | [ 1380 | -182.8348846435547, 1381 | 73.88641357421875 1382 | ], 1383 | [ 1384 | -267.8072509765625, 1385 | -0.61700439453125 1386 | ] 1387 | ] 1388 | }, 1389 | { 1390 | "type": "text", 1391 | "version": 21, 1392 | "versionNonce": 1594710940, 1393 | "isDeleted": false, 1394 | "id": "0nd5llgESbpEYXc_BaexR", 1395 | "fillStyle": "hachure", 1396 | "strokeWidth": 1, 1397 | "strokeStyle": "solid", 1398 | "roughness": 1, 1399 | "opacity": 100, 1400 | "angle": 0, 1401 | "x": -306.2164539833359, 1402 | "y": 5.968473276605327, 1403 | "strokeColor": "#c92a2a", 1404 | "backgroundColor": "#228be6", 1405 | "width": 68.53993225097656, 1406 | "height": 24, 1407 | "seed": 817133422, 1408 | "groupIds": [], 1409 | "roundness": null, 1410 | "boundElements": [], 1411 | "updated": 1678784357585, 1412 | "link": null, 1413 | "locked": false, 1414 | "fontSize": 20, 1415 | "fontFamily": 1, 1416 | "text": "4. resp", 1417 | "textAlign": "center", 1418 | "verticalAlign": "middle", 1419 | "containerId": "ZE5SJf-9sD79ItE-Y4ZgZ", 1420 | "originalText": "4. resp" 1421 | } 1422 | ], 1423 | "appState": { 1424 | "gridSize": null, 1425 | "viewBackgroundColor": "#ffffff" 1426 | }, 1427 | "files": {} 1428 | } -------------------------------------------------------------------------------- /documentation/project-diagram.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ivangfr/springboot-react-basic-auth/471752eee16d0117380134dc1db3e01bacfc0838/documentation/project-diagram.jpeg -------------------------------------------------------------------------------- /documentation/user-login.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ivangfr/springboot-react-basic-auth/471752eee16d0117380134dc1db3e01bacfc0838/documentation/user-login.gif --------------------------------------------------------------------------------