|
| 1 | +# ROLE WITH PERMISSION THORUGH SPRING SECURITY IN SPRING BOOT |
| 2 | + |
| 3 | +<p align="center"> |
| 4 | + <img src="screenshots/spring_boot_role_permission_main_image.png" alt="Main Information" width="700" height="500"> |
| 5 | +</p> |
| 6 | + |
| 7 | +### 📖 Information |
| 8 | + |
| 9 | +<ul style="list-style-type:disc"> |
| 10 | + <li><b>This</b> is a Spring Boot example covering important and useful features.</li> |
| 11 | + <li>Here is an explanation of the example:</li> |
| 12 | + <ul> |
| 13 | + <li><b>Admin</b> and <b>User</b> implement their own <b>authentication</b> and <b>authorization</b> through their defined <b>role</b> names.</li> |
| 14 | + <li>The <b>Admin</b> handles with the following process shown above: |
| 15 | + <ul> |
| 16 | + <li><b>Admin</b> with <b>Role</b> containing <b>create</b> permission only handles with creating product</li> |
| 17 | + <li><b>Admin</b> with <b>Role</b> containing <b>get</b> permission only handles with getting product by id</li> |
| 18 | + <li><b>Admin</b> with <b>Role</b> containing <b>update</b> permission only handles with updating product by id</li> |
| 19 | + <li><b>Admin</b> with <b>Role</b> containing <b>delete</b> permission only handles with deleting product by id</li> |
| 20 | + </ul> |
| 21 | + </li> |
| 22 | + <li>The <b>User</b> handles with the following process shown above: |
| 23 | + <ul> |
| 24 | + <li><b>User</b> with <b>Role</b> containing <b>get</b> permission only handles with getting product by id</li> |
| 25 | + </ul> |
| 26 | + </li> |
| 27 | + </ul> |
| 28 | +</ul> |
| 29 | + |
| 30 | + |
| 31 | +### Explore Rest APIs |
| 32 | + |
| 33 | +<table style="width:100%"> |
| 34 | + <tr> |
| 35 | + <th>Method</th> |
| 36 | + <th>Url</th> |
| 37 | + <th>Description</th> |
| 38 | + <th>Request Body</th> |
| 39 | + <th>Header</th> |
| 40 | + <th>Valid Path Variable</th> |
| 41 | + <th>No Path Variable</th> |
| 42 | + </tr> |
| 43 | + <tr> |
| 44 | + <td>POST</td> |
| 45 | + <td>/api/v1/authentication/user/register</td> |
| 46 | + <td>User Register</td> |
| 47 | + <td>RegisterRequest</td> |
| 48 | + <td></td> |
| 49 | + <td></td> |
| 50 | + <td></td> |
| 51 | + <tr> |
| 52 | + <tr> |
| 53 | + <td>POST</td> |
| 54 | + <td>/api/v1/authentication/user/login</td> |
| 55 | + <td>User Login</td> |
| 56 | + <td>LoginRequest</td> |
| 57 | + <td></td> |
| 58 | + <td></td> |
| 59 | + <td></td> |
| 60 | + <tr> |
| 61 | + <tr> |
| 62 | + <td>POST</td> |
| 63 | + <td>/api/v1/authentication/user/refresh-token</td> |
| 64 | + <td>User Refresh Token</td> |
| 65 | + <td>TokenRefreshRequest</td> |
| 66 | + <td></td> |
| 67 | + <td></td> |
| 68 | + <td></td> |
| 69 | + <tr> |
| 70 | + <tr> |
| 71 | + <td>POST</td> |
| 72 | + <td>/api/v1/authentication/user/logout</td> |
| 73 | + <td>User Logout</td> |
| 74 | + <td>TokenInvalidateRequest</td> |
| 75 | + <td></td> |
| 76 | + <td></td> |
| 77 | + <td></td> |
| 78 | + <tr> |
| 79 | + <tr> |
| 80 | + <td>POST</td> |
| 81 | + <td>/api/v1/products</td> |
| 82 | + <td>Create Product</td> |
| 83 | + <td>ProductCreateRequest</td> |
| 84 | + <td></td> |
| 85 | + <td></td> |
| 86 | + <td></td> |
| 87 | + <tr> |
| 88 | + <tr> |
| 89 | + <td>GET</td> |
| 90 | + <td>/api/v1/products/{productId}</td> |
| 91 | + <td>Get Product By Id</td> |
| 92 | + <td></td> |
| 93 | + <td></td> |
| 94 | + <td>ProductId</td> |
| 95 | + <td></td> |
| 96 | + <tr> |
| 97 | + <tr> |
| 98 | + <td>GET</td> |
| 99 | + <td>/api/v1/products</td> |
| 100 | + <td>Get Products</td> |
| 101 | + <td>ProductPagingRequest</td> |
| 102 | + <td></td> |
| 103 | + <td></td> |
| 104 | + <td></td> |
| 105 | + <tr> |
| 106 | + <tr> |
| 107 | + <td>PUT</td> |
| 108 | + <td>/api/v1/products/{productId}</td> |
| 109 | + <td>Update Product By Id</td> |
| 110 | + <td>ProductUpdateRequest</td> |
| 111 | + <td></td> |
| 112 | + <td>ProductId</td> |
| 113 | + <td></td> |
| 114 | + <tr> |
| 115 | + <tr> |
| 116 | + <td>DELETE</td> |
| 117 | + <td>/api/v1/products/{productId}</td> |
| 118 | + <td>Delete Product By Id</td> |
| 119 | + <td></td> |
| 120 | + <td></td> |
| 121 | + <td>ProductId</td> |
| 122 | + <td></td> |
| 123 | + <tr> |
| 124 | +</table> |
| 125 | + |
| 126 | + |
| 127 | +### Technologies |
| 128 | + |
| 129 | +--- |
| 130 | +- Java 21 |
| 131 | +- Spring Boot 3.0 |
| 132 | +- Restful API |
| 133 | +- Lombok |
| 134 | +- Maven |
| 135 | +- Junit5 |
| 136 | +- Mockito |
| 137 | +- TestContainer |
| 138 | +- Integration Tests |
| 139 | +- Docker |
| 140 | +- Docker Compose |
| 141 | +- CI/CD (Github Actions) |
| 142 | +- Postman |
| 143 | + |
| 144 | + |
| 145 | +### Postman |
| 146 | + |
| 147 | +``` |
| 148 | +Import postman collection under postman_collection folder |
| 149 | +``` |
| 150 | + |
| 151 | + |
| 152 | +### Prerequisites |
| 153 | + |
| 154 | +#### Define Variable in .env file |
| 155 | + |
| 156 | +``` |
| 157 | +DATABASE_USERNAME={DATABASE_USERNAME} |
| 158 | +DATABASE_PASSWORD={DATABASE_PASSWORD} |
| 159 | +``` |
| 160 | + |
| 161 | +--- |
| 162 | +- Maven or Docker |
| 163 | +--- |
| 164 | + |
| 165 | + |
| 166 | +### Docker Run |
| 167 | +The application can be built and run by the `Docker` engine. The `Dockerfile` has multistage build, so you do not need to build and run separately. |
| 168 | + |
| 169 | +Please follow directions shown below in order to build and run the application with Docker Compose file; |
| 170 | + |
| 171 | +```sh |
| 172 | +$ cd rolepermissionexample |
| 173 | +$ docker-compose up -d |
| 174 | +``` |
| 175 | + |
| 176 | +If you change anything in the project and run it on Docker, you can also use this command shown below |
| 177 | + |
| 178 | +```sh |
| 179 | +$ cd rolepermissionexample |
| 180 | +$ docker-compose up --build |
| 181 | +``` |
| 182 | + |
| 183 | +--- |
| 184 | +### Maven Run |
| 185 | +To build and run the application with `Maven`, please follow the directions shown below; |
| 186 | + |
| 187 | +```sh |
| 188 | +$ cd rolepermissionexample |
| 189 | +$ mvn clean install |
| 190 | +$ mvn spring-boot:run |
| 191 | +``` |
| 192 | + |
| 193 | +### Screenshots |
| 194 | + |
| 195 | +<details> |
| 196 | +<summary>Click here to show the screenshots of project</summary> |
| 197 | + <p> Figure 1 </p> |
| 198 | + <img src ="screenshots/1.PNG"> |
| 199 | + <p> Figure 2 </p> |
| 200 | + <img src ="screenshots/2.PNG"> |
| 201 | + <p> Figure 3 </p> |
| 202 | + <img src ="screenshots/3.PNG"> |
| 203 | + <p> Figure 4 </p> |
| 204 | + <img src ="screenshots/4.PNG"> |
| 205 | + <p> Figure 5 </p> |
| 206 | + <img src ="screenshots/5.PNG"> |
| 207 | + <p> Figure 6 </p> |
| 208 | + <img src ="screenshots/6.PNG"> |
| 209 | + <p> Figure 7 </p> |
| 210 | + <img src ="screenshots/7.PNG"> |
| 211 | +</details> |
| 212 | + |
| 213 | +### Contributors |
| 214 | + |
| 215 | +- [Sercan Noyan Germiyanoğlu](https://github.com/Rapter1990) |
0 commit comments