├── .gitignore ├── build.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── keycloak └── springboot-be.json ├── settings.gradle └── src ├── main ├── java │ └── dive │ │ └── dev │ │ ├── SpringbootKeycloakApplication.java │ │ ├── controller │ │ ├── OrderController.java │ │ └── RestaurantController.java │ │ ├── entity │ │ ├── Menu.java │ │ ├── MenuItem.java │ │ ├── Order.java │ │ ├── OrderItem.java │ │ └── Restaurant.java │ │ ├── repository │ │ ├── MenuItemRepository.java │ │ ├── MenuRepository.java │ │ ├── OrderItemRepository.java │ │ ├── OrderRepository.java │ │ └── RestaurantRepository.java │ │ └── security │ │ ├── JwtAuthConverter.java │ │ └── SecurityConfig.java └── resources │ ├── application.properties │ └── static │ ├── Slides │ ├── Authentication.pptx │ ├── Spring Boot 3 Authentication.pptx │ ├── Spring Boot 3 Authorization.pptx │ └── Spring Boot Use Case Diagram.pptx │ └── project_db.sql └── test └── java └── dive └── dev └── SpringbootKeycloakApplicationTests.java /.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | .gradle 3 | build/ 4 | !gradle/wrapper/gradle-wrapper.jar 5 | !**/src/main/**/build/ 6 | !**/src/test/**/build/ 7 | 8 | ### STS ### 9 | .apt_generated 10 | .classpath 11 | .factorypath 12 | .project 13 | .settings 14 | .springBeans 15 | .sts4-cache 16 | bin/ 17 | !**/src/main/**/bin/ 18 | !**/src/test/**/bin/ 19 | 20 | ### IntelliJ IDEA ### 21 | .idea 22 | *.iws 23 | *.iml 24 | *.ipr 25 | out/ 26 | !**/src/main/**/out/ 27 | !**/src/test/**/out/ 28 | 29 | ### NetBeans ### 30 | /nbproject/private/ 31 | /nbbuild/ 32 | /dist/ 33 | /nbdist/ 34 | /.nb-gradle/ 35 | 36 | ### VS Code ### 37 | .vscode/ 38 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'java' 3 | id 'org.springframework.boot' version '3.1.2' 4 | id 'io.spring.dependency-management' version '1.1.2' 5 | } 6 | 7 | group = 'dive.dev' 8 | version = '0.0.1-SNAPSHOT' 9 | 10 | java { 11 | sourceCompatibility = '17' 12 | } 13 | 14 | repositories { 15 | mavenCentral() 16 | } 17 | 18 | dependencies { 19 | implementation 'org.springframework.boot:spring-boot-starter-data-jpa' 20 | implementation 'org.springframework.boot:spring-boot-starter-oauth2-resource-server' 21 | implementation 'org.springframework.boot:spring-boot-starter-web' 22 | implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.1.0' 23 | runtimeOnly 'org.mariadb.jdbc:mariadb-java-client' 24 | testImplementation 'org.springframework.boot:spring-boot-starter-test' 25 | } 26 | 27 | tasks.named('test') { 28 | useJUnitPlatform() 29 | } 30 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dive-into-dev/springboot-keycloak/4e1254becfe0945b52be7e69143d0d34f3929b65/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-bin.zip 4 | networkTimeout=10000 5 | validateDistributionUrl=true 6 | zipStoreBase=GRADLE_USER_HOME 7 | zipStorePath=wrapper/dists 8 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Copyright © 2015-2021 the original authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | # 21 | # Gradle start up script for POSIX generated by Gradle. 22 | # 23 | # Important for running: 24 | # 25 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is 26 | # noncompliant, but you have some other compliant shell such as ksh or 27 | # bash, then to run this script, type that shell name before the whole 28 | # command line, like: 29 | # 30 | # ksh Gradle 31 | # 32 | # Busybox and similar reduced shells will NOT work, because this script 33 | # requires all of these POSIX shell features: 34 | # * functions; 35 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}», 36 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»; 37 | # * compound commands having a testable exit status, especially «case»; 38 | # * various built-in commands including «command», «set», and «ulimit». 39 | # 40 | # Important for patching: 41 | # 42 | # (2) This script targets any POSIX shell, so it avoids extensions provided 43 | # by Bash, Ksh, etc; in particular arrays are avoided. 44 | # 45 | # The "traditional" practice of packing multiple parameters into a 46 | # space-separated string is a well documented source of bugs and security 47 | # problems, so this is (mostly) avoided, by progressively accumulating 48 | # options in "$@", and eventually passing that to Java. 49 | # 50 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, 51 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; 52 | # see the in-line comments for details. 53 | # 54 | # There are tweaks for specific operating systems such as AIX, CygWin, 55 | # Darwin, MinGW, and NonStop. 56 | # 57 | # (3) This script is generated from the Groovy template 58 | # https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt 59 | # within the Gradle project. 60 | # 61 | # You can find Gradle at https://github.com/gradle/gradle/. 62 | # 63 | ############################################################################## 64 | 65 | # Attempt to set APP_HOME 66 | 67 | # Resolve links: $0 may be a link 68 | app_path=$0 69 | 70 | # Need this for daisy-chained symlinks. 71 | while 72 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path 73 | [ -h "$app_path" ] 74 | do 75 | ls=$( ls -ld "$app_path" ) 76 | link=${ls#*' -> '} 77 | case $link in #( 78 | /*) app_path=$link ;; #( 79 | *) app_path=$APP_HOME$link ;; 80 | esac 81 | done 82 | 83 | # This is normally unused 84 | # shellcheck disable=SC2034 85 | APP_BASE_NAME=${0##*/} 86 | APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit 87 | 88 | # Use the maximum available, or set MAX_FD != -1 to use that value. 89 | MAX_FD=maximum 90 | 91 | warn () { 92 | echo "$*" 93 | } >&2 94 | 95 | die () { 96 | echo 97 | echo "$*" 98 | echo 99 | exit 1 100 | } >&2 101 | 102 | # OS specific support (must be 'true' or 'false'). 103 | cygwin=false 104 | msys=false 105 | darwin=false 106 | nonstop=false 107 | case "$( uname )" in #( 108 | CYGWIN* ) cygwin=true ;; #( 109 | Darwin* ) darwin=true ;; #( 110 | MSYS* | MINGW* ) msys=true ;; #( 111 | NONSTOP* ) nonstop=true ;; 112 | esac 113 | 114 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 115 | 116 | 117 | # Determine the Java command to use to start the JVM. 118 | if [ -n "$JAVA_HOME" ] ; then 119 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 120 | # IBM's JDK on AIX uses strange locations for the executables 121 | JAVACMD=$JAVA_HOME/jre/sh/java 122 | else 123 | JAVACMD=$JAVA_HOME/bin/java 124 | fi 125 | if [ ! -x "$JAVACMD" ] ; then 126 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 127 | 128 | Please set the JAVA_HOME variable in your environment to match the 129 | location of your Java installation." 130 | fi 131 | else 132 | JAVACMD=java 133 | if ! command -v java >/dev/null 2>&1 134 | then 135 | die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 136 | 137 | Please set the JAVA_HOME variable in your environment to match the 138 | location of your Java installation." 139 | fi 140 | fi 141 | 142 | # Increase the maximum file descriptors if we can. 143 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then 144 | case $MAX_FD in #( 145 | max*) 146 | # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. 147 | # shellcheck disable=SC3045 148 | MAX_FD=$( ulimit -H -n ) || 149 | warn "Could not query maximum file descriptor limit" 150 | esac 151 | case $MAX_FD in #( 152 | '' | soft) :;; #( 153 | *) 154 | # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. 155 | # shellcheck disable=SC3045 156 | ulimit -n "$MAX_FD" || 157 | warn "Could not set maximum file descriptor limit to $MAX_FD" 158 | esac 159 | fi 160 | 161 | # Collect all arguments for the java command, stacking in reverse order: 162 | # * args from the command line 163 | # * the main class name 164 | # * -classpath 165 | # * -D...appname settings 166 | # * --module-path (only if needed) 167 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. 168 | 169 | # For Cygwin or MSYS, switch paths to Windows format before running java 170 | if "$cygwin" || "$msys" ; then 171 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) 172 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) 173 | 174 | JAVACMD=$( cygpath --unix "$JAVACMD" ) 175 | 176 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 177 | for arg do 178 | if 179 | case $arg in #( 180 | -*) false ;; # don't mess with options #( 181 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath 182 | [ -e "$t" ] ;; #( 183 | *) false ;; 184 | esac 185 | then 186 | arg=$( cygpath --path --ignore --mixed "$arg" ) 187 | fi 188 | # Roll the args list around exactly as many times as the number of 189 | # args, so each arg winds up back in the position where it started, but 190 | # possibly modified. 191 | # 192 | # NB: a `for` loop captures its iteration list before it begins, so 193 | # changing the positional parameters here affects neither the number of 194 | # iterations, nor the values presented in `arg`. 195 | shift # remove old arg 196 | set -- "$@" "$arg" # push replacement arg 197 | done 198 | fi 199 | 200 | 201 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 202 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 203 | 204 | # Collect all arguments for the java command; 205 | # * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of 206 | # shell script including quotes and variable substitutions, so put them in 207 | # double quotes to make sure that they get re-expanded; and 208 | # * put everything else in single quotes, so that it's not re-expanded. 209 | 210 | set -- \ 211 | "-Dorg.gradle.appname=$APP_BASE_NAME" \ 212 | -classpath "$CLASSPATH" \ 213 | org.gradle.wrapper.GradleWrapperMain \ 214 | "$@" 215 | 216 | # Stop when "xargs" is not available. 217 | if ! command -v xargs >/dev/null 2>&1 218 | then 219 | die "xargs is not available" 220 | fi 221 | 222 | # Use "xargs" to parse quoted args. 223 | # 224 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed. 225 | # 226 | # In Bash we could simply go: 227 | # 228 | # readarray ARGS < <( xargs -n1 <<<"$var" ) && 229 | # set -- "${ARGS[@]}" "$@" 230 | # 231 | # but POSIX shell has neither arrays nor command substitution, so instead we 232 | # post-process each arg (as a line of input to sed) to backslash-escape any 233 | # character that might be a shell metacharacter, then use eval to reverse 234 | # that process (while maintaining the separation between arguments), and wrap 235 | # the whole thing up as a single "set" statement. 236 | # 237 | # This will of course break if any of these variables contains a newline or 238 | # an unmatched quote. 239 | # 240 | 241 | eval "set -- $( 242 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | 243 | xargs -n1 | 244 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | 245 | tr '\n' ' ' 246 | )" '"$@"' 247 | 248 | exec "$JAVACMD" "$@" 249 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%"=="" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%"=="" set DIRNAME=. 29 | @rem This is normally unused 30 | set APP_BASE_NAME=%~n0 31 | set APP_HOME=%DIRNAME% 32 | 33 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 34 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 35 | 36 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 37 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 38 | 39 | @rem Find java.exe 40 | if defined JAVA_HOME goto findJavaFromJavaHome 41 | 42 | set JAVA_EXE=java.exe 43 | %JAVA_EXE% -version >NUL 2>&1 44 | if %ERRORLEVEL% equ 0 goto execute 45 | 46 | echo. 47 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 48 | echo. 49 | echo Please set the JAVA_HOME variable in your environment to match the 50 | echo location of your Java installation. 51 | 52 | goto fail 53 | 54 | :findJavaFromJavaHome 55 | set JAVA_HOME=%JAVA_HOME:"=% 56 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 57 | 58 | if exist "%JAVA_EXE%" goto execute 59 | 60 | echo. 61 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 62 | echo. 63 | echo Please set the JAVA_HOME variable in your environment to match the 64 | echo location of your Java installation. 65 | 66 | goto fail 67 | 68 | :execute 69 | @rem Setup the command line 70 | 71 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 72 | 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if %ERRORLEVEL% equ 0 goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | set EXIT_CODE=%ERRORLEVEL% 85 | if %EXIT_CODE% equ 0 set EXIT_CODE=1 86 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% 87 | exit /b %EXIT_CODE% 88 | 89 | :mainEnd 90 | if "%OS%"=="Windows_NT" endlocal 91 | 92 | :omega 93 | -------------------------------------------------------------------------------- /keycloak/springboot-be.json: -------------------------------------------------------------------------------- 1 | { 2 | "clientId": "springboot-be", 3 | "name": "Springboot Application", 4 | "description": "", 5 | "rootUrl": "", 6 | "adminUrl": "", 7 | "baseUrl": "", 8 | "surrogateAuthRequired": false, 9 | "enabled": true, 10 | "alwaysDisplayInConsole": false, 11 | "clientAuthenticatorType": "client-secret", 12 | "secret": "zfopel8nyMgZ4kpUADHxHOn6WI67Zurx", 13 | "redirectUris": [ 14 | "http://localhost:8080/*" 15 | ], 16 | "webOrigins": [ 17 | "*" 18 | ], 19 | "notBefore": 0, 20 | "bearerOnly": false, 21 | "consentRequired": false, 22 | "standardFlowEnabled": true, 23 | "implicitFlowEnabled": false, 24 | "directAccessGrantsEnabled": true, 25 | "serviceAccountsEnabled": false, 26 | "publicClient": false, 27 | "frontchannelLogout": true, 28 | "protocol": "openid-connect", 29 | "attributes": { 30 | "oidc.ciba.grant.enabled": "false", 31 | "oauth2.device.authorization.grant.enabled": "false", 32 | "client.secret.creation.time": "1692194798", 33 | "backchannel.logout.session.required": "true", 34 | "backchannel.logout.revoke.offline.tokens": "false" 35 | }, 36 | "authenticationFlowBindingOverrides": {}, 37 | "fullScopeAllowed": true, 38 | "nodeReRegistrationTimeout": -1, 39 | "defaultClientScopes": [ 40 | "web-origins", 41 | "acr", 42 | "profile", 43 | "roles", 44 | "email" 45 | ], 46 | "optionalClientScopes": [ 47 | "address", 48 | "phone", 49 | "offline_access", 50 | "microprofile-jwt" 51 | ], 52 | "access": { 53 | "view": true, 54 | "configure": true, 55 | "manage": true 56 | } 57 | } -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'springboot-keycloak' 2 | -------------------------------------------------------------------------------- /src/main/java/dive/dev/SpringbootKeycloakApplication.java: -------------------------------------------------------------------------------- 1 | package dive.dev; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | import io.swagger.v3.oas.annotations.enums.SecuritySchemeIn; 7 | import io.swagger.v3.oas.annotations.enums.SecuritySchemeType; 8 | import io.swagger.v3.oas.annotations.security.SecurityScheme; 9 | 10 | @SpringBootApplication 11 | @SecurityScheme( 12 | name = "Keycloak" 13 | , openIdConnectUrl = "http://127.0.0.1:8081/realms/dive-dev/.well-known/openid-configuration" 14 | , scheme = "bearer" 15 | , type = SecuritySchemeType.OPENIDCONNECT 16 | , in = SecuritySchemeIn.HEADER 17 | ) 18 | public class SpringbootKeycloakApplication { 19 | 20 | public static void main(String[] args) { 21 | SpringApplication.run(SpringbootKeycloakApplication.class, args); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/dive/dev/controller/OrderController.java: -------------------------------------------------------------------------------- 1 | package dive.dev.controller; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.web.bind.annotation.GetMapping; 7 | import org.springframework.web.bind.annotation.PathVariable; 8 | import org.springframework.web.bind.annotation.PostMapping; 9 | import org.springframework.web.bind.annotation.RequestMapping; 10 | import org.springframework.web.bind.annotation.RestController; 11 | 12 | import dive.dev.entity.Order; 13 | import dive.dev.entity.OrderItem; 14 | import dive.dev.repository.OrderItemRepository; 15 | import dive.dev.repository.OrderRepository; 16 | 17 | @RestController 18 | @RequestMapping("/order") 19 | public class OrderController { 20 | 21 | @Autowired 22 | OrderRepository orderRepository; 23 | 24 | @Autowired 25 | OrderItemRepository orderItemRepository; 26 | 27 | @GetMapping 28 | @RequestMapping("/{restaurantId}/list") 29 | // manager can access (suresh) 30 | public List getOrders(@PathVariable Long restaurantId) { 31 | return orderRepository.findByRestaurantId(restaurantId); 32 | } 33 | 34 | @GetMapping 35 | @RequestMapping("/{orderId}") 36 | // manager can access (suresh) 37 | public Order getOrderDetails(@PathVariable Long orderId) { 38 | Order order = orderRepository.findById(orderId).get(); 39 | order.setOrderItems(orderItemRepository.findByOrderId(order.getId())); 40 | return order; 41 | } 42 | 43 | @PostMapping 44 | // authenticated users can access 45 | public Order createOrder(Order order) { 46 | orderRepository.save(order); 47 | List orderItems = order.getOrderItems(); 48 | orderItems.forEach(orderItem -> { 49 | orderItem.setOrderId(order.id); 50 | orderItemRepository.save(orderItem); 51 | }); 52 | return order; 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/dive/dev/controller/RestaurantController.java: -------------------------------------------------------------------------------- 1 | package dive.dev.controller; 2 | 3 | import java.math.BigDecimal; 4 | import java.util.List; 5 | import java.util.Optional; 6 | 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.security.access.prepost.PreAuthorize; 9 | import org.springframework.web.bind.annotation.GetMapping; 10 | import org.springframework.web.bind.annotation.PathVariable; 11 | import org.springframework.web.bind.annotation.PostMapping; 12 | import org.springframework.web.bind.annotation.PutMapping; 13 | import org.springframework.web.bind.annotation.RequestMapping; 14 | import org.springframework.web.bind.annotation.RestController; 15 | 16 | import dive.dev.entity.Menu; 17 | import dive.dev.entity.MenuItem; 18 | import dive.dev.entity.Restaurant; 19 | import dive.dev.repository.MenuItemRepository; 20 | import dive.dev.repository.MenuRepository; 21 | import dive.dev.repository.RestaurantRepository; 22 | import io.swagger.v3.oas.annotations.security.SecurityRequirement; 23 | 24 | @RestController 25 | @RequestMapping("/restaurant") 26 | @SecurityRequirement(name = "Keycloak") 27 | public class RestaurantController { 28 | 29 | @Autowired 30 | RestaurantRepository restaurantRepository; 31 | 32 | @Autowired 33 | MenuRepository menuRepository; 34 | 35 | @Autowired 36 | MenuItemRepository menuItemRepository; 37 | 38 | @GetMapping 39 | @RequestMapping("/public/list") 40 | //Public API 41 | public List getRestaurants() { 42 | return restaurantRepository.findAll(); 43 | } 44 | 45 | @GetMapping 46 | @RequestMapping("/public/menu/{restaurantId}") 47 | //Public API 48 | public Menu getMenu(@PathVariable Long restaurantId) { 49 | Menu menu = menuRepository.findByRestaurantId(restaurantId); 50 | menu.setMenuItems(menuItemRepository.findAllByMenuId(menu.id)); 51 | return menu; 52 | } 53 | 54 | @PostMapping 55 | // admin can access (admin) 56 | @PreAuthorize("hasRole('admin')") 57 | public Restaurant createRestaurant(Restaurant restaurant) { 58 | return restaurantRepository.save(restaurant); 59 | } 60 | 61 | @PostMapping 62 | @RequestMapping("/menu") 63 | // manager can access (suresh) 64 | @PreAuthorize("hasRole('manager')") 65 | public Menu createMenu(Menu menu) { 66 | menuRepository.save(menu); 67 | menu.getMenuItems().forEach(menuItem -> { 68 | menuItem.setMenuId(menu.id); 69 | menuItemRepository.save(menuItem); 70 | }); 71 | return menu; 72 | } 73 | 74 | @PutMapping 75 | @RequestMapping("/menu/item/{itemId}/{price}") 76 | // owner can access (amar) 77 | @PreAuthorize("hasRole('owner')") 78 | public MenuItem updateMenuItemPrice(@PathVariable Long itemId 79 | , @PathVariable BigDecimal price) { 80 | Optional menuItem = menuItemRepository.findById(itemId); 81 | menuItem.get().setPrice(price); 82 | menuItemRepository.save(menuItem.get()); 83 | return menuItem.get(); 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /src/main/java/dive/dev/entity/Menu.java: -------------------------------------------------------------------------------- 1 | package dive.dev.entity; 2 | 3 | import jakarta.persistence.Entity; 4 | import jakarta.persistence.GeneratedValue; 5 | import jakarta.persistence.Id; 6 | import jakarta.persistence.Transient; 7 | 8 | import java.util.List; 9 | 10 | @Entity 11 | public class Menu { 12 | 13 | @Id 14 | @GeneratedValue 15 | public Long id; 16 | 17 | private Long restaurantId; 18 | 19 | private Boolean active; 20 | 21 | @Transient 22 | private List menuItems; 23 | 24 | public Long getId() { 25 | return id; 26 | } 27 | 28 | public void setId(Long id) { 29 | this.id = id; 30 | } 31 | 32 | public Long getRestaurantId() { 33 | return restaurantId; 34 | } 35 | 36 | public void setRestaurantId(Long restaurantId) { 37 | this.restaurantId = restaurantId; 38 | } 39 | 40 | public Boolean getActive() { 41 | return active; 42 | } 43 | 44 | public void setActive(Boolean active) { 45 | this.active = active; 46 | } 47 | 48 | public List getMenuItems() { 49 | return menuItems; 50 | } 51 | 52 | public void setMenuItems(List menuItems) { 53 | this.menuItems = menuItems; 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/dive/dev/entity/MenuItem.java: -------------------------------------------------------------------------------- 1 | package dive.dev.entity; 2 | 3 | import jakarta.persistence.Column; 4 | import jakarta.persistence.Entity; 5 | import jakarta.persistence.GeneratedValue; 6 | import jakarta.persistence.Id; 7 | 8 | import java.math.BigDecimal; 9 | 10 | @Entity 11 | public class MenuItem { 12 | 13 | @Id 14 | @GeneratedValue 15 | public Long id; 16 | 17 | private Long menuId; 18 | 19 | private String name; 20 | 21 | private String description; 22 | 23 | @Column(name = "type_name") 24 | private String type; 25 | 26 | @Column(name = "group_name") 27 | private String group; 28 | 29 | private BigDecimal price; 30 | 31 | public Long getId() { 32 | return id; 33 | } 34 | 35 | public void setId(Long id) { 36 | this.id = id; 37 | } 38 | 39 | public Long getMenuId() { 40 | return menuId; 41 | } 42 | 43 | public void setMenuId(Long menuId) { 44 | this.menuId = menuId; 45 | } 46 | 47 | public String getName() { 48 | return name; 49 | } 50 | 51 | public void setName(String name) { 52 | this.name = name; 53 | } 54 | 55 | public String getDescription() { 56 | return description; 57 | } 58 | 59 | public void setDescription(String description) { 60 | this.description = description; 61 | } 62 | 63 | public String getType() { 64 | return type; 65 | } 66 | 67 | public void setType(String type) { 68 | this.type = type; 69 | } 70 | 71 | public String getGroup() { 72 | return group; 73 | } 74 | 75 | public void setGroup(String group) { 76 | this.group = group; 77 | } 78 | 79 | public BigDecimal getPrice() { 80 | return price; 81 | } 82 | 83 | public void setPrice(BigDecimal price) { 84 | this.price = price; 85 | } 86 | 87 | } 88 | -------------------------------------------------------------------------------- /src/main/java/dive/dev/entity/Order.java: -------------------------------------------------------------------------------- 1 | package dive.dev.entity; 2 | 3 | import java.math.BigDecimal; 4 | import java.util.List; 5 | 6 | import jakarta.persistence.Entity; 7 | import jakarta.persistence.GeneratedValue; 8 | import jakarta.persistence.Id; 9 | import jakarta.persistence.Table; 10 | import jakarta.persistence.Transient; 11 | 12 | @Entity 13 | @Table(name = "`order`") 14 | public class Order{ 15 | 16 | @Id 17 | @GeneratedValue 18 | public Long id; 19 | 20 | private Long restaurantId; 21 | 22 | private BigDecimal total; 23 | 24 | @Transient 25 | private List orderItems; 26 | 27 | public Long getId() { 28 | return id; 29 | } 30 | 31 | public void setId(Long id) { 32 | this.id = id; 33 | } 34 | 35 | public Long getRestaurantId() { 36 | return restaurantId; 37 | } 38 | 39 | public void setRestaurantId(Long restaurantId) { 40 | this.restaurantId = restaurantId; 41 | } 42 | 43 | public BigDecimal getTotal() { 44 | return total; 45 | } 46 | 47 | public void setTotal(BigDecimal total) { 48 | this.total = total; 49 | } 50 | 51 | public List getOrderItems() { 52 | return orderItems; 53 | } 54 | 55 | public void setOrderItems(List orderItems) { 56 | this.orderItems = orderItems; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/dive/dev/entity/OrderItem.java: -------------------------------------------------------------------------------- 1 | package dive.dev.entity; 2 | 3 | import java.math.BigDecimal; 4 | 5 | import jakarta.persistence.Entity; 6 | import jakarta.persistence.GeneratedValue; 7 | import jakarta.persistence.Id; 8 | 9 | @Entity 10 | public class OrderItem{ 11 | 12 | @Id 13 | @GeneratedValue 14 | public Long id; 15 | 16 | private Long orderId; 17 | 18 | private Long menuItemId; 19 | 20 | private BigDecimal price; 21 | 22 | public Long getId() { 23 | return id; 24 | } 25 | 26 | public void setId(Long id) { 27 | this.id = id; 28 | } 29 | 30 | public Long getOrderId() { 31 | return orderId; 32 | } 33 | 34 | public void setOrderId(Long orderId) { 35 | this.orderId = orderId; 36 | } 37 | 38 | public Long getMenuItemId() { 39 | return menuItemId; 40 | } 41 | 42 | public void setMenuItemId(Long menuItemId) { 43 | this.menuItemId = menuItemId; 44 | } 45 | 46 | public BigDecimal getPrice() { 47 | return price; 48 | } 49 | 50 | public void setPrice(BigDecimal price) { 51 | this.price = price; 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/dive/dev/entity/Restaurant.java: -------------------------------------------------------------------------------- 1 | package dive.dev.entity; 2 | 3 | import jakarta.persistence.Column; 4 | import jakarta.persistence.Entity; 5 | import jakarta.persistence.GeneratedValue; 6 | import jakarta.persistence.Id; 7 | 8 | @Entity 9 | public class Restaurant { 10 | 11 | @Id 12 | @GeneratedValue 13 | public Long id; 14 | 15 | private String name; 16 | 17 | private String location; 18 | 19 | @Column(name = "type_name") 20 | private String type; 21 | 22 | public Long getId() { 23 | return id; 24 | } 25 | 26 | public void setId(Long id) { 27 | this.id = id; 28 | } 29 | 30 | public String getName() { 31 | return name; 32 | } 33 | 34 | public void setName(String name) { 35 | this.name = name; 36 | } 37 | 38 | public String getLocation() { 39 | return location; 40 | } 41 | 42 | public void setLocation(String location) { 43 | this.location = location; 44 | } 45 | 46 | public String getType() { 47 | return type; 48 | } 49 | 50 | public void setType(String type) { 51 | this.type = type; 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/dive/dev/repository/MenuItemRepository.java: -------------------------------------------------------------------------------- 1 | package dive.dev.repository; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.data.jpa.repository.JpaRepository; 6 | 7 | import dive.dev.entity.MenuItem; 8 | 9 | public interface MenuItemRepository extends JpaRepository{ 10 | 11 | List findAllByMenuId(Long id); 12 | 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/dive/dev/repository/MenuRepository.java: -------------------------------------------------------------------------------- 1 | package dive.dev.repository; 2 | 3 | import org.springframework.data.jpa.repository.JpaRepository; 4 | 5 | import dive.dev.entity.Menu; 6 | 7 | public interface MenuRepository extends JpaRepository{ 8 | 9 | Menu findByRestaurantId(Long restaurantId); 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/dive/dev/repository/OrderItemRepository.java: -------------------------------------------------------------------------------- 1 | package dive.dev.repository; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.data.jpa.repository.JpaRepository; 6 | 7 | import dive.dev.entity.OrderItem; 8 | 9 | public interface OrderItemRepository extends JpaRepository{ 10 | 11 | List findByOrderId(Long id); 12 | 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/dive/dev/repository/OrderRepository.java: -------------------------------------------------------------------------------- 1 | package dive.dev.repository; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.data.jpa.repository.JpaRepository; 6 | 7 | import dive.dev.entity.Order; 8 | 9 | public interface OrderRepository extends JpaRepository{ 10 | 11 | List findByRestaurantId(Long restaurantId); 12 | 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/dive/dev/repository/RestaurantRepository.java: -------------------------------------------------------------------------------- 1 | package dive.dev.repository; 2 | 3 | import org.springframework.data.jpa.repository.JpaRepository; 4 | import org.springframework.stereotype.Repository; 5 | 6 | import dive.dev.entity.Restaurant; 7 | 8 | @Repository 9 | public interface RestaurantRepository extends JpaRepository{ 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/dive/dev/security/JwtAuthConverter.java: -------------------------------------------------------------------------------- 1 | package dive.dev.security; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Collection; 5 | import java.util.List; 6 | import java.util.Map; 7 | 8 | import org.springframework.core.convert.converter.Converter; 9 | import org.springframework.security.authentication.AbstractAuthenticationToken; 10 | import org.springframework.security.core.GrantedAuthority; 11 | import org.springframework.security.core.authority.SimpleGrantedAuthority; 12 | import org.springframework.security.oauth2.jwt.Jwt; 13 | import org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationToken; 14 | import org.springframework.stereotype.Component; 15 | 16 | import com.fasterxml.jackson.core.type.TypeReference; 17 | import com.fasterxml.jackson.databind.ObjectMapper; 18 | 19 | @Component 20 | public class JwtAuthConverter implements Converter { 21 | 22 | @Override 23 | public AbstractAuthenticationToken convert(Jwt jwt) { 24 | Collection roles = extractAuthorities(jwt); 25 | return new JwtAuthenticationToken(jwt, roles); 26 | } 27 | 28 | private Collection extractAuthorities(Jwt jwt) { 29 | if(jwt.getClaim("realm_access") != null) { 30 | Map realmAccess = jwt.getClaim("realm_access"); 31 | ObjectMapper mapper = new ObjectMapper(); 32 | List keycloakRoles = mapper.convertValue(realmAccess.get("roles"), new TypeReference>(){}); 33 | List roles = new ArrayList<>(); 34 | 35 | for (String keycloakRole : keycloakRoles) { 36 | roles.add(new SimpleGrantedAuthority(keycloakRole)); 37 | } 38 | 39 | return roles; 40 | } 41 | return new ArrayList<>(); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/dive/dev/security/SecurityConfig.java: -------------------------------------------------------------------------------- 1 | package dive.dev.security; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.http.HttpMethod; 7 | import org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler; 8 | import org.springframework.security.config.Customizer; 9 | import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity; 10 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; 11 | import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; 12 | import org.springframework.security.config.http.SessionCreationPolicy; 13 | import org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationConverter; 14 | import org.springframework.security.oauth2.server.resource.authentication.JwtGrantedAuthoritiesConverter; 15 | import org.springframework.security.web.SecurityFilterChain; 16 | 17 | @Configuration 18 | @EnableWebSecurity 19 | @EnableMethodSecurity 20 | public class SecurityConfig { 21 | 22 | //@Autowired 23 | //JwtAuthConverter jwtAuthConverter; 24 | 25 | @Bean 26 | public SecurityFilterChain securityFilterChain(HttpSecurity http) 27 | throws Exception { 28 | http.csrf(t -> t.disable()); 29 | http.authorizeHttpRequests(authorize -> { 30 | authorize 31 | .requestMatchers(HttpMethod.GET, "/restaurant/public/list").permitAll() 32 | .requestMatchers(HttpMethod.GET, "/restaurant/public/menu/*").permitAll() 33 | .requestMatchers("/swagger-ui/**", "/v3/api-docs/**").permitAll() 34 | .anyRequest().authenticated(); 35 | }); 36 | http.oauth2ResourceServer(t-> { 37 | t.jwt(Customizer.withDefaults()); 38 | //t.opaqueToken(Customizer.withDefaults()); 39 | }); 40 | http.sessionManagement( 41 | t -> t.sessionCreationPolicy(SessionCreationPolicy.STATELESS) 42 | ); 43 | return http.build(); 44 | } 45 | 46 | @Bean 47 | public DefaultMethodSecurityExpressionHandler msecurity() { 48 | DefaultMethodSecurityExpressionHandler defaultMethodSecurityExpressionHandler = 49 | new DefaultMethodSecurityExpressionHandler(); 50 | defaultMethodSecurityExpressionHandler.setDefaultRolePrefix(""); 51 | return defaultMethodSecurityExpressionHandler; 52 | } 53 | 54 | @Bean 55 | public JwtAuthenticationConverter con() { 56 | JwtAuthenticationConverter c =new JwtAuthenticationConverter(); 57 | JwtGrantedAuthoritiesConverter cv = new JwtGrantedAuthoritiesConverter(); 58 | cv.setAuthorityPrefix(""); // Default "SCOPE_" 59 | cv.setAuthoritiesClaimName("roles"); // Default "scope" or "scp" 60 | c.setJwtGrantedAuthoritiesConverter(cv); 61 | return c; 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.datasource.url=jdbc:mariadb://localhost:3306/project_db 2 | spring.datasource.username=root 3 | spring.datasource.password=root 4 | 5 | 6 | spring.security.oauth2.resourceserver.jwt.issuer-uri=http://127.0.0.1:8081/realms/dive-dev 7 | #spring.security.oauth2.resourceserver.opaquetoken.client-id=springboot-be 8 | #spring.security.oauth2.resourceserver.opaquetoken.client-secret=zfopel8nyMgZ4kpUADHxHOn6WI67Zurx 9 | #spring.security.oauth2.resourceserver.opaquetoken.introspection-uri=http://127.0.0.1:8081/realms/dive-dev/protocol/openid-connect/token/introspect 10 | 11 | springdoc.swagger-ui.oauth.client-id=springboot-be 12 | springdoc.swagger-ui.oauth.client-secret=zfopel8nyMgZ4kpUADHxHOn6WI67Zurx 13 | -------------------------------------------------------------------------------- /src/main/resources/static/Slides/Authentication.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dive-into-dev/springboot-keycloak/4e1254becfe0945b52be7e69143d0d34f3929b65/src/main/resources/static/Slides/Authentication.pptx -------------------------------------------------------------------------------- /src/main/resources/static/Slides/Spring Boot 3 Authentication.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dive-into-dev/springboot-keycloak/4e1254becfe0945b52be7e69143d0d34f3929b65/src/main/resources/static/Slides/Spring Boot 3 Authentication.pptx -------------------------------------------------------------------------------- /src/main/resources/static/Slides/Spring Boot 3 Authorization.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dive-into-dev/springboot-keycloak/4e1254becfe0945b52be7e69143d0d34f3929b65/src/main/resources/static/Slides/Spring Boot 3 Authorization.pptx -------------------------------------------------------------------------------- /src/main/resources/static/Slides/Spring Boot Use Case Diagram.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dive-into-dev/springboot-keycloak/4e1254becfe0945b52be7e69143d0d34f3929b65/src/main/resources/static/Slides/Spring Boot Use Case Diagram.pptx -------------------------------------------------------------------------------- /src/main/resources/static/project_db.sql: -------------------------------------------------------------------------------- 1 | -- MySQL dump 10.13 Distrib 5.5.62, for Win64 (AMD64) 2 | -- 3 | -- Host: localhost Database: project_db 4 | -- ------------------------------------------------------ 5 | -- Server version 5.5.5-10.6.10-MariaDB 6 | 7 | /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; 8 | /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; 9 | /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; 10 | /*!40101 SET NAMES utf8 */; 11 | /*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; 12 | /*!40103 SET TIME_ZONE='+00:00' */; 13 | /*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; 14 | /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; 15 | /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; 16 | /*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; 17 | 18 | -- 19 | -- Table structure for table `hibernate_sequence` 20 | -- 21 | 22 | DROP TABLE IF EXISTS `hibernate_sequence`; 23 | /*!40101 SET @saved_cs_client = @@character_set_client */; 24 | /*!40101 SET character_set_client = utf8 */; 25 | CREATE TABLE `hibernate_sequence` ( 26 | `next_not_cached_value` bigint(21) NOT NULL, 27 | `minimum_value` bigint(21) NOT NULL, 28 | `maximum_value` bigint(21) NOT NULL, 29 | `start_value` bigint(21) NOT NULL COMMENT 'start value when sequences is created or value if RESTART is used', 30 | `increment` bigint(21) NOT NULL COMMENT 'increment value', 31 | `cache_size` bigint(21) unsigned NOT NULL, 32 | `cycle_option` tinyint(1) unsigned NOT NULL COMMENT '0 if no cycles are allowed, 1 if the sequence should begin a new cycle when maximum_value is passed', 33 | `cycle_count` bigint(21) NOT NULL COMMENT 'How many cycles have been done' 34 | ) ENGINE=InnoDB SEQUENCE=1; 35 | /*!40101 SET character_set_client = @saved_cs_client */; 36 | 37 | -- 38 | -- Dumping data for table `hibernate_sequence` 39 | -- 40 | 41 | LOCK TABLES `hibernate_sequence` WRITE; 42 | /*!40000 ALTER TABLE `hibernate_sequence` DISABLE KEYS */; 43 | INSERT INTO `hibernate_sequence` VALUES (4001,1,9223372036854775806,1,1,1000,0,0); 44 | /*!40000 ALTER TABLE `hibernate_sequence` ENABLE KEYS */; 45 | UNLOCK TABLES; 46 | 47 | -- 48 | -- Table structure for table `menu` 49 | -- 50 | 51 | DROP TABLE IF EXISTS `menu`; 52 | /*!40101 SET @saved_cs_client = @@character_set_client */; 53 | /*!40101 SET character_set_client = utf8 */; 54 | CREATE TABLE `menu` ( 55 | `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, 56 | `restaurant_id` bigint(20) NOT NULL, 57 | `active` bit(1) DEFAULT NULL, 58 | PRIMARY KEY (`id`), 59 | KEY `menu_FK` (`restaurant_id`) 60 | ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4; 61 | /*!40101 SET character_set_client = @saved_cs_client */; 62 | 63 | -- 64 | -- Dumping data for table `menu` 65 | -- 66 | 67 | LOCK TABLES `menu` WRITE; 68 | /*!40000 ALTER TABLE `menu` DISABLE KEYS */; 69 | INSERT INTO `menu` VALUES (1,1,''),(2,2,''); 70 | /*!40000 ALTER TABLE `menu` ENABLE KEYS */; 71 | UNLOCK TABLES; 72 | 73 | -- 74 | -- Table structure for table `menu_item` 75 | -- 76 | 77 | DROP TABLE IF EXISTS `menu_item`; 78 | /*!40101 SET @saved_cs_client = @@character_set_client */; 79 | /*!40101 SET character_set_client = utf8 */; 80 | CREATE TABLE `menu_item` ( 81 | `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, 82 | `name` varchar(255) DEFAULT NULL, 83 | `description` varchar(100) DEFAULT NULL, 84 | `type_name` varchar(100) DEFAULT NULL, 85 | `group_name` varchar(100) DEFAULT NULL, 86 | `price` decimal(10,2) DEFAULT NULL, 87 | `menu_id` bigint(20) DEFAULT NULL, 88 | PRIMARY KEY (`id`), 89 | KEY `menu_item_FK` (`menu_id`) 90 | ) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8mb4; 91 | /*!40101 SET character_set_client = @saved_cs_client */; 92 | 93 | -- 94 | -- Dumping data for table `menu_item` 95 | -- 96 | 97 | LOCK TABLES `menu_item` WRITE; 98 | /*!40000 ALTER TABLE `menu_item` DISABLE KEYS */; 99 | INSERT INTO `menu_item` VALUES (1,'Amritsari Dal','Green gram and bengal gram with spices','VEG','MAIN_COURSE',222.00,1),(2,'Samosa Masala','Deep fried savory pastry with dressing of chickpeas salad','VEG','STARTER',123.00,1),(3,'Phirni','Creamy dessert of ground rice','VEG','DESSERT',120.00,1),(4,'Nizami Chicken Biryani','Freshly cooked kacchi dum ki biryany','NON_VEG','MAIN_COURSE',319.00,2),(5,'Mutton Seekh Kebab','Minced goat meet mixed with spices and cooked on gridle','NON_VEG','STARTER',365.00,2),(6,'Kurbaani Ka Meetha','Sweet dessert made from dried apricots and sugar enriched with saffron strands and rose water ','VEG','DESSERT',160.00,2); 100 | /*!40000 ALTER TABLE `menu_item` ENABLE KEYS */; 101 | UNLOCK TABLES; 102 | 103 | -- 104 | -- Table structure for table `order` 105 | -- 106 | 107 | DROP TABLE IF EXISTS `order`; 108 | /*!40101 SET @saved_cs_client = @@character_set_client */; 109 | /*!40101 SET character_set_client = utf8 */; 110 | CREATE TABLE `order` ( 111 | `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, 112 | `restaurant_id` bigint(20) NOT NULL, 113 | `total` decimal(10,2) DEFAULT NULL, 114 | PRIMARY KEY (`id`), 115 | KEY `order_FK` (`restaurant_id`) 116 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; 117 | /*!40101 SET character_set_client = @saved_cs_client */; 118 | 119 | -- 120 | -- Dumping data for table `order` 121 | -- 122 | 123 | LOCK TABLES `order` WRITE; 124 | /*!40000 ALTER TABLE `order` DISABLE KEYS */; 125 | /*!40000 ALTER TABLE `order` ENABLE KEYS */; 126 | UNLOCK TABLES; 127 | 128 | -- 129 | -- Table structure for table `order_item` 130 | -- 131 | 132 | DROP TABLE IF EXISTS `order_item`; 133 | /*!40101 SET @saved_cs_client = @@character_set_client */; 134 | /*!40101 SET character_set_client = utf8 */; 135 | CREATE TABLE `order_item` ( 136 | `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, 137 | `order_id` bigint(20) NOT NULL, 138 | `menu_item_id` bigint(20) NOT NULL, 139 | `price` decimal(10,2) DEFAULT NULL, 140 | PRIMARY KEY (`id`), 141 | KEY `order_item_FK` (`menu_item_id`), 142 | KEY `order_item_FK_1` (`order_id`) 143 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; 144 | /*!40101 SET character_set_client = @saved_cs_client */; 145 | 146 | -- 147 | -- Dumping data for table `order_item` 148 | -- 149 | 150 | LOCK TABLES `order_item` WRITE; 151 | /*!40000 ALTER TABLE `order_item` DISABLE KEYS */; 152 | /*!40000 ALTER TABLE `order_item` ENABLE KEYS */; 153 | UNLOCK TABLES; 154 | 155 | -- 156 | -- Table structure for table `restaurant` 157 | -- 158 | 159 | DROP TABLE IF EXISTS `restaurant`; 160 | /*!40101 SET @saved_cs_client = @@character_set_client */; 161 | /*!40101 SET character_set_client = utf8 */; 162 | CREATE TABLE `restaurant` ( 163 | `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, 164 | `name` varchar(250) NOT NULL, 165 | `location` varchar(250) DEFAULT NULL, 166 | `type_name` varchar(100) DEFAULT NULL, 167 | PRIMARY KEY (`id`) 168 | ) ENGINE=InnoDB AUTO_INCREMENT=1033 DEFAULT CHARSET=utf8mb4; 169 | /*!40101 SET character_set_client = @saved_cs_client */; 170 | 171 | -- 172 | -- Dumping data for table `restaurant` 173 | -- 174 | 175 | LOCK TABLES `restaurant` WRITE; 176 | /*!40000 ALTER TABLE `restaurant` DISABLE KEYS */; 177 | INSERT INTO `restaurant` VALUES (1,'Imli','Bangalore','VEG'),(2,'Paradise','Hyderabad','NON_VEG'),(1027,'Kritunga','Hyderabad','NON_VEG'); 178 | /*!40000 ALTER TABLE `restaurant` ENABLE KEYS */; 179 | UNLOCK TABLES; 180 | 181 | -- 182 | -- Dumping routines for database 'project_db' 183 | -- 184 | /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; 185 | 186 | /*!40101 SET SQL_MODE=@OLD_SQL_MODE */; 187 | /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; 188 | /*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; 189 | /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; 190 | /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; 191 | /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; 192 | /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; 193 | 194 | -- Dump completed on 2023-12-21 13:36:54 195 | -------------------------------------------------------------------------------- /src/test/java/dive/dev/SpringbootKeycloakApplicationTests.java: -------------------------------------------------------------------------------- 1 | package dive.dev; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class SpringbootKeycloakApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | --------------------------------------------------------------------------------