diff --git a/pom.xml b/pom.xml index 683d6e6a1c..178e852f5b 100644 --- a/pom.xml +++ b/pom.xml @@ -344,7 +344,6 @@ apache-poi apache-poi-2 apache-rocketmq - apache-shiro apache-spark apache-tapestry apache-thrift @@ -365,11 +364,9 @@ bazel blade bootique - cas cdi checker-plugin - cloud-foundry-uaa code-generation core-groovy-modules @@ -415,9 +412,6 @@ jackson-modules jackson-simple java-blockchain - - - javafx java-jdi java-lite @@ -431,14 +425,12 @@ javaxval jaxb jee-7 - jee-7-security jakarta-ee jersey jgit jgroups jhipster-5 jib - jjwt jmeter jmh java-native @@ -491,7 +483,6 @@ ninja open-liberty - oauth2-framework-impl orika osgi @@ -515,6 +506,7 @@ rxjava-modules atomikos reactive-systems + security-modules slack @@ -561,7 +553,6 @@ parent-java saas - software-security/sql-injection-samples spark-java spf4j @@ -775,7 +766,6 @@ apache-poi apache-poi-2 apache-rocketmq - apache-shiro apache-spark apache-tapestry apache-thrift @@ -796,11 +786,9 @@ bazel blade bootique - cas cdi checker-plugin - cloud-foundry-uaa code-generation core-groovy-modules @@ -846,9 +834,6 @@ jackson-modules jackson-simple java-blockchain - - - javafx java-jdi java-lite @@ -862,14 +847,12 @@ javaxval jaxb jee-7 - jee-7-security jakarta-ee jersey jgit jgroups jhipster-5 jib - jjwt jmeter jmh java-native @@ -924,7 +907,6 @@ ninja open-liberty - oauth2-framework-impl orika osgi @@ -948,6 +930,7 @@ rxjava-modules atomikos reactive-systems + security-modules slack @@ -986,7 +969,6 @@ parent-java saas - software-security/sql-injection-samples spark-java spf4j diff --git a/apache-shiro/.gitignore b/security-modules/apache-shiro/.gitignore similarity index 100% rename from apache-shiro/.gitignore rename to security-modules/apache-shiro/.gitignore diff --git a/apache-shiro/README.md b/security-modules/apache-shiro/README.md similarity index 100% rename from apache-shiro/README.md rename to security-modules/apache-shiro/README.md diff --git a/apache-shiro/pom.xml b/security-modules/apache-shiro/pom.xml similarity index 97% rename from apache-shiro/pom.xml rename to security-modules/apache-shiro/pom.xml index 850653ef98..2ab168ded5 100644 --- a/apache-shiro/pom.xml +++ b/security-modules/apache-shiro/pom.xml @@ -11,7 +11,7 @@ com.baeldung parent-boot-2 0.0.1-SNAPSHOT - ../parent-boot-2 + ../../parent-boot-2 diff --git a/apache-shiro/src/main/java/com/baeldung/comparison/shiro/CustomRealm.java b/security-modules/apache-shiro/src/main/java/com/baeldung/comparison/shiro/CustomRealm.java similarity index 100% rename from apache-shiro/src/main/java/com/baeldung/comparison/shiro/CustomRealm.java rename to security-modules/apache-shiro/src/main/java/com/baeldung/comparison/shiro/CustomRealm.java diff --git a/apache-shiro/src/main/java/com/baeldung/comparison/shiro/ShiroApplication.java b/security-modules/apache-shiro/src/main/java/com/baeldung/comparison/shiro/ShiroApplication.java similarity index 100% rename from apache-shiro/src/main/java/com/baeldung/comparison/shiro/ShiroApplication.java rename to security-modules/apache-shiro/src/main/java/com/baeldung/comparison/shiro/ShiroApplication.java diff --git a/apache-shiro/src/main/java/com/baeldung/comparison/shiro/controllers/ShiroController.java b/security-modules/apache-shiro/src/main/java/com/baeldung/comparison/shiro/controllers/ShiroController.java similarity index 100% rename from apache-shiro/src/main/java/com/baeldung/comparison/shiro/controllers/ShiroController.java rename to security-modules/apache-shiro/src/main/java/com/baeldung/comparison/shiro/controllers/ShiroController.java diff --git a/apache-shiro/src/main/java/com/baeldung/comparison/shiro/models/UserCredentials.java b/security-modules/apache-shiro/src/main/java/com/baeldung/comparison/shiro/models/UserCredentials.java similarity index 100% rename from apache-shiro/src/main/java/com/baeldung/comparison/shiro/models/UserCredentials.java rename to security-modules/apache-shiro/src/main/java/com/baeldung/comparison/shiro/models/UserCredentials.java diff --git a/apache-shiro/src/main/java/com/baeldung/comparison/springsecurity/Application.java b/security-modules/apache-shiro/src/main/java/com/baeldung/comparison/springsecurity/Application.java similarity index 100% rename from apache-shiro/src/main/java/com/baeldung/comparison/springsecurity/Application.java rename to security-modules/apache-shiro/src/main/java/com/baeldung/comparison/springsecurity/Application.java diff --git a/apache-shiro/src/main/java/com/baeldung/comparison/springsecurity/config/SecurityConfig.java b/security-modules/apache-shiro/src/main/java/com/baeldung/comparison/springsecurity/config/SecurityConfig.java similarity index 100% rename from apache-shiro/src/main/java/com/baeldung/comparison/springsecurity/config/SecurityConfig.java rename to security-modules/apache-shiro/src/main/java/com/baeldung/comparison/springsecurity/config/SecurityConfig.java diff --git a/apache-shiro/src/main/java/com/baeldung/comparison/springsecurity/web/SpringController.java b/security-modules/apache-shiro/src/main/java/com/baeldung/comparison/springsecurity/web/SpringController.java similarity index 100% rename from apache-shiro/src/main/java/com/baeldung/comparison/springsecurity/web/SpringController.java rename to security-modules/apache-shiro/src/main/java/com/baeldung/comparison/springsecurity/web/SpringController.java diff --git a/apache-shiro/src/main/java/com/baeldung/intro/Main.java b/security-modules/apache-shiro/src/main/java/com/baeldung/intro/Main.java similarity index 100% rename from apache-shiro/src/main/java/com/baeldung/intro/Main.java rename to security-modules/apache-shiro/src/main/java/com/baeldung/intro/Main.java diff --git a/apache-shiro/src/main/java/com/baeldung/intro/MyCustomRealm.java b/security-modules/apache-shiro/src/main/java/com/baeldung/intro/MyCustomRealm.java similarity index 100% rename from apache-shiro/src/main/java/com/baeldung/intro/MyCustomRealm.java rename to security-modules/apache-shiro/src/main/java/com/baeldung/intro/MyCustomRealm.java diff --git a/apache-shiro/src/main/java/com/baeldung/intro/ShiroSpringApplication.java b/security-modules/apache-shiro/src/main/java/com/baeldung/intro/ShiroSpringApplication.java similarity index 100% rename from apache-shiro/src/main/java/com/baeldung/intro/ShiroSpringApplication.java rename to security-modules/apache-shiro/src/main/java/com/baeldung/intro/ShiroSpringApplication.java diff --git a/apache-shiro/src/main/java/com/baeldung/intro/controllers/ShiroSpringController.java b/security-modules/apache-shiro/src/main/java/com/baeldung/intro/controllers/ShiroSpringController.java similarity index 100% rename from apache-shiro/src/main/java/com/baeldung/intro/controllers/ShiroSpringController.java rename to security-modules/apache-shiro/src/main/java/com/baeldung/intro/controllers/ShiroSpringController.java diff --git a/apache-shiro/src/main/java/com/baeldung/intro/models/UserCredentials.java b/security-modules/apache-shiro/src/main/java/com/baeldung/intro/models/UserCredentials.java similarity index 100% rename from apache-shiro/src/main/java/com/baeldung/intro/models/UserCredentials.java rename to security-modules/apache-shiro/src/main/java/com/baeldung/intro/models/UserCredentials.java diff --git a/apache-shiro/src/main/java/com/baeldung/permissions/custom/Main.java b/security-modules/apache-shiro/src/main/java/com/baeldung/permissions/custom/Main.java similarity index 100% rename from apache-shiro/src/main/java/com/baeldung/permissions/custom/Main.java rename to security-modules/apache-shiro/src/main/java/com/baeldung/permissions/custom/Main.java diff --git a/apache-shiro/src/main/java/com/baeldung/permissions/custom/PathPermission.java b/security-modules/apache-shiro/src/main/java/com/baeldung/permissions/custom/PathPermission.java similarity index 100% rename from apache-shiro/src/main/java/com/baeldung/permissions/custom/PathPermission.java rename to security-modules/apache-shiro/src/main/java/com/baeldung/permissions/custom/PathPermission.java diff --git a/apache-shiro/src/main/java/com/baeldung/permissions/custom/PathPermissionResolver.java b/security-modules/apache-shiro/src/main/java/com/baeldung/permissions/custom/PathPermissionResolver.java similarity index 100% rename from apache-shiro/src/main/java/com/baeldung/permissions/custom/PathPermissionResolver.java rename to security-modules/apache-shiro/src/main/java/com/baeldung/permissions/custom/PathPermissionResolver.java diff --git a/apache-shiro/src/main/resources/application.properties b/security-modules/apache-shiro/src/main/resources/application.properties similarity index 100% rename from apache-shiro/src/main/resources/application.properties rename to security-modules/apache-shiro/src/main/resources/application.properties diff --git a/apache-shiro/src/main/resources/com/baeldung/shiro/permissions/custom/shiro.ini b/security-modules/apache-shiro/src/main/resources/com/baeldung/shiro/permissions/custom/shiro.ini similarity index 100% rename from apache-shiro/src/main/resources/com/baeldung/shiro/permissions/custom/shiro.ini rename to security-modules/apache-shiro/src/main/resources/com/baeldung/shiro/permissions/custom/shiro.ini diff --git a/apache-shiro/src/main/resources/log4j.properties b/security-modules/apache-shiro/src/main/resources/log4j.properties similarity index 100% rename from apache-shiro/src/main/resources/log4j.properties rename to security-modules/apache-shiro/src/main/resources/log4j.properties diff --git a/apache-shiro/src/main/resources/logback.xml b/security-modules/apache-shiro/src/main/resources/logback.xml similarity index 100% rename from apache-shiro/src/main/resources/logback.xml rename to security-modules/apache-shiro/src/main/resources/logback.xml diff --git a/apache-shiro/src/main/resources/shiro.ini b/security-modules/apache-shiro/src/main/resources/shiro.ini similarity index 100% rename from apache-shiro/src/main/resources/shiro.ini rename to security-modules/apache-shiro/src/main/resources/shiro.ini diff --git a/apache-shiro/src/main/resources/templates/comparison/home.ftl b/security-modules/apache-shiro/src/main/resources/templates/comparison/home.ftl similarity index 100% rename from apache-shiro/src/main/resources/templates/comparison/home.ftl rename to security-modules/apache-shiro/src/main/resources/templates/comparison/home.ftl diff --git a/apache-shiro/src/main/resources/templates/comparison/index.ftl b/security-modules/apache-shiro/src/main/resources/templates/comparison/index.ftl similarity index 100% rename from apache-shiro/src/main/resources/templates/comparison/index.ftl rename to security-modules/apache-shiro/src/main/resources/templates/comparison/index.ftl diff --git a/apache-shiro/src/main/resources/templates/comparison/login.ftl b/security-modules/apache-shiro/src/main/resources/templates/comparison/login.ftl similarity index 100% rename from apache-shiro/src/main/resources/templates/comparison/login.ftl rename to security-modules/apache-shiro/src/main/resources/templates/comparison/login.ftl diff --git a/apache-shiro/src/main/resources/templates/index.ftl b/security-modules/apache-shiro/src/main/resources/templates/index.ftl similarity index 100% rename from apache-shiro/src/main/resources/templates/index.ftl rename to security-modules/apache-shiro/src/main/resources/templates/index.ftl diff --git a/apache-shiro/src/main/resources/templates/login.ftl b/security-modules/apache-shiro/src/main/resources/templates/login.ftl similarity index 100% rename from apache-shiro/src/main/resources/templates/login.ftl rename to security-modules/apache-shiro/src/main/resources/templates/login.ftl diff --git a/apache-shiro/src/main/resources/templates/secure.ftl b/security-modules/apache-shiro/src/main/resources/templates/secure.ftl similarity index 100% rename from apache-shiro/src/main/resources/templates/secure.ftl rename to security-modules/apache-shiro/src/main/resources/templates/secure.ftl diff --git a/apache-shiro/src/test/java/com/baeldung/comparison/shiro/SpringContextTest.java b/security-modules/apache-shiro/src/test/java/com/baeldung/comparison/shiro/SpringContextTest.java similarity index 100% rename from apache-shiro/src/test/java/com/baeldung/comparison/shiro/SpringContextTest.java rename to security-modules/apache-shiro/src/test/java/com/baeldung/comparison/shiro/SpringContextTest.java diff --git a/apache-shiro/src/test/java/com/baeldung/comparison/springsecurity/SpringContextTest.java b/security-modules/apache-shiro/src/test/java/com/baeldung/comparison/springsecurity/SpringContextTest.java similarity index 100% rename from apache-shiro/src/test/java/com/baeldung/comparison/springsecurity/SpringContextTest.java rename to security-modules/apache-shiro/src/test/java/com/baeldung/comparison/springsecurity/SpringContextTest.java diff --git a/apache-shiro/src/test/resources/logback-test.xml b/security-modules/apache-shiro/src/test/resources/logback-test.xml similarity index 100% rename from apache-shiro/src/test/resources/logback-test.xml rename to security-modules/apache-shiro/src/test/resources/logback-test.xml diff --git a/cas/README.md b/security-modules/cas/README.md similarity index 100% rename from cas/README.md rename to security-modules/cas/README.md diff --git a/cas/cas-secured-app/.gitignore b/security-modules/cas/cas-secured-app/.gitignore similarity index 100% rename from cas/cas-secured-app/.gitignore rename to security-modules/cas/cas-secured-app/.gitignore diff --git a/cas/cas-secured-app/README.md b/security-modules/cas/cas-secured-app/README.md similarity index 100% rename from cas/cas-secured-app/README.md rename to security-modules/cas/cas-secured-app/README.md diff --git a/cas/cas-secured-app/pom.xml b/security-modules/cas/cas-secured-app/pom.xml similarity index 100% rename from cas/cas-secured-app/pom.xml rename to security-modules/cas/cas-secured-app/pom.xml diff --git a/cas/cas-secured-app/src/main/java/com/baeldung/cassecuredapp/CasSecuredApplication.java b/security-modules/cas/cas-secured-app/src/main/java/com/baeldung/cassecuredapp/CasSecuredApplication.java similarity index 100% rename from cas/cas-secured-app/src/main/java/com/baeldung/cassecuredapp/CasSecuredApplication.java rename to security-modules/cas/cas-secured-app/src/main/java/com/baeldung/cassecuredapp/CasSecuredApplication.java diff --git a/cas/cas-secured-app/src/main/java/com/baeldung/cassecuredapp/config/WebSecurityConfig.java b/security-modules/cas/cas-secured-app/src/main/java/com/baeldung/cassecuredapp/config/WebSecurityConfig.java similarity index 100% rename from cas/cas-secured-app/src/main/java/com/baeldung/cassecuredapp/config/WebSecurityConfig.java rename to security-modules/cas/cas-secured-app/src/main/java/com/baeldung/cassecuredapp/config/WebSecurityConfig.java diff --git a/cas/cas-secured-app/src/main/java/com/baeldung/cassecuredapp/controllers/AuthController.java b/security-modules/cas/cas-secured-app/src/main/java/com/baeldung/cassecuredapp/controllers/AuthController.java similarity index 100% rename from cas/cas-secured-app/src/main/java/com/baeldung/cassecuredapp/controllers/AuthController.java rename to security-modules/cas/cas-secured-app/src/main/java/com/baeldung/cassecuredapp/controllers/AuthController.java diff --git a/cas/cas-secured-app/src/main/java/com/baeldung/cassecuredapp/controllers/IndexController.java b/security-modules/cas/cas-secured-app/src/main/java/com/baeldung/cassecuredapp/controllers/IndexController.java similarity index 100% rename from cas/cas-secured-app/src/main/java/com/baeldung/cassecuredapp/controllers/IndexController.java rename to security-modules/cas/cas-secured-app/src/main/java/com/baeldung/cassecuredapp/controllers/IndexController.java diff --git a/cas/cas-secured-app/src/main/java/com/baeldung/cassecuredapp/controllers/SecuredController.java b/security-modules/cas/cas-secured-app/src/main/java/com/baeldung/cassecuredapp/controllers/SecuredController.java similarity index 100% rename from cas/cas-secured-app/src/main/java/com/baeldung/cassecuredapp/controllers/SecuredController.java rename to security-modules/cas/cas-secured-app/src/main/java/com/baeldung/cassecuredapp/controllers/SecuredController.java diff --git a/cas/cas-secured-app/src/main/resources/application.properties b/security-modules/cas/cas-secured-app/src/main/resources/application.properties similarity index 100% rename from cas/cas-secured-app/src/main/resources/application.properties rename to security-modules/cas/cas-secured-app/src/main/resources/application.properties diff --git a/cas/cas-secured-app/src/main/resources/logback.xml b/security-modules/cas/cas-secured-app/src/main/resources/logback.xml similarity index 100% rename from cas/cas-secured-app/src/main/resources/logback.xml rename to security-modules/cas/cas-secured-app/src/main/resources/logback.xml diff --git a/cas/cas-secured-app/src/main/resources/templates/auth/logout.ftl b/security-modules/cas/cas-secured-app/src/main/resources/templates/auth/logout.ftl similarity index 100% rename from cas/cas-secured-app/src/main/resources/templates/auth/logout.ftl rename to security-modules/cas/cas-secured-app/src/main/resources/templates/auth/logout.ftl diff --git a/cas/cas-secured-app/src/main/resources/templates/index.ftl b/security-modules/cas/cas-secured-app/src/main/resources/templates/index.ftl similarity index 100% rename from cas/cas-secured-app/src/main/resources/templates/index.ftl rename to security-modules/cas/cas-secured-app/src/main/resources/templates/index.ftl diff --git a/cas/cas-secured-app/src/main/resources/templates/secure/index.ftl b/security-modules/cas/cas-secured-app/src/main/resources/templates/secure/index.ftl similarity index 100% rename from cas/cas-secured-app/src/main/resources/templates/secure/index.ftl rename to security-modules/cas/cas-secured-app/src/main/resources/templates/secure/index.ftl diff --git a/cas/cas-secured-app/src/test/java/com/baeldung/cassecuredapp/CasSecuredApplicationIntegrationTest.java b/security-modules/cas/cas-secured-app/src/test/java/com/baeldung/cassecuredapp/CasSecuredApplicationIntegrationTest.java similarity index 100% rename from cas/cas-secured-app/src/test/java/com/baeldung/cassecuredapp/CasSecuredApplicationIntegrationTest.java rename to security-modules/cas/cas-secured-app/src/test/java/com/baeldung/cassecuredapp/CasSecuredApplicationIntegrationTest.java diff --git a/cas/cas-server/.gitignore b/security-modules/cas/cas-server/.gitignore old mode 100755 new mode 100644 similarity index 100% rename from cas/cas-server/.gitignore rename to security-modules/cas/cas-server/.gitignore diff --git a/cas/cas-server/.mergify.yml b/security-modules/cas/cas-server/.mergify.yml similarity index 100% rename from cas/cas-server/.mergify.yml rename to security-modules/cas/cas-server/.mergify.yml diff --git a/cas/cas-server/.travis.yml b/security-modules/cas/cas-server/.travis.yml similarity index 100% rename from cas/cas-server/.travis.yml rename to security-modules/cas/cas-server/.travis.yml diff --git a/cas/cas-server/Dockerfile b/security-modules/cas/cas-server/Dockerfile similarity index 100% rename from cas/cas-server/Dockerfile rename to security-modules/cas/cas-server/Dockerfile diff --git a/cas/cas-server/LICENSE.txt b/security-modules/cas/cas-server/LICENSE.txt similarity index 100% rename from cas/cas-server/LICENSE.txt rename to security-modules/cas/cas-server/LICENSE.txt diff --git a/cas/cas-server/build.gradle b/security-modules/cas/cas-server/build.gradle similarity index 100% rename from cas/cas-server/build.gradle rename to security-modules/cas/cas-server/build.gradle diff --git a/cas/cas-server/docker-build.sh b/security-modules/cas/cas-server/docker-build.sh old mode 100755 new mode 100644 similarity index 100% rename from cas/cas-server/docker-build.sh rename to security-modules/cas/cas-server/docker-build.sh diff --git a/cas/cas-server/docker-compose.yml b/security-modules/cas/cas-server/docker-compose.yml similarity index 100% rename from cas/cas-server/docker-compose.yml rename to security-modules/cas/cas-server/docker-compose.yml diff --git a/cas/cas-server/docker-push.sh b/security-modules/cas/cas-server/docker-push.sh old mode 100755 new mode 100644 similarity index 100% rename from cas/cas-server/docker-push.sh rename to security-modules/cas/cas-server/docker-push.sh diff --git a/cas/cas-server/docker-run.sh b/security-modules/cas/cas-server/docker-run.sh old mode 100755 new mode 100644 similarity index 100% rename from cas/cas-server/docker-run.sh rename to security-modules/cas/cas-server/docker-run.sh diff --git a/cas/cas-server/etc/cas/config/cas.properties b/security-modules/cas/cas-server/etc/cas/config/cas.properties similarity index 100% rename from cas/cas-server/etc/cas/config/cas.properties rename to security-modules/cas/cas-server/etc/cas/config/cas.properties diff --git a/cas/cas-server/etc/cas/config/log4j2.xml b/security-modules/cas/cas-server/etc/cas/config/log4j2.xml similarity index 100% rename from cas/cas-server/etc/cas/config/log4j2.xml rename to security-modules/cas/cas-server/etc/cas/config/log4j2.xml diff --git a/cas/cas-server/etc/cas/saml/.gitkeep b/security-modules/cas/cas-server/etc/cas/saml/.gitkeep similarity index 100% rename from cas/cas-server/etc/cas/saml/.gitkeep rename to security-modules/cas/cas-server/etc/cas/saml/.gitkeep diff --git a/cas/cas-server/etc/cas/services/.donotdel b/security-modules/cas/cas-server/etc/cas/services/.donotdel similarity index 100% rename from cas/cas-server/etc/cas/services/.donotdel rename to security-modules/cas/cas-server/etc/cas/services/.donotdel diff --git a/cas/cas-server/etc/cas/thekeystore b/security-modules/cas/cas-server/etc/cas/thekeystore similarity index 100% rename from cas/cas-server/etc/cas/thekeystore rename to security-modules/cas/cas-server/etc/cas/thekeystore diff --git a/cas/cas-server/gradle.properties b/security-modules/cas/cas-server/gradle.properties similarity index 100% rename from cas/cas-server/gradle.properties rename to security-modules/cas/cas-server/gradle.properties diff --git a/cas/cas-server/gradle/dockerjib.gradle b/security-modules/cas/cas-server/gradle/dockerjib.gradle similarity index 100% rename from cas/cas-server/gradle/dockerjib.gradle rename to security-modules/cas/cas-server/gradle/dockerjib.gradle diff --git a/cas/cas-server/gradle/springboot.gradle b/security-modules/cas/cas-server/gradle/springboot.gradle similarity index 100% rename from cas/cas-server/gradle/springboot.gradle rename to security-modules/cas/cas-server/gradle/springboot.gradle diff --git a/cas/cas-server/gradle/tasks.gradle b/security-modules/cas/cas-server/gradle/tasks.gradle similarity index 100% rename from cas/cas-server/gradle/tasks.gradle rename to security-modules/cas/cas-server/gradle/tasks.gradle diff --git a/cas/cas-server/gradle/wrapper/gradle-wrapper.properties b/security-modules/cas/cas-server/gradle/wrapper/gradle-wrapper.properties similarity index 100% rename from cas/cas-server/gradle/wrapper/gradle-wrapper.properties rename to security-modules/cas/cas-server/gradle/wrapper/gradle-wrapper.properties diff --git a/cas/cas-server/gradlew b/security-modules/cas/cas-server/gradlew old mode 100755 new mode 100644 similarity index 100% rename from cas/cas-server/gradlew rename to security-modules/cas/cas-server/gradlew diff --git a/cas/cas-server/gradlew.bat b/security-modules/cas/cas-server/gradlew.bat similarity index 96% rename from cas/cas-server/gradlew.bat rename to security-modules/cas/cas-server/gradlew.bat index 24467a141f..9618d8d960 100644 --- a/cas/cas-server/gradlew.bat +++ b/security-modules/cas/cas-server/gradlew.bat @@ -1,100 +1,100 @@ -@rem -@rem Copyright 2015 the original author or authors. -@rem -@rem Licensed under the Apache License, Version 2.0 (the "License"); -@rem you may not use this file except in compliance with the License. -@rem You may obtain a copy of the License at -@rem -@rem https://www.apache.org/licenses/LICENSE-2.0 -@rem -@rem Unless required by applicable law or agreed to in writing, software -@rem distributed under the License is distributed on an "AS IS" BASIS, -@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -@rem See the License for the specific language governing permissions and -@rem limitations under the License. -@rem - -@if "%DEBUG%" == "" @echo off -@rem ########################################################################## -@rem -@rem Gradle startup script for Windows -@rem -@rem ########################################################################## - -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal - -set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. -set APP_BASE_NAME=%~n0 -set APP_HOME=%DIRNAME% - -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" - -@rem Find java.exe -if defined JAVA_HOME goto findJavaFromJavaHome - -set JAVA_EXE=java.exe -%JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto init - -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:findJavaFromJavaHome -set JAVA_HOME=%JAVA_HOME:"=% -set JAVA_EXE=%JAVA_HOME%/bin/java.exe - -if exist "%JAVA_EXE%" goto init - -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:init -@rem Get command-line arguments, handling Windows variants - -if not "%OS%" == "Windows_NT" goto win9xME_args - -:win9xME_args -@rem Slurp the command line arguments. -set CMD_LINE_ARGS= -set _SKIP=2 - -:win9xME_args_slurp -if "x%~1" == "x" goto execute - -set CMD_LINE_ARGS=%* - -:execute -@rem Setup the command line - -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar - -@rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% - -:end -@rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd - -:fail -rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of -rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 - -:mainEnd -if "%OS%"=="Windows_NT" endlocal - -:omega +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windows variants + +if not "%OS%" == "Windows_NT" goto win9xME_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/cas/cas-server/settings.gradle b/security-modules/cas/cas-server/settings.gradle similarity index 100% rename from cas/cas-server/settings.gradle rename to security-modules/cas/cas-server/settings.gradle diff --git a/cas/cas-server/src/main/jib/docker/entrypoint.sh b/security-modules/cas/cas-server/src/main/jib/docker/entrypoint.sh old mode 100755 new mode 100644 similarity index 100% rename from cas/cas-server/src/main/jib/docker/entrypoint.sh rename to security-modules/cas/cas-server/src/main/jib/docker/entrypoint.sh diff --git a/cas/cas-server/src/main/resources/application.properties b/security-modules/cas/cas-server/src/main/resources/application.properties similarity index 100% rename from cas/cas-server/src/main/resources/application.properties rename to security-modules/cas/cas-server/src/main/resources/application.properties diff --git a/cas/cas-server/src/main/resources/create_test_db_and_users_tbl.sql b/security-modules/cas/cas-server/src/main/resources/create_test_db_and_users_tbl.sql similarity index 100% rename from cas/cas-server/src/main/resources/create_test_db_and_users_tbl.sql rename to security-modules/cas/cas-server/src/main/resources/create_test_db_and_users_tbl.sql diff --git a/cas/cas-server/src/main/resources/etc/cas/config/cas.properties b/security-modules/cas/cas-server/src/main/resources/etc/cas/config/cas.properties similarity index 100% rename from cas/cas-server/src/main/resources/etc/cas/config/cas.properties rename to security-modules/cas/cas-server/src/main/resources/etc/cas/config/cas.properties diff --git a/cas/cas-server/src/main/resources/etc/cas/services/casSecuredApp-8900.json b/security-modules/cas/cas-server/src/main/resources/etc/cas/services/casSecuredApp-8900.json similarity index 100% rename from cas/cas-server/src/main/resources/etc/cas/services/casSecuredApp-8900.json rename to security-modules/cas/cas-server/src/main/resources/etc/cas/services/casSecuredApp-8900.json diff --git a/cas/cas-server/src/main/resources/etc/cas/thekeystore b/security-modules/cas/cas-server/src/main/resources/etc/cas/thekeystore similarity index 100% rename from cas/cas-server/src/main/resources/etc/cas/thekeystore rename to security-modules/cas/cas-server/src/main/resources/etc/cas/thekeystore diff --git a/cas/pom.xml b/security-modules/cas/pom.xml similarity index 91% rename from cas/pom.xml rename to security-modules/cas/pom.xml index 2f24e41453..d40f303717 100644 --- a/cas/pom.xml +++ b/security-modules/cas/pom.xml @@ -12,7 +12,7 @@ com.baeldung parent-boot-2 0.0.1-SNAPSHOT - ../parent-boot-2 + ../../parent-boot-2 diff --git a/cloud-foundry-uaa/README.md b/security-modules/cloud-foundry-uaa/README.md similarity index 100% rename from cloud-foundry-uaa/README.md rename to security-modules/cloud-foundry-uaa/README.md diff --git a/cloud-foundry-uaa/cf-uaa-config/uaa.yml b/security-modules/cloud-foundry-uaa/cf-uaa-config/uaa.yml similarity index 100% rename from cloud-foundry-uaa/cf-uaa-config/uaa.yml rename to security-modules/cloud-foundry-uaa/cf-uaa-config/uaa.yml diff --git a/cloud-foundry-uaa/cf-uaa-oauth2-client/pom.xml b/security-modules/cloud-foundry-uaa/cf-uaa-oauth2-client/pom.xml similarity index 100% rename from cloud-foundry-uaa/cf-uaa-oauth2-client/pom.xml rename to security-modules/cloud-foundry-uaa/cf-uaa-oauth2-client/pom.xml diff --git a/cloud-foundry-uaa/cf-uaa-oauth2-client/src/main/java/com/baeldung/cfuaa/oauth2/client/CFUAAOAuth2ClientApplication.java b/security-modules/cloud-foundry-uaa/cf-uaa-oauth2-client/src/main/java/com/baeldung/cfuaa/oauth2/client/CFUAAOAuth2ClientApplication.java similarity index 100% rename from cloud-foundry-uaa/cf-uaa-oauth2-client/src/main/java/com/baeldung/cfuaa/oauth2/client/CFUAAOAuth2ClientApplication.java rename to security-modules/cloud-foundry-uaa/cf-uaa-oauth2-client/src/main/java/com/baeldung/cfuaa/oauth2/client/CFUAAOAuth2ClientApplication.java diff --git a/cloud-foundry-uaa/cf-uaa-oauth2-client/src/main/java/com/baeldung/cfuaa/oauth2/client/CFUAAOAuth2ClientController.java b/security-modules/cloud-foundry-uaa/cf-uaa-oauth2-client/src/main/java/com/baeldung/cfuaa/oauth2/client/CFUAAOAuth2ClientController.java similarity index 97% rename from cloud-foundry-uaa/cf-uaa-oauth2-client/src/main/java/com/baeldung/cfuaa/oauth2/client/CFUAAOAuth2ClientController.java rename to security-modules/cloud-foundry-uaa/cf-uaa-oauth2-client/src/main/java/com/baeldung/cfuaa/oauth2/client/CFUAAOAuth2ClientController.java index b1631ed327..bc745fc436 100644 --- a/cloud-foundry-uaa/cf-uaa-oauth2-client/src/main/java/com/baeldung/cfuaa/oauth2/client/CFUAAOAuth2ClientController.java +++ b/security-modules/cloud-foundry-uaa/cf-uaa-oauth2-client/src/main/java/com/baeldung/cfuaa/oauth2/client/CFUAAOAuth2ClientController.java @@ -1,80 +1,80 @@ -package com.baeldung.cfuaa.oauth2.client; - -import org.springframework.beans.factory.annotation.Value; -import org.springframework.http.HttpEntity; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpMethod; -import org.springframework.http.ResponseEntity; -import org.springframework.security.oauth2.client.OAuth2AuthorizedClient; -import org.springframework.security.oauth2.client.OAuth2AuthorizedClientService; -import org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken; -import org.springframework.security.oauth2.core.OAuth2AccessToken; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; -import org.springframework.web.client.HttpClientErrorException; -import org.springframework.web.client.RestTemplate; - -@RestController -public class CFUAAOAuth2ClientController { - - @Value("${resource.server.url}") - private String remoteResourceServer; - - private RestTemplate restTemplate; - - private OAuth2AuthorizedClientService authorizedClientService; - - public CFUAAOAuth2ClientController(OAuth2AuthorizedClientService authorizedClientService) { - this.authorizedClientService = authorizedClientService; - this.restTemplate = new RestTemplate(); - } - - @RequestMapping("/") - public String index(OAuth2AuthenticationToken authenticationToken) { - OAuth2AuthorizedClient oAuth2AuthorizedClient = this.authorizedClientService.loadAuthorizedClient(authenticationToken.getAuthorizedClientRegistrationId(), authenticationToken.getName()); - OAuth2AccessToken oAuth2AccessToken = oAuth2AuthorizedClient.getAccessToken(); - - String response = "Hello, " + authenticationToken.getPrincipal().getName(); - response += "

"; - response += "Here is your accees token :
" + oAuth2AccessToken.getTokenValue(); - response += "
"; - response += "
You can use it to call these Resource Server APIs:"; - response += "

"; - response += "Call Resource Server Read API"; - response += "
"; - response += "Call Resource Server Write API"; - return response; - } - - @RequestMapping("/read") - public String read(OAuth2AuthenticationToken authenticationToken) { - String url = remoteResourceServer + "/read"; - return callResourceServer(authenticationToken, url); - } - - @RequestMapping("/write") - public String write(OAuth2AuthenticationToken authenticationToken) { - String url = remoteResourceServer + "/write"; - return callResourceServer(authenticationToken, url); - } - - private String callResourceServer(OAuth2AuthenticationToken authenticationToken, String url) { - OAuth2AuthorizedClient oAuth2AuthorizedClient = this.authorizedClientService.loadAuthorizedClient(authenticationToken.getAuthorizedClientRegistrationId(), authenticationToken.getName()); - OAuth2AccessToken oAuth2AccessToken = oAuth2AuthorizedClient.getAccessToken(); - - HttpHeaders headers = new HttpHeaders(); - headers.add("Authorization", "Bearer " + oAuth2AccessToken.getTokenValue()); - - HttpEntity entity = new HttpEntity<>("parameters", headers); - ResponseEntity responseEntity = null; - - String response = null; - try { - responseEntity = restTemplate.exchange(url, HttpMethod.GET, entity, String.class); - response = responseEntity.getBody(); - } catch (HttpClientErrorException e) { - response = e.getMessage(); - } - return response; - } +package com.baeldung.cfuaa.oauth2.client; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.ResponseEntity; +import org.springframework.security.oauth2.client.OAuth2AuthorizedClient; +import org.springframework.security.oauth2.client.OAuth2AuthorizedClientService; +import org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken; +import org.springframework.security.oauth2.core.OAuth2AccessToken; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.client.HttpClientErrorException; +import org.springframework.web.client.RestTemplate; + +@RestController +public class CFUAAOAuth2ClientController { + + @Value("${resource.server.url}") + private String remoteResourceServer; + + private RestTemplate restTemplate; + + private OAuth2AuthorizedClientService authorizedClientService; + + public CFUAAOAuth2ClientController(OAuth2AuthorizedClientService authorizedClientService) { + this.authorizedClientService = authorizedClientService; + this.restTemplate = new RestTemplate(); + } + + @RequestMapping("/") + public String index(OAuth2AuthenticationToken authenticationToken) { + OAuth2AuthorizedClient oAuth2AuthorizedClient = this.authorizedClientService.loadAuthorizedClient(authenticationToken.getAuthorizedClientRegistrationId(), authenticationToken.getName()); + OAuth2AccessToken oAuth2AccessToken = oAuth2AuthorizedClient.getAccessToken(); + + String response = "Hello, " + authenticationToken.getPrincipal().getName(); + response += "

"; + response += "Here is your accees token :
" + oAuth2AccessToken.getTokenValue(); + response += "
"; + response += "
You can use it to call these Resource Server APIs:"; + response += "

"; + response += "Call Resource Server Read API"; + response += "
"; + response += "Call Resource Server Write API"; + return response; + } + + @RequestMapping("/read") + public String read(OAuth2AuthenticationToken authenticationToken) { + String url = remoteResourceServer + "/read"; + return callResourceServer(authenticationToken, url); + } + + @RequestMapping("/write") + public String write(OAuth2AuthenticationToken authenticationToken) { + String url = remoteResourceServer + "/write"; + return callResourceServer(authenticationToken, url); + } + + private String callResourceServer(OAuth2AuthenticationToken authenticationToken, String url) { + OAuth2AuthorizedClient oAuth2AuthorizedClient = this.authorizedClientService.loadAuthorizedClient(authenticationToken.getAuthorizedClientRegistrationId(), authenticationToken.getName()); + OAuth2AccessToken oAuth2AccessToken = oAuth2AuthorizedClient.getAccessToken(); + + HttpHeaders headers = new HttpHeaders(); + headers.add("Authorization", "Bearer " + oAuth2AccessToken.getTokenValue()); + + HttpEntity entity = new HttpEntity<>("parameters", headers); + ResponseEntity responseEntity = null; + + String response = null; + try { + responseEntity = restTemplate.exchange(url, HttpMethod.GET, entity, String.class); + response = responseEntity.getBody(); + } catch (HttpClientErrorException e) { + response = e.getMessage(); + } + return response; + } } \ No newline at end of file diff --git a/cloud-foundry-uaa/cf-uaa-oauth2-client/src/main/resources/application.properties b/security-modules/cloud-foundry-uaa/cf-uaa-oauth2-client/src/main/resources/application.properties similarity index 100% rename from cloud-foundry-uaa/cf-uaa-oauth2-client/src/main/resources/application.properties rename to security-modules/cloud-foundry-uaa/cf-uaa-oauth2-client/src/main/resources/application.properties diff --git a/cloud-foundry-uaa/cf-uaa-oauth2-client/src/main/resources/templates/index.html b/security-modules/cloud-foundry-uaa/cf-uaa-oauth2-client/src/main/resources/templates/index.html similarity index 100% rename from cloud-foundry-uaa/cf-uaa-oauth2-client/src/main/resources/templates/index.html rename to security-modules/cloud-foundry-uaa/cf-uaa-oauth2-client/src/main/resources/templates/index.html diff --git a/cloud-foundry-uaa/cf-uaa-oauth2-resource-server/pom.xml b/security-modules/cloud-foundry-uaa/cf-uaa-oauth2-resource-server/pom.xml similarity index 100% rename from cloud-foundry-uaa/cf-uaa-oauth2-resource-server/pom.xml rename to security-modules/cloud-foundry-uaa/cf-uaa-oauth2-resource-server/pom.xml diff --git a/cloud-foundry-uaa/cf-uaa-oauth2-resource-server/src/main/java/com/baeldung/cfuaa/oauth2/resourceserver/CFUAAOAuth2ResourceServerApplication.java b/security-modules/cloud-foundry-uaa/cf-uaa-oauth2-resource-server/src/main/java/com/baeldung/cfuaa/oauth2/resourceserver/CFUAAOAuth2ResourceServerApplication.java similarity index 100% rename from cloud-foundry-uaa/cf-uaa-oauth2-resource-server/src/main/java/com/baeldung/cfuaa/oauth2/resourceserver/CFUAAOAuth2ResourceServerApplication.java rename to security-modules/cloud-foundry-uaa/cf-uaa-oauth2-resource-server/src/main/java/com/baeldung/cfuaa/oauth2/resourceserver/CFUAAOAuth2ResourceServerApplication.java diff --git a/cloud-foundry-uaa/cf-uaa-oauth2-resource-server/src/main/java/com/baeldung/cfuaa/oauth2/resourceserver/CFUAAOAuth2ResourceServerRestController.java b/security-modules/cloud-foundry-uaa/cf-uaa-oauth2-resource-server/src/main/java/com/baeldung/cfuaa/oauth2/resourceserver/CFUAAOAuth2ResourceServerRestController.java similarity index 97% rename from cloud-foundry-uaa/cf-uaa-oauth2-resource-server/src/main/java/com/baeldung/cfuaa/oauth2/resourceserver/CFUAAOAuth2ResourceServerRestController.java rename to security-modules/cloud-foundry-uaa/cf-uaa-oauth2-resource-server/src/main/java/com/baeldung/cfuaa/oauth2/resourceserver/CFUAAOAuth2ResourceServerRestController.java index 75d8507451..614a92aeb4 100644 --- a/cloud-foundry-uaa/cf-uaa-oauth2-resource-server/src/main/java/com/baeldung/cfuaa/oauth2/resourceserver/CFUAAOAuth2ResourceServerRestController.java +++ b/security-modules/cloud-foundry-uaa/cf-uaa-oauth2-resource-server/src/main/java/com/baeldung/cfuaa/oauth2/resourceserver/CFUAAOAuth2ResourceServerRestController.java @@ -1,28 +1,28 @@ -package com.baeldung.cfuaa.oauth2.resourceserver; - -import org.springframework.security.core.annotation.AuthenticationPrincipal; -import org.springframework.security.oauth2.jwt.Jwt; -import org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationToken; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RestController; - -import java.security.Principal; - -@RestController -public class CFUAAOAuth2ResourceServerRestController { - - @GetMapping("/") - public String index(@AuthenticationPrincipal Jwt jwt) { - return String.format("Hello, %s!", jwt.getSubject()); - } - - @GetMapping("/read") - public String read(JwtAuthenticationToken jwtAuthenticationToken) { - return "Hello read: " + jwtAuthenticationToken.getTokenAttributes(); - } - - @GetMapping("/write") - public String write(Principal principal) { - return "Hello write: " + principal.getName(); - } -} +package com.baeldung.cfuaa.oauth2.resourceserver; + +import org.springframework.security.core.annotation.AuthenticationPrincipal; +import org.springframework.security.oauth2.jwt.Jwt; +import org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationToken; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.security.Principal; + +@RestController +public class CFUAAOAuth2ResourceServerRestController { + + @GetMapping("/") + public String index(@AuthenticationPrincipal Jwt jwt) { + return String.format("Hello, %s!", jwt.getSubject()); + } + + @GetMapping("/read") + public String read(JwtAuthenticationToken jwtAuthenticationToken) { + return "Hello read: " + jwtAuthenticationToken.getTokenAttributes(); + } + + @GetMapping("/write") + public String write(Principal principal) { + return "Hello write: " + principal.getName(); + } +} diff --git a/cloud-foundry-uaa/cf-uaa-oauth2-resource-server/src/main/java/com/baeldung/cfuaa/oauth2/resourceserver/CFUAAOAuth2ResourceServerSecurityConfiguration.java b/security-modules/cloud-foundry-uaa/cf-uaa-oauth2-resource-server/src/main/java/com/baeldung/cfuaa/oauth2/resourceserver/CFUAAOAuth2ResourceServerSecurityConfiguration.java similarity index 97% rename from cloud-foundry-uaa/cf-uaa-oauth2-resource-server/src/main/java/com/baeldung/cfuaa/oauth2/resourceserver/CFUAAOAuth2ResourceServerSecurityConfiguration.java rename to security-modules/cloud-foundry-uaa/cf-uaa-oauth2-resource-server/src/main/java/com/baeldung/cfuaa/oauth2/resourceserver/CFUAAOAuth2ResourceServerSecurityConfiguration.java index d04d51cda3..95bde8aa8a 100644 --- a/cloud-foundry-uaa/cf-uaa-oauth2-resource-server/src/main/java/com/baeldung/cfuaa/oauth2/resourceserver/CFUAAOAuth2ResourceServerSecurityConfiguration.java +++ b/security-modules/cloud-foundry-uaa/cf-uaa-oauth2-resource-server/src/main/java/com/baeldung/cfuaa/oauth2/resourceserver/CFUAAOAuth2ResourceServerSecurityConfiguration.java @@ -1,21 +1,21 @@ -package com.baeldung.cfuaa.oauth2.resourceserver; - -import org.springframework.security.config.annotation.web.builders.HttpSecurity; -import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; -import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; - -@EnableWebSecurity -public class CFUAAOAuth2ResourceServerSecurityConfiguration extends WebSecurityConfigurerAdapter { - - @Override - protected void configure(HttpSecurity http) throws Exception { - http - .authorizeRequests() - .antMatchers("/read/**").hasAuthority("SCOPE_resource.read") - .antMatchers("/write/**").hasAuthority("SCOPE_resource.write") - .anyRequest().authenticated() - .and() - .oauth2ResourceServer() - .jwt(); - } +package com.baeldung.cfuaa.oauth2.resourceserver; + +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; +import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; + +@EnableWebSecurity +public class CFUAAOAuth2ResourceServerSecurityConfiguration extends WebSecurityConfigurerAdapter { + + @Override + protected void configure(HttpSecurity http) throws Exception { + http + .authorizeRequests() + .antMatchers("/read/**").hasAuthority("SCOPE_resource.read") + .antMatchers("/write/**").hasAuthority("SCOPE_resource.write") + .anyRequest().authenticated() + .and() + .oauth2ResourceServer() + .jwt(); + } } \ No newline at end of file diff --git a/cloud-foundry-uaa/cf-uaa-oauth2-resource-server/src/main/resources/application.properties b/security-modules/cloud-foundry-uaa/cf-uaa-oauth2-resource-server/src/main/resources/application.properties similarity index 100% rename from cloud-foundry-uaa/cf-uaa-oauth2-resource-server/src/main/resources/application.properties rename to security-modules/cloud-foundry-uaa/cf-uaa-oauth2-resource-server/src/main/resources/application.properties diff --git a/cloud-foundry-uaa/pom.xml b/security-modules/cloud-foundry-uaa/pom.xml similarity index 92% rename from cloud-foundry-uaa/pom.xml rename to security-modules/cloud-foundry-uaa/pom.xml index 6ae43b2c08..ff26d56dc3 100644 --- a/cloud-foundry-uaa/pom.xml +++ b/security-modules/cloud-foundry-uaa/pom.xml @@ -11,7 +11,7 @@ com.baeldung parent-boot-2 0.0.1-SNAPSHOT - ../parent-boot-2 + ../../parent-boot-2 diff --git a/java-ee-8-security-api/README.md b/security-modules/java-ee-8-security-api/README.md similarity index 100% rename from java-ee-8-security-api/README.md rename to security-modules/java-ee-8-security-api/README.md diff --git a/java-ee-8-security-api/app-auth-basic-store-db/pom.xml b/security-modules/java-ee-8-security-api/app-auth-basic-store-db/pom.xml similarity index 100% rename from java-ee-8-security-api/app-auth-basic-store-db/pom.xml rename to security-modules/java-ee-8-security-api/app-auth-basic-store-db/pom.xml diff --git a/java-ee-8-security-api/app-auth-basic-store-db/src/main/java/com/baeldung/javaee/security/AdminServlet.java b/security-modules/java-ee-8-security-api/app-auth-basic-store-db/src/main/java/com/baeldung/javaee/security/AdminServlet.java similarity index 100% rename from java-ee-8-security-api/app-auth-basic-store-db/src/main/java/com/baeldung/javaee/security/AdminServlet.java rename to security-modules/java-ee-8-security-api/app-auth-basic-store-db/src/main/java/com/baeldung/javaee/security/AdminServlet.java diff --git a/java-ee-8-security-api/app-auth-basic-store-db/src/main/java/com/baeldung/javaee/security/AppConfig.java b/security-modules/java-ee-8-security-api/app-auth-basic-store-db/src/main/java/com/baeldung/javaee/security/AppConfig.java similarity index 100% rename from java-ee-8-security-api/app-auth-basic-store-db/src/main/java/com/baeldung/javaee/security/AppConfig.java rename to security-modules/java-ee-8-security-api/app-auth-basic-store-db/src/main/java/com/baeldung/javaee/security/AppConfig.java diff --git a/java-ee-8-security-api/app-auth-basic-store-db/src/main/java/com/baeldung/javaee/security/DatabaseSetupServlet.java b/security-modules/java-ee-8-security-api/app-auth-basic-store-db/src/main/java/com/baeldung/javaee/security/DatabaseSetupServlet.java similarity index 100% rename from java-ee-8-security-api/app-auth-basic-store-db/src/main/java/com/baeldung/javaee/security/DatabaseSetupServlet.java rename to security-modules/java-ee-8-security-api/app-auth-basic-store-db/src/main/java/com/baeldung/javaee/security/DatabaseSetupServlet.java diff --git a/java-ee-8-security-api/app-auth-basic-store-db/src/main/java/com/baeldung/javaee/security/UserServlet.java b/security-modules/java-ee-8-security-api/app-auth-basic-store-db/src/main/java/com/baeldung/javaee/security/UserServlet.java similarity index 100% rename from java-ee-8-security-api/app-auth-basic-store-db/src/main/java/com/baeldung/javaee/security/UserServlet.java rename to security-modules/java-ee-8-security-api/app-auth-basic-store-db/src/main/java/com/baeldung/javaee/security/UserServlet.java diff --git a/java-ee-8-security-api/app-auth-basic-store-db/src/main/liberty/config/server.xml b/security-modules/java-ee-8-security-api/app-auth-basic-store-db/src/main/liberty/config/server.xml similarity index 100% rename from java-ee-8-security-api/app-auth-basic-store-db/src/main/liberty/config/server.xml rename to security-modules/java-ee-8-security-api/app-auth-basic-store-db/src/main/liberty/config/server.xml diff --git a/java-ee-8-security-api/app-auth-basic-store-db/src/main/resources/logback.xml b/security-modules/java-ee-8-security-api/app-auth-basic-store-db/src/main/resources/logback.xml similarity index 100% rename from java-ee-8-security-api/app-auth-basic-store-db/src/main/resources/logback.xml rename to security-modules/java-ee-8-security-api/app-auth-basic-store-db/src/main/resources/logback.xml diff --git a/java-ee-8-security-api/app-auth-custom-form-store-custom/pom.xml b/security-modules/java-ee-8-security-api/app-auth-custom-form-store-custom/pom.xml similarity index 100% rename from java-ee-8-security-api/app-auth-custom-form-store-custom/pom.xml rename to security-modules/java-ee-8-security-api/app-auth-custom-form-store-custom/pom.xml diff --git a/java-ee-8-security-api/app-auth-custom-form-store-custom/src/main/java/com/baeldung/javaee/security/AppConfig.java b/security-modules/java-ee-8-security-api/app-auth-custom-form-store-custom/src/main/java/com/baeldung/javaee/security/AppConfig.java similarity index 100% rename from java-ee-8-security-api/app-auth-custom-form-store-custom/src/main/java/com/baeldung/javaee/security/AppConfig.java rename to security-modules/java-ee-8-security-api/app-auth-custom-form-store-custom/src/main/java/com/baeldung/javaee/security/AppConfig.java diff --git a/java-ee-8-security-api/app-auth-custom-form-store-custom/src/main/java/com/baeldung/javaee/security/InMemoryIdentityStore4Authentication.java b/security-modules/java-ee-8-security-api/app-auth-custom-form-store-custom/src/main/java/com/baeldung/javaee/security/InMemoryIdentityStore4Authentication.java similarity index 100% rename from java-ee-8-security-api/app-auth-custom-form-store-custom/src/main/java/com/baeldung/javaee/security/InMemoryIdentityStore4Authentication.java rename to security-modules/java-ee-8-security-api/app-auth-custom-form-store-custom/src/main/java/com/baeldung/javaee/security/InMemoryIdentityStore4Authentication.java diff --git a/java-ee-8-security-api/app-auth-custom-form-store-custom/src/main/java/com/baeldung/javaee/security/InMemoryIdentityStore4Authorization.java b/security-modules/java-ee-8-security-api/app-auth-custom-form-store-custom/src/main/java/com/baeldung/javaee/security/InMemoryIdentityStore4Authorization.java similarity index 100% rename from java-ee-8-security-api/app-auth-custom-form-store-custom/src/main/java/com/baeldung/javaee/security/InMemoryIdentityStore4Authorization.java rename to security-modules/java-ee-8-security-api/app-auth-custom-form-store-custom/src/main/java/com/baeldung/javaee/security/InMemoryIdentityStore4Authorization.java diff --git a/java-ee-8-security-api/app-auth-custom-form-store-custom/src/main/java/com/baeldung/javaee/security/LoginBean.java b/security-modules/java-ee-8-security-api/app-auth-custom-form-store-custom/src/main/java/com/baeldung/javaee/security/LoginBean.java similarity index 100% rename from java-ee-8-security-api/app-auth-custom-form-store-custom/src/main/java/com/baeldung/javaee/security/LoginBean.java rename to security-modules/java-ee-8-security-api/app-auth-custom-form-store-custom/src/main/java/com/baeldung/javaee/security/LoginBean.java diff --git a/java-ee-8-security-api/app-auth-custom-form-store-custom/src/main/java/com/baeldung/javaee/security/WelcomeServlet.java b/security-modules/java-ee-8-security-api/app-auth-custom-form-store-custom/src/main/java/com/baeldung/javaee/security/WelcomeServlet.java similarity index 100% rename from java-ee-8-security-api/app-auth-custom-form-store-custom/src/main/java/com/baeldung/javaee/security/WelcomeServlet.java rename to security-modules/java-ee-8-security-api/app-auth-custom-form-store-custom/src/main/java/com/baeldung/javaee/security/WelcomeServlet.java diff --git a/java-ee-8-security-api/app-auth-custom-form-store-custom/src/main/liberty/config/server.xml b/security-modules/java-ee-8-security-api/app-auth-custom-form-store-custom/src/main/liberty/config/server.xml similarity index 100% rename from java-ee-8-security-api/app-auth-custom-form-store-custom/src/main/liberty/config/server.xml rename to security-modules/java-ee-8-security-api/app-auth-custom-form-store-custom/src/main/liberty/config/server.xml diff --git a/java-ee-8-security-api/app-auth-custom-form-store-custom/src/main/resources/logback.xml b/security-modules/java-ee-8-security-api/app-auth-custom-form-store-custom/src/main/resources/logback.xml similarity index 100% rename from java-ee-8-security-api/app-auth-custom-form-store-custom/src/main/resources/logback.xml rename to security-modules/java-ee-8-security-api/app-auth-custom-form-store-custom/src/main/resources/logback.xml diff --git a/java-ee-8-security-api/app-auth-custom-form-store-custom/src/main/webapp/WEB-INF/beans.xml b/security-modules/java-ee-8-security-api/app-auth-custom-form-store-custom/src/main/webapp/WEB-INF/beans.xml similarity index 100% rename from java-ee-8-security-api/app-auth-custom-form-store-custom/src/main/webapp/WEB-INF/beans.xml rename to security-modules/java-ee-8-security-api/app-auth-custom-form-store-custom/src/main/webapp/WEB-INF/beans.xml diff --git a/java-ee-8-security-api/app-auth-custom-form-store-custom/src/main/webapp/WEB-INF/web.xml b/security-modules/java-ee-8-security-api/app-auth-custom-form-store-custom/src/main/webapp/WEB-INF/web.xml similarity index 100% rename from java-ee-8-security-api/app-auth-custom-form-store-custom/src/main/webapp/WEB-INF/web.xml rename to security-modules/java-ee-8-security-api/app-auth-custom-form-store-custom/src/main/webapp/WEB-INF/web.xml diff --git a/java-ee-8-security-api/app-auth-custom-form-store-custom/src/main/webapp/login-error.html b/security-modules/java-ee-8-security-api/app-auth-custom-form-store-custom/src/main/webapp/login-error.html similarity index 100% rename from java-ee-8-security-api/app-auth-custom-form-store-custom/src/main/webapp/login-error.html rename to security-modules/java-ee-8-security-api/app-auth-custom-form-store-custom/src/main/webapp/login-error.html diff --git a/java-ee-8-security-api/app-auth-custom-form-store-custom/src/main/webapp/login.xhtml b/security-modules/java-ee-8-security-api/app-auth-custom-form-store-custom/src/main/webapp/login.xhtml similarity index 100% rename from java-ee-8-security-api/app-auth-custom-form-store-custom/src/main/webapp/login.xhtml rename to security-modules/java-ee-8-security-api/app-auth-custom-form-store-custom/src/main/webapp/login.xhtml diff --git a/java-ee-8-security-api/app-auth-custom-form-store-custom/src/main/webapp/welcome.xhtml b/security-modules/java-ee-8-security-api/app-auth-custom-form-store-custom/src/main/webapp/welcome.xhtml similarity index 100% rename from java-ee-8-security-api/app-auth-custom-form-store-custom/src/main/webapp/welcome.xhtml rename to security-modules/java-ee-8-security-api/app-auth-custom-form-store-custom/src/main/webapp/welcome.xhtml diff --git a/java-ee-8-security-api/app-auth-custom-no-store/pom.xml b/security-modules/java-ee-8-security-api/app-auth-custom-no-store/pom.xml similarity index 100% rename from java-ee-8-security-api/app-auth-custom-no-store/pom.xml rename to security-modules/java-ee-8-security-api/app-auth-custom-no-store/pom.xml diff --git a/java-ee-8-security-api/app-auth-custom-no-store/src/main/java/com/baeldung/javaee/security/AdminServlet.java b/security-modules/java-ee-8-security-api/app-auth-custom-no-store/src/main/java/com/baeldung/javaee/security/AdminServlet.java similarity index 100% rename from java-ee-8-security-api/app-auth-custom-no-store/src/main/java/com/baeldung/javaee/security/AdminServlet.java rename to security-modules/java-ee-8-security-api/app-auth-custom-no-store/src/main/java/com/baeldung/javaee/security/AdminServlet.java diff --git a/java-ee-8-security-api/app-auth-custom-no-store/src/main/java/com/baeldung/javaee/security/AppConfig.java b/security-modules/java-ee-8-security-api/app-auth-custom-no-store/src/main/java/com/baeldung/javaee/security/AppConfig.java similarity index 100% rename from java-ee-8-security-api/app-auth-custom-no-store/src/main/java/com/baeldung/javaee/security/AppConfig.java rename to security-modules/java-ee-8-security-api/app-auth-custom-no-store/src/main/java/com/baeldung/javaee/security/AppConfig.java diff --git a/java-ee-8-security-api/app-auth-custom-no-store/src/main/java/com/baeldung/javaee/security/CustomAuthentication.java b/security-modules/java-ee-8-security-api/app-auth-custom-no-store/src/main/java/com/baeldung/javaee/security/CustomAuthentication.java similarity index 100% rename from java-ee-8-security-api/app-auth-custom-no-store/src/main/java/com/baeldung/javaee/security/CustomAuthentication.java rename to security-modules/java-ee-8-security-api/app-auth-custom-no-store/src/main/java/com/baeldung/javaee/security/CustomAuthentication.java diff --git a/java-ee-8-security-api/app-auth-custom-no-store/src/main/java/com/baeldung/javaee/security/CustomPrincipal.java b/security-modules/java-ee-8-security-api/app-auth-custom-no-store/src/main/java/com/baeldung/javaee/security/CustomPrincipal.java similarity index 100% rename from java-ee-8-security-api/app-auth-custom-no-store/src/main/java/com/baeldung/javaee/security/CustomPrincipal.java rename to security-modules/java-ee-8-security-api/app-auth-custom-no-store/src/main/java/com/baeldung/javaee/security/CustomPrincipal.java diff --git a/java-ee-8-security-api/app-auth-custom-no-store/src/main/java/com/baeldung/javaee/security/UserDetail.java b/security-modules/java-ee-8-security-api/app-auth-custom-no-store/src/main/java/com/baeldung/javaee/security/UserDetail.java similarity index 100% rename from java-ee-8-security-api/app-auth-custom-no-store/src/main/java/com/baeldung/javaee/security/UserDetail.java rename to security-modules/java-ee-8-security-api/app-auth-custom-no-store/src/main/java/com/baeldung/javaee/security/UserDetail.java diff --git a/java-ee-8-security-api/app-auth-custom-no-store/src/main/liberty/config/server.xml b/security-modules/java-ee-8-security-api/app-auth-custom-no-store/src/main/liberty/config/server.xml similarity index 100% rename from java-ee-8-security-api/app-auth-custom-no-store/src/main/liberty/config/server.xml rename to security-modules/java-ee-8-security-api/app-auth-custom-no-store/src/main/liberty/config/server.xml diff --git a/java-ee-8-security-api/app-auth-custom-no-store/src/main/resources/logback.xml b/security-modules/java-ee-8-security-api/app-auth-custom-no-store/src/main/resources/logback.xml similarity index 100% rename from java-ee-8-security-api/app-auth-custom-no-store/src/main/resources/logback.xml rename to security-modules/java-ee-8-security-api/app-auth-custom-no-store/src/main/resources/logback.xml diff --git a/java-ee-8-security-api/app-auth-custom-no-store/src/main/webapp/login-error.html b/security-modules/java-ee-8-security-api/app-auth-custom-no-store/src/main/webapp/login-error.html similarity index 100% rename from java-ee-8-security-api/app-auth-custom-no-store/src/main/webapp/login-error.html rename to security-modules/java-ee-8-security-api/app-auth-custom-no-store/src/main/webapp/login-error.html diff --git a/java-ee-8-security-api/app-auth-custom-no-store/src/main/webapp/login.html b/security-modules/java-ee-8-security-api/app-auth-custom-no-store/src/main/webapp/login.html similarity index 100% rename from java-ee-8-security-api/app-auth-custom-no-store/src/main/webapp/login.html rename to security-modules/java-ee-8-security-api/app-auth-custom-no-store/src/main/webapp/login.html diff --git a/java-ee-8-security-api/app-auth-form-store-ldap/pom.xml b/security-modules/java-ee-8-security-api/app-auth-form-store-ldap/pom.xml similarity index 100% rename from java-ee-8-security-api/app-auth-form-store-ldap/pom.xml rename to security-modules/java-ee-8-security-api/app-auth-form-store-ldap/pom.xml diff --git a/java-ee-8-security-api/app-auth-form-store-ldap/src/main/java/com/baeldung/javaee/security/AdminServlet.java b/security-modules/java-ee-8-security-api/app-auth-form-store-ldap/src/main/java/com/baeldung/javaee/security/AdminServlet.java similarity index 100% rename from java-ee-8-security-api/app-auth-form-store-ldap/src/main/java/com/baeldung/javaee/security/AdminServlet.java rename to security-modules/java-ee-8-security-api/app-auth-form-store-ldap/src/main/java/com/baeldung/javaee/security/AdminServlet.java diff --git a/java-ee-8-security-api/app-auth-form-store-ldap/src/main/java/com/baeldung/javaee/security/AppConfig.java b/security-modules/java-ee-8-security-api/app-auth-form-store-ldap/src/main/java/com/baeldung/javaee/security/AppConfig.java similarity index 100% rename from java-ee-8-security-api/app-auth-form-store-ldap/src/main/java/com/baeldung/javaee/security/AppConfig.java rename to security-modules/java-ee-8-security-api/app-auth-form-store-ldap/src/main/java/com/baeldung/javaee/security/AppConfig.java diff --git a/java-ee-8-security-api/app-auth-form-store-ldap/src/main/java/com/baeldung/javaee/security/LdapSetupServlet.java b/security-modules/java-ee-8-security-api/app-auth-form-store-ldap/src/main/java/com/baeldung/javaee/security/LdapSetupServlet.java similarity index 100% rename from java-ee-8-security-api/app-auth-form-store-ldap/src/main/java/com/baeldung/javaee/security/LdapSetupServlet.java rename to security-modules/java-ee-8-security-api/app-auth-form-store-ldap/src/main/java/com/baeldung/javaee/security/LdapSetupServlet.java diff --git a/java-ee-8-security-api/app-auth-form-store-ldap/src/main/java/com/baeldung/javaee/security/UserServlet.java b/security-modules/java-ee-8-security-api/app-auth-form-store-ldap/src/main/java/com/baeldung/javaee/security/UserServlet.java similarity index 100% rename from java-ee-8-security-api/app-auth-form-store-ldap/src/main/java/com/baeldung/javaee/security/UserServlet.java rename to security-modules/java-ee-8-security-api/app-auth-form-store-ldap/src/main/java/com/baeldung/javaee/security/UserServlet.java diff --git a/java-ee-8-security-api/app-auth-form-store-ldap/src/main/liberty/config/server.xml b/security-modules/java-ee-8-security-api/app-auth-form-store-ldap/src/main/liberty/config/server.xml similarity index 100% rename from java-ee-8-security-api/app-auth-form-store-ldap/src/main/liberty/config/server.xml rename to security-modules/java-ee-8-security-api/app-auth-form-store-ldap/src/main/liberty/config/server.xml diff --git a/java-ee-8-security-api/app-auth-form-store-ldap/src/main/resources/logback.xml b/security-modules/java-ee-8-security-api/app-auth-form-store-ldap/src/main/resources/logback.xml similarity index 100% rename from java-ee-8-security-api/app-auth-form-store-ldap/src/main/resources/logback.xml rename to security-modules/java-ee-8-security-api/app-auth-form-store-ldap/src/main/resources/logback.xml diff --git a/java-ee-8-security-api/app-auth-form-store-ldap/src/main/resources/users.ldif b/security-modules/java-ee-8-security-api/app-auth-form-store-ldap/src/main/resources/users.ldif similarity index 100% rename from java-ee-8-security-api/app-auth-form-store-ldap/src/main/resources/users.ldif rename to security-modules/java-ee-8-security-api/app-auth-form-store-ldap/src/main/resources/users.ldif diff --git a/java-ee-8-security-api/app-auth-form-store-ldap/src/main/webapp/login-error.html b/security-modules/java-ee-8-security-api/app-auth-form-store-ldap/src/main/webapp/login-error.html similarity index 100% rename from java-ee-8-security-api/app-auth-form-store-ldap/src/main/webapp/login-error.html rename to security-modules/java-ee-8-security-api/app-auth-form-store-ldap/src/main/webapp/login-error.html diff --git a/java-ee-8-security-api/app-auth-form-store-ldap/src/main/webapp/login.html b/security-modules/java-ee-8-security-api/app-auth-form-store-ldap/src/main/webapp/login.html similarity index 100% rename from java-ee-8-security-api/app-auth-form-store-ldap/src/main/webapp/login.html rename to security-modules/java-ee-8-security-api/app-auth-form-store-ldap/src/main/webapp/login.html diff --git a/java-ee-8-security-api/pom.xml b/security-modules/java-ee-8-security-api/pom.xml similarity index 98% rename from java-ee-8-security-api/pom.xml rename to security-modules/java-ee-8-security-api/pom.xml index c01bedbeee..bcd15ed685 100644 --- a/java-ee-8-security-api/pom.xml +++ b/security-modules/java-ee-8-security-api/pom.xml @@ -10,7 +10,7 @@ com.baeldung - parent-modules + security-modules 1.0.0-SNAPSHOT diff --git a/jee-7-security/README.md b/security-modules/jee-7-security/README.md similarity index 100% rename from jee-7-security/README.md rename to security-modules/jee-7-security/README.md diff --git a/jee-7-security/pom.xml b/security-modules/jee-7-security/pom.xml similarity index 97% rename from jee-7-security/pom.xml rename to security-modules/jee-7-security/pom.xml index a8ceee8704..71084d6cd1 100644 --- a/jee-7-security/pom.xml +++ b/security-modules/jee-7-security/pom.xml @@ -11,7 +11,7 @@ com.baeldung - parent-modules + security-modules 1.0.0-SNAPSHOT diff --git a/jee-7-security/src/main/java/com/baeldung/springsecurity/SecurityWebApplicationInitializer.java b/security-modules/jee-7-security/src/main/java/com/baeldung/springsecurity/SecurityWebApplicationInitializer.java similarity index 100% rename from jee-7-security/src/main/java/com/baeldung/springsecurity/SecurityWebApplicationInitializer.java rename to security-modules/jee-7-security/src/main/java/com/baeldung/springsecurity/SecurityWebApplicationInitializer.java diff --git a/jee-7-security/src/main/java/com/baeldung/springsecurity/SpringSecurityConfig.java b/security-modules/jee-7-security/src/main/java/com/baeldung/springsecurity/SpringSecurityConfig.java similarity index 100% rename from jee-7-security/src/main/java/com/baeldung/springsecurity/SpringSecurityConfig.java rename to security-modules/jee-7-security/src/main/java/com/baeldung/springsecurity/SpringSecurityConfig.java diff --git a/jee-7-security/src/main/java/com/baeldung/springsecurity/controller/HomeController.java b/security-modules/jee-7-security/src/main/java/com/baeldung/springsecurity/controller/HomeController.java similarity index 100% rename from jee-7-security/src/main/java/com/baeldung/springsecurity/controller/HomeController.java rename to security-modules/jee-7-security/src/main/java/com/baeldung/springsecurity/controller/HomeController.java diff --git a/jee-7-security/src/main/java/com/baeldung/springsecurity/controller/LoginController.java b/security-modules/jee-7-security/src/main/java/com/baeldung/springsecurity/controller/LoginController.java similarity index 100% rename from jee-7-security/src/main/java/com/baeldung/springsecurity/controller/LoginController.java rename to security-modules/jee-7-security/src/main/java/com/baeldung/springsecurity/controller/LoginController.java diff --git a/jee-7-security/src/main/resources/logback.xml b/security-modules/jee-7-security/src/main/resources/logback.xml similarity index 100% rename from jee-7-security/src/main/resources/logback.xml rename to security-modules/jee-7-security/src/main/resources/logback.xml diff --git a/jee-7-security/src/main/webapp/WEB-INF/beans.xml b/security-modules/jee-7-security/src/main/webapp/WEB-INF/beans.xml similarity index 100% rename from jee-7-security/src/main/webapp/WEB-INF/beans.xml rename to security-modules/jee-7-security/src/main/webapp/WEB-INF/beans.xml diff --git a/jee-7-security/src/main/webapp/WEB-INF/faces-config.xml b/security-modules/jee-7-security/src/main/webapp/WEB-INF/faces-config.xml similarity index 100% rename from jee-7-security/src/main/webapp/WEB-INF/faces-config.xml rename to security-modules/jee-7-security/src/main/webapp/WEB-INF/faces-config.xml diff --git a/jee-7-security/src/main/webapp/WEB-INF/spring/security.xml b/security-modules/jee-7-security/src/main/webapp/WEB-INF/spring/security.xml similarity index 100% rename from jee-7-security/src/main/webapp/WEB-INF/spring/security.xml rename to security-modules/jee-7-security/src/main/webapp/WEB-INF/spring/security.xml diff --git a/jee-7-security/src/main/webapp/WEB-INF/views/admin.jsp b/security-modules/jee-7-security/src/main/webapp/WEB-INF/views/admin.jsp similarity index 100% rename from jee-7-security/src/main/webapp/WEB-INF/views/admin.jsp rename to security-modules/jee-7-security/src/main/webapp/WEB-INF/views/admin.jsp diff --git a/jee-7-security/src/main/webapp/WEB-INF/views/home.jsp b/security-modules/jee-7-security/src/main/webapp/WEB-INF/views/home.jsp similarity index 100% rename from jee-7-security/src/main/webapp/WEB-INF/views/home.jsp rename to security-modules/jee-7-security/src/main/webapp/WEB-INF/views/home.jsp diff --git a/jee-7-security/src/main/webapp/WEB-INF/views/login.jsp b/security-modules/jee-7-security/src/main/webapp/WEB-INF/views/login.jsp similarity index 100% rename from jee-7-security/src/main/webapp/WEB-INF/views/login.jsp rename to security-modules/jee-7-security/src/main/webapp/WEB-INF/views/login.jsp diff --git a/jee-7-security/src/main/webapp/WEB-INF/views/user.jsp b/security-modules/jee-7-security/src/main/webapp/WEB-INF/views/user.jsp similarity index 100% rename from jee-7-security/src/main/webapp/WEB-INF/views/user.jsp rename to security-modules/jee-7-security/src/main/webapp/WEB-INF/views/user.jsp diff --git a/jee-7-security/src/main/webapp/WEB-INF/web.xml b/security-modules/jee-7-security/src/main/webapp/WEB-INF/web.xml similarity index 100% rename from jee-7-security/src/main/webapp/WEB-INF/web.xml rename to security-modules/jee-7-security/src/main/webapp/WEB-INF/web.xml diff --git a/jee-7-security/src/main/webapp/index.jsp b/security-modules/jee-7-security/src/main/webapp/index.jsp similarity index 100% rename from jee-7-security/src/main/webapp/index.jsp rename to security-modules/jee-7-security/src/main/webapp/index.jsp diff --git a/jee-7-security/src/main/webapp/secure.jsp b/security-modules/jee-7-security/src/main/webapp/secure.jsp similarity index 100% rename from jee-7-security/src/main/webapp/secure.jsp rename to security-modules/jee-7-security/src/main/webapp/secure.jsp diff --git a/jjwt/.gitignore b/security-modules/jjwt/.gitignore similarity index 100% rename from jjwt/.gitignore rename to security-modules/jjwt/.gitignore diff --git a/jjwt/README.md b/security-modules/jjwt/README.md similarity index 100% rename from jjwt/README.md rename to security-modules/jjwt/README.md diff --git a/jjwt/pom.xml b/security-modules/jjwt/pom.xml similarity index 96% rename from jjwt/pom.xml rename to security-modules/jjwt/pom.xml index cc169ba9fc..3ea4a46b8a 100644 --- a/jjwt/pom.xml +++ b/security-modules/jjwt/pom.xml @@ -13,7 +13,7 @@ com.baeldung parent-boot-2 0.0.1-SNAPSHOT - ../parent-boot-2 + ../../parent-boot-2 diff --git a/jjwt/src/main/java/io/jsonwebtoken/jjwtfun/JJWTFunApplication.java b/security-modules/jjwt/src/main/java/io/jsonwebtoken/jjwtfun/JJWTFunApplication.java similarity index 100% rename from jjwt/src/main/java/io/jsonwebtoken/jjwtfun/JJWTFunApplication.java rename to security-modules/jjwt/src/main/java/io/jsonwebtoken/jjwtfun/JJWTFunApplication.java diff --git a/jjwt/src/main/java/io/jsonwebtoken/jjwtfun/config/CSRFConfig.java b/security-modules/jjwt/src/main/java/io/jsonwebtoken/jjwtfun/config/CSRFConfig.java similarity index 100% rename from jjwt/src/main/java/io/jsonwebtoken/jjwtfun/config/CSRFConfig.java rename to security-modules/jjwt/src/main/java/io/jsonwebtoken/jjwtfun/config/CSRFConfig.java diff --git a/jjwt/src/main/java/io/jsonwebtoken/jjwtfun/config/JWTCsrfTokenRepository.java b/security-modules/jjwt/src/main/java/io/jsonwebtoken/jjwtfun/config/JWTCsrfTokenRepository.java similarity index 100% rename from jjwt/src/main/java/io/jsonwebtoken/jjwtfun/config/JWTCsrfTokenRepository.java rename to security-modules/jjwt/src/main/java/io/jsonwebtoken/jjwtfun/config/JWTCsrfTokenRepository.java diff --git a/jjwt/src/main/java/io/jsonwebtoken/jjwtfun/config/WebSecurityConfig.java b/security-modules/jjwt/src/main/java/io/jsonwebtoken/jjwtfun/config/WebSecurityConfig.java similarity index 100% rename from jjwt/src/main/java/io/jsonwebtoken/jjwtfun/config/WebSecurityConfig.java rename to security-modules/jjwt/src/main/java/io/jsonwebtoken/jjwtfun/config/WebSecurityConfig.java diff --git a/jjwt/src/main/java/io/jsonwebtoken/jjwtfun/controller/BaseController.java b/security-modules/jjwt/src/main/java/io/jsonwebtoken/jjwtfun/controller/BaseController.java similarity index 100% rename from jjwt/src/main/java/io/jsonwebtoken/jjwtfun/controller/BaseController.java rename to security-modules/jjwt/src/main/java/io/jsonwebtoken/jjwtfun/controller/BaseController.java diff --git a/jjwt/src/main/java/io/jsonwebtoken/jjwtfun/controller/DynamicJWTController.java b/security-modules/jjwt/src/main/java/io/jsonwebtoken/jjwtfun/controller/DynamicJWTController.java similarity index 100% rename from jjwt/src/main/java/io/jsonwebtoken/jjwtfun/controller/DynamicJWTController.java rename to security-modules/jjwt/src/main/java/io/jsonwebtoken/jjwtfun/controller/DynamicJWTController.java diff --git a/jjwt/src/main/java/io/jsonwebtoken/jjwtfun/controller/FormController.java b/security-modules/jjwt/src/main/java/io/jsonwebtoken/jjwtfun/controller/FormController.java similarity index 100% rename from jjwt/src/main/java/io/jsonwebtoken/jjwtfun/controller/FormController.java rename to security-modules/jjwt/src/main/java/io/jsonwebtoken/jjwtfun/controller/FormController.java diff --git a/jjwt/src/main/java/io/jsonwebtoken/jjwtfun/controller/HomeController.java b/security-modules/jjwt/src/main/java/io/jsonwebtoken/jjwtfun/controller/HomeController.java similarity index 100% rename from jjwt/src/main/java/io/jsonwebtoken/jjwtfun/controller/HomeController.java rename to security-modules/jjwt/src/main/java/io/jsonwebtoken/jjwtfun/controller/HomeController.java diff --git a/jjwt/src/main/java/io/jsonwebtoken/jjwtfun/controller/SecretsController.java b/security-modules/jjwt/src/main/java/io/jsonwebtoken/jjwtfun/controller/SecretsController.java similarity index 100% rename from jjwt/src/main/java/io/jsonwebtoken/jjwtfun/controller/SecretsController.java rename to security-modules/jjwt/src/main/java/io/jsonwebtoken/jjwtfun/controller/SecretsController.java diff --git a/jjwt/src/main/java/io/jsonwebtoken/jjwtfun/controller/StaticJWTController.java b/security-modules/jjwt/src/main/java/io/jsonwebtoken/jjwtfun/controller/StaticJWTController.java similarity index 100% rename from jjwt/src/main/java/io/jsonwebtoken/jjwtfun/controller/StaticJWTController.java rename to security-modules/jjwt/src/main/java/io/jsonwebtoken/jjwtfun/controller/StaticJWTController.java diff --git a/jjwt/src/main/java/io/jsonwebtoken/jjwtfun/model/JwtResponse.java b/security-modules/jjwt/src/main/java/io/jsonwebtoken/jjwtfun/model/JwtResponse.java similarity index 100% rename from jjwt/src/main/java/io/jsonwebtoken/jjwtfun/model/JwtResponse.java rename to security-modules/jjwt/src/main/java/io/jsonwebtoken/jjwtfun/model/JwtResponse.java diff --git a/jjwt/src/main/java/io/jsonwebtoken/jjwtfun/service/SecretService.java b/security-modules/jjwt/src/main/java/io/jsonwebtoken/jjwtfun/service/SecretService.java similarity index 100% rename from jjwt/src/main/java/io/jsonwebtoken/jjwtfun/service/SecretService.java rename to security-modules/jjwt/src/main/java/io/jsonwebtoken/jjwtfun/service/SecretService.java diff --git a/jjwt/src/main/java/io/jsonwebtoken/jjwtfun/util/JWTDecoderUtil.java b/security-modules/jjwt/src/main/java/io/jsonwebtoken/jjwtfun/util/JWTDecoderUtil.java similarity index 100% rename from jjwt/src/main/java/io/jsonwebtoken/jjwtfun/util/JWTDecoderUtil.java rename to security-modules/jjwt/src/main/java/io/jsonwebtoken/jjwtfun/util/JWTDecoderUtil.java diff --git a/jjwt/src/main/resources/application.properties b/security-modules/jjwt/src/main/resources/application.properties similarity index 100% rename from jjwt/src/main/resources/application.properties rename to security-modules/jjwt/src/main/resources/application.properties diff --git a/jjwt/src/main/resources/logback.xml b/security-modules/jjwt/src/main/resources/logback.xml similarity index 100% rename from jjwt/src/main/resources/logback.xml rename to security-modules/jjwt/src/main/resources/logback.xml diff --git a/jjwt/src/main/resources/templates/expired-jwt.html b/security-modules/jjwt/src/main/resources/templates/expired-jwt.html similarity index 100% rename from jjwt/src/main/resources/templates/expired-jwt.html rename to security-modules/jjwt/src/main/resources/templates/expired-jwt.html diff --git a/jjwt/src/main/resources/templates/fragments/head.html b/security-modules/jjwt/src/main/resources/templates/fragments/head.html similarity index 100% rename from jjwt/src/main/resources/templates/fragments/head.html rename to security-modules/jjwt/src/main/resources/templates/fragments/head.html diff --git a/jjwt/src/main/resources/templates/jwt-csrf-form-result.html b/security-modules/jjwt/src/main/resources/templates/jwt-csrf-form-result.html similarity index 100% rename from jjwt/src/main/resources/templates/jwt-csrf-form-result.html rename to security-modules/jjwt/src/main/resources/templates/jwt-csrf-form-result.html diff --git a/jjwt/src/main/resources/templates/jwt-csrf-form.html b/security-modules/jjwt/src/main/resources/templates/jwt-csrf-form.html similarity index 100% rename from jjwt/src/main/resources/templates/jwt-csrf-form.html rename to security-modules/jjwt/src/main/resources/templates/jwt-csrf-form.html diff --git a/jjwt/src/test/java/io/jsonwebtoken/jjwtfun/DemoApplicationIntegrationTest.java b/security-modules/jjwt/src/test/java/io/jsonwebtoken/jjwtfun/DemoApplicationIntegrationTest.java similarity index 100% rename from jjwt/src/test/java/io/jsonwebtoken/jjwtfun/DemoApplicationIntegrationTest.java rename to security-modules/jjwt/src/test/java/io/jsonwebtoken/jjwtfun/DemoApplicationIntegrationTest.java diff --git a/jjwt/src/test/java/io/jsonwebtoken/jjwtfun/util/JWTDecoderUtilUnitTest.java b/security-modules/jjwt/src/test/java/io/jsonwebtoken/jjwtfun/util/JWTDecoderUtilUnitTest.java similarity index 100% rename from jjwt/src/test/java/io/jsonwebtoken/jjwtfun/util/JWTDecoderUtilUnitTest.java rename to security-modules/jjwt/src/test/java/io/jsonwebtoken/jjwtfun/util/JWTDecoderUtilUnitTest.java diff --git a/oauth2-framework-impl/README.md b/security-modules/oauth2-framework-impl/README.md similarity index 100% rename from oauth2-framework-impl/README.md rename to security-modules/oauth2-framework-impl/README.md diff --git a/oauth2-framework-impl/oauth2-authorization-server/pom.xml b/security-modules/oauth2-framework-impl/oauth2-authorization-server/pom.xml similarity index 100% rename from oauth2-framework-impl/oauth2-authorization-server/pom.xml rename to security-modules/oauth2-framework-impl/oauth2-authorization-server/pom.xml diff --git a/oauth2-framework-impl/oauth2-authorization-server/src/main/java/com/baeldung/oauth2/authorization/server/OAuth2ServerApplication.java b/security-modules/oauth2-framework-impl/oauth2-authorization-server/src/main/java/com/baeldung/oauth2/authorization/server/OAuth2ServerApplication.java similarity index 100% rename from oauth2-framework-impl/oauth2-authorization-server/src/main/java/com/baeldung/oauth2/authorization/server/OAuth2ServerApplication.java rename to security-modules/oauth2-framework-impl/oauth2-authorization-server/src/main/java/com/baeldung/oauth2/authorization/server/OAuth2ServerApplication.java diff --git a/oauth2-framework-impl/oauth2-authorization-server/src/main/java/com/baeldung/oauth2/authorization/server/PEMKeyUtils.java b/security-modules/oauth2-framework-impl/oauth2-authorization-server/src/main/java/com/baeldung/oauth2/authorization/server/PEMKeyUtils.java similarity index 96% rename from oauth2-framework-impl/oauth2-authorization-server/src/main/java/com/baeldung/oauth2/authorization/server/PEMKeyUtils.java rename to security-modules/oauth2-framework-impl/oauth2-authorization-server/src/main/java/com/baeldung/oauth2/authorization/server/PEMKeyUtils.java index dab57b91a7..3947874179 100644 --- a/oauth2-framework-impl/oauth2-authorization-server/src/main/java/com/baeldung/oauth2/authorization/server/PEMKeyUtils.java +++ b/security-modules/oauth2-framework-impl/oauth2-authorization-server/src/main/java/com/baeldung/oauth2/authorization/server/PEMKeyUtils.java @@ -1,17 +1,17 @@ -package com.baeldung.oauth2.authorization.server; - -import java.net.URI; -import java.nio.file.Files; -import java.nio.file.Paths; - -import static java.lang.Thread.currentThread; - - -public class PEMKeyUtils { - - public static String readKeyAsString(String keyLocation) throws Exception { - URI uri = currentThread().getContextClassLoader().getResource(keyLocation).toURI(); - byte[] byteArray = Files.readAllBytes(Paths.get(uri)); - return new String(byteArray); - } -} +package com.baeldung.oauth2.authorization.server; + +import java.net.URI; +import java.nio.file.Files; +import java.nio.file.Paths; + +import static java.lang.Thread.currentThread; + + +public class PEMKeyUtils { + + public static String readKeyAsString(String keyLocation) throws Exception { + URI uri = currentThread().getContextClassLoader().getResource(keyLocation).toURI(); + byte[] byteArray = Files.readAllBytes(Paths.get(uri)); + return new String(byteArray); + } +} diff --git a/oauth2-framework-impl/oauth2-authorization-server/src/main/java/com/baeldung/oauth2/authorization/server/api/AuthorizationEndpoint.java b/security-modules/oauth2-framework-impl/oauth2-authorization-server/src/main/java/com/baeldung/oauth2/authorization/server/api/AuthorizationEndpoint.java similarity index 97% rename from oauth2-framework-impl/oauth2-authorization-server/src/main/java/com/baeldung/oauth2/authorization/server/api/AuthorizationEndpoint.java rename to security-modules/oauth2-framework-impl/oauth2-authorization-server/src/main/java/com/baeldung/oauth2/authorization/server/api/AuthorizationEndpoint.java index ba5e1ec359..618363c7e1 100644 --- a/oauth2-framework-impl/oauth2-authorization-server/src/main/java/com/baeldung/oauth2/authorization/server/api/AuthorizationEndpoint.java +++ b/security-modules/oauth2-framework-impl/oauth2-authorization-server/src/main/java/com/baeldung/oauth2/authorization/server/api/AuthorizationEndpoint.java @@ -1,185 +1,185 @@ -package com.baeldung.oauth2.authorization.server.api; - -import com.baeldung.oauth2.authorization.server.handler.AuthorizationGrantTypeHandler; -import com.baeldung.oauth2.authorization.server.model.AppDataRepository; -import com.baeldung.oauth2.authorization.server.model.AuthorizationCode; -import com.baeldung.oauth2.authorization.server.model.Client; -import com.baeldung.oauth2.authorization.server.model.User; - -import javax.annotation.security.RolesAllowed; -import javax.enterprise.context.RequestScoped; -import javax.enterprise.inject.Instance; -import javax.enterprise.inject.literal.NamedLiteral; -import javax.inject.Inject; -import javax.json.JsonObject; -import javax.security.enterprise.SecurityContext; -import javax.security.enterprise.authentication.mechanism.http.FormAuthenticationMechanismDefinition; -import javax.security.enterprise.authentication.mechanism.http.LoginToContinue; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.ws.rs.*; -import javax.ws.rs.core.*; -import java.io.IOException; -import java.net.URI; -import java.security.Principal; -import java.time.LocalDateTime; -import java.util.*; - -@FormAuthenticationMechanismDefinition( - loginToContinue = @LoginToContinue(loginPage = "/login.jsp", errorPage = "/login.jsp") -) -@RolesAllowed("USER") -@RequestScoped -@Path("authorize") -public class AuthorizationEndpoint { - - @Inject - private SecurityContext securityContext; - - @Inject - private AppDataRepository appDataRepository; - - @Inject - Instance authorizationGrantTypeHandlers; - - @GET - @Produces(MediaType.TEXT_HTML) - public Response doGet(@Context HttpServletRequest request, - @Context HttpServletResponse response, - @Context UriInfo uriInfo) throws ServletException, IOException { - MultivaluedMap params = uriInfo.getQueryParameters(); - Principal principal = securityContext.getCallerPrincipal(); - - //error about redirect_uri && client_id ==> forward user, thus to error.jsp. - //otherwise ==> sendRedirect redirect_uri?error=error&error_description=error_description - //1. client_id - String clientId = params.getFirst("client_id"); - if (clientId == null || clientId.isEmpty()) { - return informUserAboutError(request, response, "Invalid client_id :" + clientId); - } - Client client = appDataRepository.getClient(clientId); - if (client == null) { - return informUserAboutError(request, response, "Invalid client_id :" + clientId); - } - //2. Client Authorized Grant Type - String clientError = ""; - if (client.getAuthorizedGrantTypes() != null && !client.getAuthorizedGrantTypes().contains("authorization_code")) { - return informUserAboutError(request, response, "Authorization Grant type, authorization_code, is not allowed for this client :" + clientId); - } - - //3. redirectUri - String redirectUri = params.getFirst("redirect_uri"); - if (client.getRedirectUri() != null && !client.getRedirectUri().isEmpty()) { - if (redirectUri != null && !redirectUri.isEmpty() && !client.getRedirectUri().equals(redirectUri)) { - //sould be in the client.redirectUri - return informUserAboutError(request, response, "redirect_uri is pre-registred and should match"); - } - redirectUri = client.getRedirectUri(); - params.putSingle("resolved_redirect_uri", redirectUri); - } else { - if (redirectUri == null || redirectUri.isEmpty()) { - return informUserAboutError(request, response, "redirect_uri is not pre-registred and should be provided"); - } - params.putSingle("resolved_redirect_uri", redirectUri); - } - request.setAttribute("client", client); - - //4. response_type - String responseType = params.getFirst("response_type"); - if (!"code".equals(responseType) && !"token".equals(responseType)) { - //error = "invalid_grant :" + responseType + ", response_type params should be code or token:"; - //return informUserAboutError(error); - } - - //Save params in session - request.getSession().setAttribute("ORIGINAL_PARAMS", params); - - //4.scope: Optional - String requestedScope = request.getParameter("scope"); - if (requestedScope == null || requestedScope.isEmpty()) { - requestedScope = client.getScope(); - } - User user = appDataRepository.getUser(principal.getName()); - String allowedScopes = checkUserScopes(user.getScopes(), requestedScope); - request.setAttribute("scopes", allowedScopes); - - request.getRequestDispatcher("/authorize.jsp").forward(request, response); - return null; - } - - @POST - @Consumes(MediaType.APPLICATION_FORM_URLENCODED) - @Produces(MediaType.TEXT_HTML) - public Response doPost(@Context HttpServletRequest request, - @Context HttpServletResponse response, - MultivaluedMap params) throws Exception { - MultivaluedMap originalParams = (MultivaluedMap) request.getSession().getAttribute("ORIGINAL_PARAMS"); - if (originalParams == null) { - return informUserAboutError(request, response, "No pending authorization request."); - } - String redirectUri = originalParams.getFirst("resolved_redirect_uri"); - StringBuilder sb = new StringBuilder(redirectUri); - - String approvalStatus = params.getFirst("approval_status"); - if ("NO".equals(approvalStatus)) { - URI location = UriBuilder.fromUri(sb.toString()) - .queryParam("error", "User doesn't approved the request.") - .queryParam("error_description", "User doesn't approved the request.") - .build(); - return Response.seeOther(location).build(); - } - //==> YES - List approvedScopes = params.get("scope"); - if (approvedScopes == null || approvedScopes.isEmpty()) { - URI location = UriBuilder.fromUri(sb.toString()) - .queryParam("error", "User doesn't approved the request.") - .queryParam("error_description", "User doesn't approved the request.") - .build(); - return Response.seeOther(location).build(); - } - - String responseType = originalParams.getFirst("response_type"); - String clientId = originalParams.getFirst("client_id"); - if ("code".equals(responseType)) { - String userId = securityContext.getCallerPrincipal().getName(); - AuthorizationCode authorizationCode = new AuthorizationCode(); - authorizationCode.setClientId(clientId); - authorizationCode.setUserId(userId); - authorizationCode.setApprovedScopes(String.join(" ", approvedScopes)); - authorizationCode.setExpirationDate(LocalDateTime.now().plusMinutes(10)); - authorizationCode.setRedirectUri(redirectUri); - appDataRepository.save(authorizationCode); - String code = authorizationCode.getCode(); - sb.append("?code=").append(code); - } else { - //Implicit: responseType=token - AuthorizationGrantTypeHandler authorizationGrantTypeHandler = authorizationGrantTypeHandlers.select(NamedLiteral.of("implicit")).get(); - JsonObject tokenResponse = authorizationGrantTypeHandler.createAccessToken(clientId, params); - sb.append("#access_token=").append(tokenResponse.getString("access_token")) - .append("&token_type=").append(tokenResponse.getString("token_type")) - .append("&scope=").append(tokenResponse.getString("scope")); - } - String state = originalParams.getFirst("state"); - if (state != null) { - sb.append("&state=").append(state); - } - return Response.seeOther(UriBuilder.fromUri(sb.toString()).build()).build(); - } - - private String checkUserScopes(String userScopes, String requestedScope) { - Set allowedScopes = new LinkedHashSet<>(); - Set rScopes = new HashSet(Arrays.asList(requestedScope.split(" "))); - Set uScopes = new HashSet(Arrays.asList(userScopes.split(" "))); - for (String scope : uScopes) { - if (rScopes.contains(scope)) allowedScopes.add(scope); - } - return String.join(" ", allowedScopes); - } - - private Response informUserAboutError(HttpServletRequest request, HttpServletResponse response, String error) throws ServletException, IOException { - request.setAttribute("error", error); - request.getRequestDispatcher("/error.jsp").forward(request, response); - return null; - } -} +package com.baeldung.oauth2.authorization.server.api; + +import com.baeldung.oauth2.authorization.server.handler.AuthorizationGrantTypeHandler; +import com.baeldung.oauth2.authorization.server.model.AppDataRepository; +import com.baeldung.oauth2.authorization.server.model.AuthorizationCode; +import com.baeldung.oauth2.authorization.server.model.Client; +import com.baeldung.oauth2.authorization.server.model.User; + +import javax.annotation.security.RolesAllowed; +import javax.enterprise.context.RequestScoped; +import javax.enterprise.inject.Instance; +import javax.enterprise.inject.literal.NamedLiteral; +import javax.inject.Inject; +import javax.json.JsonObject; +import javax.security.enterprise.SecurityContext; +import javax.security.enterprise.authentication.mechanism.http.FormAuthenticationMechanismDefinition; +import javax.security.enterprise.authentication.mechanism.http.LoginToContinue; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.ws.rs.*; +import javax.ws.rs.core.*; +import java.io.IOException; +import java.net.URI; +import java.security.Principal; +import java.time.LocalDateTime; +import java.util.*; + +@FormAuthenticationMechanismDefinition( + loginToContinue = @LoginToContinue(loginPage = "/login.jsp", errorPage = "/login.jsp") +) +@RolesAllowed("USER") +@RequestScoped +@Path("authorize") +public class AuthorizationEndpoint { + + @Inject + private SecurityContext securityContext; + + @Inject + private AppDataRepository appDataRepository; + + @Inject + Instance authorizationGrantTypeHandlers; + + @GET + @Produces(MediaType.TEXT_HTML) + public Response doGet(@Context HttpServletRequest request, + @Context HttpServletResponse response, + @Context UriInfo uriInfo) throws ServletException, IOException { + MultivaluedMap params = uriInfo.getQueryParameters(); + Principal principal = securityContext.getCallerPrincipal(); + + //error about redirect_uri && client_id ==> forward user, thus to error.jsp. + //otherwise ==> sendRedirect redirect_uri?error=error&error_description=error_description + //1. client_id + String clientId = params.getFirst("client_id"); + if (clientId == null || clientId.isEmpty()) { + return informUserAboutError(request, response, "Invalid client_id :" + clientId); + } + Client client = appDataRepository.getClient(clientId); + if (client == null) { + return informUserAboutError(request, response, "Invalid client_id :" + clientId); + } + //2. Client Authorized Grant Type + String clientError = ""; + if (client.getAuthorizedGrantTypes() != null && !client.getAuthorizedGrantTypes().contains("authorization_code")) { + return informUserAboutError(request, response, "Authorization Grant type, authorization_code, is not allowed for this client :" + clientId); + } + + //3. redirectUri + String redirectUri = params.getFirst("redirect_uri"); + if (client.getRedirectUri() != null && !client.getRedirectUri().isEmpty()) { + if (redirectUri != null && !redirectUri.isEmpty() && !client.getRedirectUri().equals(redirectUri)) { + //sould be in the client.redirectUri + return informUserAboutError(request, response, "redirect_uri is pre-registred and should match"); + } + redirectUri = client.getRedirectUri(); + params.putSingle("resolved_redirect_uri", redirectUri); + } else { + if (redirectUri == null || redirectUri.isEmpty()) { + return informUserAboutError(request, response, "redirect_uri is not pre-registred and should be provided"); + } + params.putSingle("resolved_redirect_uri", redirectUri); + } + request.setAttribute("client", client); + + //4. response_type + String responseType = params.getFirst("response_type"); + if (!"code".equals(responseType) && !"token".equals(responseType)) { + //error = "invalid_grant :" + responseType + ", response_type params should be code or token:"; + //return informUserAboutError(error); + } + + //Save params in session + request.getSession().setAttribute("ORIGINAL_PARAMS", params); + + //4.scope: Optional + String requestedScope = request.getParameter("scope"); + if (requestedScope == null || requestedScope.isEmpty()) { + requestedScope = client.getScope(); + } + User user = appDataRepository.getUser(principal.getName()); + String allowedScopes = checkUserScopes(user.getScopes(), requestedScope); + request.setAttribute("scopes", allowedScopes); + + request.getRequestDispatcher("/authorize.jsp").forward(request, response); + return null; + } + + @POST + @Consumes(MediaType.APPLICATION_FORM_URLENCODED) + @Produces(MediaType.TEXT_HTML) + public Response doPost(@Context HttpServletRequest request, + @Context HttpServletResponse response, + MultivaluedMap params) throws Exception { + MultivaluedMap originalParams = (MultivaluedMap) request.getSession().getAttribute("ORIGINAL_PARAMS"); + if (originalParams == null) { + return informUserAboutError(request, response, "No pending authorization request."); + } + String redirectUri = originalParams.getFirst("resolved_redirect_uri"); + StringBuilder sb = new StringBuilder(redirectUri); + + String approvalStatus = params.getFirst("approval_status"); + if ("NO".equals(approvalStatus)) { + URI location = UriBuilder.fromUri(sb.toString()) + .queryParam("error", "User doesn't approved the request.") + .queryParam("error_description", "User doesn't approved the request.") + .build(); + return Response.seeOther(location).build(); + } + //==> YES + List approvedScopes = params.get("scope"); + if (approvedScopes == null || approvedScopes.isEmpty()) { + URI location = UriBuilder.fromUri(sb.toString()) + .queryParam("error", "User doesn't approved the request.") + .queryParam("error_description", "User doesn't approved the request.") + .build(); + return Response.seeOther(location).build(); + } + + String responseType = originalParams.getFirst("response_type"); + String clientId = originalParams.getFirst("client_id"); + if ("code".equals(responseType)) { + String userId = securityContext.getCallerPrincipal().getName(); + AuthorizationCode authorizationCode = new AuthorizationCode(); + authorizationCode.setClientId(clientId); + authorizationCode.setUserId(userId); + authorizationCode.setApprovedScopes(String.join(" ", approvedScopes)); + authorizationCode.setExpirationDate(LocalDateTime.now().plusMinutes(10)); + authorizationCode.setRedirectUri(redirectUri); + appDataRepository.save(authorizationCode); + String code = authorizationCode.getCode(); + sb.append("?code=").append(code); + } else { + //Implicit: responseType=token + AuthorizationGrantTypeHandler authorizationGrantTypeHandler = authorizationGrantTypeHandlers.select(NamedLiteral.of("implicit")).get(); + JsonObject tokenResponse = authorizationGrantTypeHandler.createAccessToken(clientId, params); + sb.append("#access_token=").append(tokenResponse.getString("access_token")) + .append("&token_type=").append(tokenResponse.getString("token_type")) + .append("&scope=").append(tokenResponse.getString("scope")); + } + String state = originalParams.getFirst("state"); + if (state != null) { + sb.append("&state=").append(state); + } + return Response.seeOther(UriBuilder.fromUri(sb.toString()).build()).build(); + } + + private String checkUserScopes(String userScopes, String requestedScope) { + Set allowedScopes = new LinkedHashSet<>(); + Set rScopes = new HashSet(Arrays.asList(requestedScope.split(" "))); + Set uScopes = new HashSet(Arrays.asList(userScopes.split(" "))); + for (String scope : uScopes) { + if (rScopes.contains(scope)) allowedScopes.add(scope); + } + return String.join(" ", allowedScopes); + } + + private Response informUserAboutError(HttpServletRequest request, HttpServletResponse response, String error) throws ServletException, IOException { + request.setAttribute("error", error); + request.getRequestDispatcher("/error.jsp").forward(request, response); + return null; + } +} diff --git a/oauth2-framework-impl/oauth2-authorization-server/src/main/java/com/baeldung/oauth2/authorization/server/api/JWKEndpoint.java b/security-modules/oauth2-framework-impl/oauth2-authorization-server/src/main/java/com/baeldung/oauth2/authorization/server/api/JWKEndpoint.java similarity index 97% rename from oauth2-framework-impl/oauth2-authorization-server/src/main/java/com/baeldung/oauth2/authorization/server/api/JWKEndpoint.java rename to security-modules/oauth2-framework-impl/oauth2-authorization-server/src/main/java/com/baeldung/oauth2/authorization/server/api/JWKEndpoint.java index 9d38c823b9..0fbdbb1891 100644 --- a/oauth2-framework-impl/oauth2-authorization-server/src/main/java/com/baeldung/oauth2/authorization/server/api/JWKEndpoint.java +++ b/security-modules/oauth2-framework-impl/oauth2-authorization-server/src/main/java/com/baeldung/oauth2/authorization/server/api/JWKEndpoint.java @@ -1,38 +1,38 @@ -package com.baeldung.oauth2.authorization.server.api; - -import com.baeldung.oauth2.authorization.server.PEMKeyUtils; -import com.nimbusds.jose.jwk.JWK; -import org.eclipse.microprofile.config.Config; - -import javax.enterprise.context.ApplicationScoped; -import javax.inject.Inject; -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import java.util.Arrays; - -@Path("jwk") -@ApplicationScoped -public class JWKEndpoint { - - @Inject - private Config config; - - @GET - public Response getKey(@QueryParam("format") String format) throws Exception { - if (format != null && !Arrays.asList("jwk", "pem").contains(format)) { - return Response.status(Response.Status.BAD_REQUEST).entity("Public Key Format should be : jwk or pem").build(); - } - String verificationkey = config.getValue("verificationkey", String.class); - String pemEncodedRSAPublicKey = PEMKeyUtils.readKeyAsString(verificationkey); - if (format == null || format.equals("jwk")) { - JWK jwk = JWK.parseFromPEMEncodedObjects(pemEncodedRSAPublicKey); - return Response.ok(jwk.toJSONString()).type(MediaType.APPLICATION_JSON).build(); - } else if (format.equals("pem")) { - return Response.ok(pemEncodedRSAPublicKey).build(); - } - return null; - } -} +package com.baeldung.oauth2.authorization.server.api; + +import com.baeldung.oauth2.authorization.server.PEMKeyUtils; +import com.nimbusds.jose.jwk.JWK; +import org.eclipse.microprofile.config.Config; + +import javax.enterprise.context.ApplicationScoped; +import javax.inject.Inject; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import java.util.Arrays; + +@Path("jwk") +@ApplicationScoped +public class JWKEndpoint { + + @Inject + private Config config; + + @GET + public Response getKey(@QueryParam("format") String format) throws Exception { + if (format != null && !Arrays.asList("jwk", "pem").contains(format)) { + return Response.status(Response.Status.BAD_REQUEST).entity("Public Key Format should be : jwk or pem").build(); + } + String verificationkey = config.getValue("verificationkey", String.class); + String pemEncodedRSAPublicKey = PEMKeyUtils.readKeyAsString(verificationkey); + if (format == null || format.equals("jwk")) { + JWK jwk = JWK.parseFromPEMEncodedObjects(pemEncodedRSAPublicKey); + return Response.ok(jwk.toJSONString()).type(MediaType.APPLICATION_JSON).build(); + } else if (format.equals("pem")) { + return Response.ok(pemEncodedRSAPublicKey).build(); + } + return null; + } +} diff --git a/oauth2-framework-impl/oauth2-authorization-server/src/main/java/com/baeldung/oauth2/authorization/server/api/TokenEndpoint.java b/security-modules/oauth2-framework-impl/oauth2-authorization-server/src/main/java/com/baeldung/oauth2/authorization/server/api/TokenEndpoint.java similarity index 100% rename from oauth2-framework-impl/oauth2-authorization-server/src/main/java/com/baeldung/oauth2/authorization/server/api/TokenEndpoint.java rename to security-modules/oauth2-framework-impl/oauth2-authorization-server/src/main/java/com/baeldung/oauth2/authorization/server/api/TokenEndpoint.java diff --git a/oauth2-framework-impl/oauth2-authorization-server/src/main/java/com/baeldung/oauth2/authorization/server/handler/AbstractGrantTypeHandler.java b/security-modules/oauth2-framework-impl/oauth2-authorization-server/src/main/java/com/baeldung/oauth2/authorization/server/handler/AbstractGrantTypeHandler.java similarity index 97% rename from oauth2-framework-impl/oauth2-authorization-server/src/main/java/com/baeldung/oauth2/authorization/server/handler/AbstractGrantTypeHandler.java rename to security-modules/oauth2-framework-impl/oauth2-authorization-server/src/main/java/com/baeldung/oauth2/authorization/server/handler/AbstractGrantTypeHandler.java index 324bacb33f..021ab6bfb8 100644 --- a/oauth2-framework-impl/oauth2-authorization-server/src/main/java/com/baeldung/oauth2/authorization/server/handler/AbstractGrantTypeHandler.java +++ b/security-modules/oauth2-framework-impl/oauth2-authorization-server/src/main/java/com/baeldung/oauth2/authorization/server/handler/AbstractGrantTypeHandler.java @@ -1,87 +1,87 @@ -package com.baeldung.oauth2.authorization.server.handler; - -import com.baeldung.oauth2.authorization.server.PEMKeyUtils; -import com.nimbusds.jose.*; -import com.nimbusds.jose.crypto.RSASSASigner; -import com.nimbusds.jose.crypto.RSASSAVerifier; -import com.nimbusds.jose.jwk.JWK; -import com.nimbusds.jose.jwk.RSAKey; -import com.nimbusds.jwt.JWTClaimsSet; -import com.nimbusds.jwt.SignedJWT; -import org.eclipse.microprofile.config.Config; - -import javax.inject.Inject; -import java.time.Instant; -import java.time.temporal.ChronoUnit; -import java.util.Arrays; -import java.util.Date; -import java.util.UUID; - -public abstract class AbstractGrantTypeHandler implements AuthorizationGrantTypeHandler { - - //Always RSA 256, but could be parametrized - protected JWSHeader jwsHeader = new JWSHeader.Builder(JWSAlgorithm.RS256).type(JOSEObjectType.JWT).build(); - - @Inject - protected Config config; - - //30 min - protected Long expiresInMin = 30L; - - protected JWSVerifier getJWSVerifier() throws Exception { - String verificationkey = config.getValue("verificationkey", String.class); - String pemEncodedRSAPublicKey = PEMKeyUtils.readKeyAsString(verificationkey); - RSAKey rsaPublicKey = (RSAKey) JWK.parseFromPEMEncodedObjects(pemEncodedRSAPublicKey); - return new RSASSAVerifier(rsaPublicKey); - } - - protected JWSSigner getJwsSigner() throws Exception { - String signingkey = config.getValue("signingkey", String.class); - String pemEncodedRSAPrivateKey = PEMKeyUtils.readKeyAsString(signingkey); - RSAKey rsaKey = (RSAKey) JWK.parseFromPEMEncodedObjects(pemEncodedRSAPrivateKey); - return new RSASSASigner(rsaKey.toRSAPrivateKey()); - } - - protected String getAccessToken(String clientId, String subject, String approvedScope) throws Exception { - //4. Signing - JWSSigner jwsSigner = getJwsSigner(); - - Instant now = Instant.now(); - //Long expiresInMin = 30L; - Date expirationTime = Date.from(now.plus(expiresInMin, ChronoUnit.MINUTES)); - - //3. JWT Payload or claims - JWTClaimsSet jwtClaims = new JWTClaimsSet.Builder() - .issuer("http://localhost:9080") - .subject(subject) - .claim("upn", subject) - .claim("client_id", clientId) - .audience("http://localhost:9280") - .claim("scope", approvedScope) - .claim("groups", Arrays.asList(approvedScope.split(" "))) - .expirationTime(expirationTime) // expires in 30 minutes - .notBeforeTime(Date.from(now)) - .issueTime(Date.from(now)) - .jwtID(UUID.randomUUID().toString()) - .build(); - SignedJWT signedJWT = new SignedJWT(jwsHeader, jwtClaims); - signedJWT.sign(jwsSigner); - return signedJWT.serialize(); - } - - protected String getRefreshToken(String clientId, String subject, String approvedScope) throws Exception { - JWSSigner jwsSigner = getJwsSigner(); - Instant now = Instant.now(); - //6.Build refresh token - JWTClaimsSet refreshTokenClaims = new JWTClaimsSet.Builder() - .subject(subject) - .claim("client_id", clientId) - .claim("scope", approvedScope) - //refresh token for 1 day. - .expirationTime(Date.from(now.plus(1, ChronoUnit.DAYS))) - .build(); - SignedJWT signedRefreshToken = new SignedJWT(jwsHeader, refreshTokenClaims); - signedRefreshToken.sign(jwsSigner); - return signedRefreshToken.serialize(); - } -} +package com.baeldung.oauth2.authorization.server.handler; + +import com.baeldung.oauth2.authorization.server.PEMKeyUtils; +import com.nimbusds.jose.*; +import com.nimbusds.jose.crypto.RSASSASigner; +import com.nimbusds.jose.crypto.RSASSAVerifier; +import com.nimbusds.jose.jwk.JWK; +import com.nimbusds.jose.jwk.RSAKey; +import com.nimbusds.jwt.JWTClaimsSet; +import com.nimbusds.jwt.SignedJWT; +import org.eclipse.microprofile.config.Config; + +import javax.inject.Inject; +import java.time.Instant; +import java.time.temporal.ChronoUnit; +import java.util.Arrays; +import java.util.Date; +import java.util.UUID; + +public abstract class AbstractGrantTypeHandler implements AuthorizationGrantTypeHandler { + + //Always RSA 256, but could be parametrized + protected JWSHeader jwsHeader = new JWSHeader.Builder(JWSAlgorithm.RS256).type(JOSEObjectType.JWT).build(); + + @Inject + protected Config config; + + //30 min + protected Long expiresInMin = 30L; + + protected JWSVerifier getJWSVerifier() throws Exception { + String verificationkey = config.getValue("verificationkey", String.class); + String pemEncodedRSAPublicKey = PEMKeyUtils.readKeyAsString(verificationkey); + RSAKey rsaPublicKey = (RSAKey) JWK.parseFromPEMEncodedObjects(pemEncodedRSAPublicKey); + return new RSASSAVerifier(rsaPublicKey); + } + + protected JWSSigner getJwsSigner() throws Exception { + String signingkey = config.getValue("signingkey", String.class); + String pemEncodedRSAPrivateKey = PEMKeyUtils.readKeyAsString(signingkey); + RSAKey rsaKey = (RSAKey) JWK.parseFromPEMEncodedObjects(pemEncodedRSAPrivateKey); + return new RSASSASigner(rsaKey.toRSAPrivateKey()); + } + + protected String getAccessToken(String clientId, String subject, String approvedScope) throws Exception { + //4. Signing + JWSSigner jwsSigner = getJwsSigner(); + + Instant now = Instant.now(); + //Long expiresInMin = 30L; + Date expirationTime = Date.from(now.plus(expiresInMin, ChronoUnit.MINUTES)); + + //3. JWT Payload or claims + JWTClaimsSet jwtClaims = new JWTClaimsSet.Builder() + .issuer("http://localhost:9080") + .subject(subject) + .claim("upn", subject) + .claim("client_id", clientId) + .audience("http://localhost:9280") + .claim("scope", approvedScope) + .claim("groups", Arrays.asList(approvedScope.split(" "))) + .expirationTime(expirationTime) // expires in 30 minutes + .notBeforeTime(Date.from(now)) + .issueTime(Date.from(now)) + .jwtID(UUID.randomUUID().toString()) + .build(); + SignedJWT signedJWT = new SignedJWT(jwsHeader, jwtClaims); + signedJWT.sign(jwsSigner); + return signedJWT.serialize(); + } + + protected String getRefreshToken(String clientId, String subject, String approvedScope) throws Exception { + JWSSigner jwsSigner = getJwsSigner(); + Instant now = Instant.now(); + //6.Build refresh token + JWTClaimsSet refreshTokenClaims = new JWTClaimsSet.Builder() + .subject(subject) + .claim("client_id", clientId) + .claim("scope", approvedScope) + //refresh token for 1 day. + .expirationTime(Date.from(now.plus(1, ChronoUnit.DAYS))) + .build(); + SignedJWT signedRefreshToken = new SignedJWT(jwsHeader, refreshTokenClaims); + signedRefreshToken.sign(jwsSigner); + return signedRefreshToken.serialize(); + } +} diff --git a/oauth2-framework-impl/oauth2-authorization-server/src/main/java/com/baeldung/oauth2/authorization/server/handler/AuthorizationCodeGrantTypeHandler.java b/security-modules/oauth2-framework-impl/oauth2-authorization-server/src/main/java/com/baeldung/oauth2/authorization/server/handler/AuthorizationCodeGrantTypeHandler.java similarity index 97% rename from oauth2-framework-impl/oauth2-authorization-server/src/main/java/com/baeldung/oauth2/authorization/server/handler/AuthorizationCodeGrantTypeHandler.java rename to security-modules/oauth2-framework-impl/oauth2-authorization-server/src/main/java/com/baeldung/oauth2/authorization/server/handler/AuthorizationCodeGrantTypeHandler.java index 78128aead6..bd7dbb0d31 100644 --- a/oauth2-framework-impl/oauth2-authorization-server/src/main/java/com/baeldung/oauth2/authorization/server/handler/AuthorizationCodeGrantTypeHandler.java +++ b/security-modules/oauth2-framework-impl/oauth2-authorization-server/src/main/java/com/baeldung/oauth2/authorization/server/handler/AuthorizationCodeGrantTypeHandler.java @@ -1,54 +1,54 @@ -package com.baeldung.oauth2.authorization.server.handler; - -import com.baeldung.oauth2.authorization.server.model.AuthorizationCode; - -import javax.inject.Named; -import javax.json.Json; -import javax.json.JsonObject; -import javax.persistence.EntityManager; -import javax.persistence.PersistenceContext; -import javax.ws.rs.WebApplicationException; -import javax.ws.rs.core.MultivaluedMap; -import java.time.LocalDateTime; - -@Named("authorization_code") -public class AuthorizationCodeGrantTypeHandler extends AbstractGrantTypeHandler { - - @PersistenceContext - private EntityManager entityManager; - - @Override - public JsonObject createAccessToken(String clientId, MultivaluedMap params) throws Exception { - //1. code is required - String code = params.getFirst("code"); - if (code == null || "".equals(code)) { - throw new WebApplicationException("invalid_grant"); - } - AuthorizationCode authorizationCode = entityManager.find(AuthorizationCode.class, code); - if (!authorizationCode.getExpirationDate().isAfter(LocalDateTime.now())) { - throw new WebApplicationException("code Expired !"); - } - String redirectUri = params.getFirst("redirect_uri"); - //redirecturi match - if (authorizationCode.getRedirectUri() != null && !authorizationCode.getRedirectUri().equals(redirectUri)) { - //redirectUri params should be the same as the requested redirectUri. - throw new WebApplicationException("invalid_grant"); - } - //client match - if (!clientId.equals(authorizationCode.getClientId())) { - throw new WebApplicationException("invalid_grant"); - } - - //3. JWT Payload or claims - String accessToken = getAccessToken(clientId, authorizationCode.getUserId(), authorizationCode.getApprovedScopes()); - String refreshToken = getRefreshToken(clientId, authorizationCode.getUserId(), authorizationCode.getApprovedScopes()); - - return Json.createObjectBuilder() - .add("token_type", "Bearer") - .add("access_token", accessToken) - .add("expires_in", expiresInMin * 60) - .add("scope", authorizationCode.getApprovedScopes()) - .add("refresh_token", refreshToken) - .build(); - } -} +package com.baeldung.oauth2.authorization.server.handler; + +import com.baeldung.oauth2.authorization.server.model.AuthorizationCode; + +import javax.inject.Named; +import javax.json.Json; +import javax.json.JsonObject; +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; +import javax.ws.rs.WebApplicationException; +import javax.ws.rs.core.MultivaluedMap; +import java.time.LocalDateTime; + +@Named("authorization_code") +public class AuthorizationCodeGrantTypeHandler extends AbstractGrantTypeHandler { + + @PersistenceContext + private EntityManager entityManager; + + @Override + public JsonObject createAccessToken(String clientId, MultivaluedMap params) throws Exception { + //1. code is required + String code = params.getFirst("code"); + if (code == null || "".equals(code)) { + throw new WebApplicationException("invalid_grant"); + } + AuthorizationCode authorizationCode = entityManager.find(AuthorizationCode.class, code); + if (!authorizationCode.getExpirationDate().isAfter(LocalDateTime.now())) { + throw new WebApplicationException("code Expired !"); + } + String redirectUri = params.getFirst("redirect_uri"); + //redirecturi match + if (authorizationCode.getRedirectUri() != null && !authorizationCode.getRedirectUri().equals(redirectUri)) { + //redirectUri params should be the same as the requested redirectUri. + throw new WebApplicationException("invalid_grant"); + } + //client match + if (!clientId.equals(authorizationCode.getClientId())) { + throw new WebApplicationException("invalid_grant"); + } + + //3. JWT Payload or claims + String accessToken = getAccessToken(clientId, authorizationCode.getUserId(), authorizationCode.getApprovedScopes()); + String refreshToken = getRefreshToken(clientId, authorizationCode.getUserId(), authorizationCode.getApprovedScopes()); + + return Json.createObjectBuilder() + .add("token_type", "Bearer") + .add("access_token", accessToken) + .add("expires_in", expiresInMin * 60) + .add("scope", authorizationCode.getApprovedScopes()) + .add("refresh_token", refreshToken) + .build(); + } +} diff --git a/oauth2-framework-impl/oauth2-authorization-server/src/main/java/com/baeldung/oauth2/authorization/server/handler/AuthorizationGrantTypeHandler.java b/security-modules/oauth2-framework-impl/oauth2-authorization-server/src/main/java/com/baeldung/oauth2/authorization/server/handler/AuthorizationGrantTypeHandler.java similarity index 97% rename from oauth2-framework-impl/oauth2-authorization-server/src/main/java/com/baeldung/oauth2/authorization/server/handler/AuthorizationGrantTypeHandler.java rename to security-modules/oauth2-framework-impl/oauth2-authorization-server/src/main/java/com/baeldung/oauth2/authorization/server/handler/AuthorizationGrantTypeHandler.java index a5afe293ef..0568db1b5c 100644 --- a/oauth2-framework-impl/oauth2-authorization-server/src/main/java/com/baeldung/oauth2/authorization/server/handler/AuthorizationGrantTypeHandler.java +++ b/security-modules/oauth2-framework-impl/oauth2-authorization-server/src/main/java/com/baeldung/oauth2/authorization/server/handler/AuthorizationGrantTypeHandler.java @@ -1,8 +1,8 @@ -package com.baeldung.oauth2.authorization.server.handler; - -import javax.json.JsonObject; -import javax.ws.rs.core.MultivaluedMap; - -public interface AuthorizationGrantTypeHandler { - JsonObject createAccessToken(String clientId, MultivaluedMap params) throws Exception; -} +package com.baeldung.oauth2.authorization.server.handler; + +import javax.json.JsonObject; +import javax.ws.rs.core.MultivaluedMap; + +public interface AuthorizationGrantTypeHandler { + JsonObject createAccessToken(String clientId, MultivaluedMap params) throws Exception; +} diff --git a/oauth2-framework-impl/oauth2-authorization-server/src/main/java/com/baeldung/oauth2/authorization/server/handler/RefreshTokenGrantTypeHandler.java b/security-modules/oauth2-framework-impl/oauth2-authorization-server/src/main/java/com/baeldung/oauth2/authorization/server/handler/RefreshTokenGrantTypeHandler.java similarity index 97% rename from oauth2-framework-impl/oauth2-authorization-server/src/main/java/com/baeldung/oauth2/authorization/server/handler/RefreshTokenGrantTypeHandler.java rename to security-modules/oauth2-framework-impl/oauth2-authorization-server/src/main/java/com/baeldung/oauth2/authorization/server/handler/RefreshTokenGrantTypeHandler.java index 63e3552353..433371f0d2 100644 --- a/oauth2-framework-impl/oauth2-authorization-server/src/main/java/com/baeldung/oauth2/authorization/server/handler/RefreshTokenGrantTypeHandler.java +++ b/security-modules/oauth2-framework-impl/oauth2-authorization-server/src/main/java/com/baeldung/oauth2/authorization/server/handler/RefreshTokenGrantTypeHandler.java @@ -1,72 +1,72 @@ -package com.baeldung.oauth2.authorization.server.handler; - -import com.nimbusds.jose.JWSVerifier; -import com.nimbusds.jwt.SignedJWT; - -import javax.inject.Named; -import javax.json.Json; -import javax.json.JsonObject; -import javax.ws.rs.WebApplicationException; -import javax.ws.rs.core.MultivaluedMap; -import javax.ws.rs.core.Response; -import java.util.Arrays; -import java.util.Date; -import java.util.HashSet; -import java.util.Set; - -@Named("refresh_token") -public class RefreshTokenGrantTypeHandler extends AbstractGrantTypeHandler { - - @Override - public JsonObject createAccessToken(String clientId, MultivaluedMap params) throws Exception { - String refreshToken = params.getFirst("refresh_token"); - if (refreshToken == null || "".equals(refreshToken)) { - throw new WebApplicationException("invalid_grant"); - } - - //Decode refresh token - SignedJWT signedRefreshToken = SignedJWT.parse(refreshToken); - JWSVerifier verifier = getJWSVerifier(); - - if (!signedRefreshToken.verify(verifier)) { - throw new WebApplicationException("Invalid refresh token."); - } - if (!(new Date().before(signedRefreshToken.getJWTClaimsSet().getExpirationTime()))) { - throw new WebApplicationException("Refresh token expired."); - } - String refreshTokenClientId = signedRefreshToken.getJWTClaimsSet().getStringClaim("client_id"); - if (!clientId.equals(refreshTokenClientId)) { - throw new WebApplicationException("Invalid client_id."); - } - - //At this point, the refresh token is valid and not yet expired - //So create a new access token from it. - String subject = signedRefreshToken.getJWTClaimsSet().getSubject(); - String approvedScopes = signedRefreshToken.getJWTClaimsSet().getStringClaim("scope"); - - String requestedScopes = params.getFirst("scope"); - if (requestedScopes != null && !requestedScopes.isEmpty()) { - Set rScopes = new HashSet(Arrays.asList(requestedScopes.split(" "))); - Set aScopes = new HashSet(Arrays.asList(approvedScopes.split(" "))); - if (!aScopes.containsAll(rScopes)) { - JsonObject error = Json.createObjectBuilder() - .add("error", "Invalid_request") - .add("error_description", "Requested scopes should be a subset of the original scopes.") - .build(); - Response response = Response.status(Response.Status.BAD_REQUEST).entity(error).build(); - throw new WebApplicationException(response); - } - } else { - requestedScopes = approvedScopes; - } - - String accessToken = getAccessToken(clientId, subject, requestedScopes); - return Json.createObjectBuilder() - .add("token_type", "Bearer") - .add("access_token", accessToken) - .add("expires_in", expiresInMin * 60) - .add("scope", requestedScopes) - .add("refresh_token", refreshToken) - .build(); - } -} +package com.baeldung.oauth2.authorization.server.handler; + +import com.nimbusds.jose.JWSVerifier; +import com.nimbusds.jwt.SignedJWT; + +import javax.inject.Named; +import javax.json.Json; +import javax.json.JsonObject; +import javax.ws.rs.WebApplicationException; +import javax.ws.rs.core.MultivaluedMap; +import javax.ws.rs.core.Response; +import java.util.Arrays; +import java.util.Date; +import java.util.HashSet; +import java.util.Set; + +@Named("refresh_token") +public class RefreshTokenGrantTypeHandler extends AbstractGrantTypeHandler { + + @Override + public JsonObject createAccessToken(String clientId, MultivaluedMap params) throws Exception { + String refreshToken = params.getFirst("refresh_token"); + if (refreshToken == null || "".equals(refreshToken)) { + throw new WebApplicationException("invalid_grant"); + } + + //Decode refresh token + SignedJWT signedRefreshToken = SignedJWT.parse(refreshToken); + JWSVerifier verifier = getJWSVerifier(); + + if (!signedRefreshToken.verify(verifier)) { + throw new WebApplicationException("Invalid refresh token."); + } + if (!(new Date().before(signedRefreshToken.getJWTClaimsSet().getExpirationTime()))) { + throw new WebApplicationException("Refresh token expired."); + } + String refreshTokenClientId = signedRefreshToken.getJWTClaimsSet().getStringClaim("client_id"); + if (!clientId.equals(refreshTokenClientId)) { + throw new WebApplicationException("Invalid client_id."); + } + + //At this point, the refresh token is valid and not yet expired + //So create a new access token from it. + String subject = signedRefreshToken.getJWTClaimsSet().getSubject(); + String approvedScopes = signedRefreshToken.getJWTClaimsSet().getStringClaim("scope"); + + String requestedScopes = params.getFirst("scope"); + if (requestedScopes != null && !requestedScopes.isEmpty()) { + Set rScopes = new HashSet(Arrays.asList(requestedScopes.split(" "))); + Set aScopes = new HashSet(Arrays.asList(approvedScopes.split(" "))); + if (!aScopes.containsAll(rScopes)) { + JsonObject error = Json.createObjectBuilder() + .add("error", "Invalid_request") + .add("error_description", "Requested scopes should be a subset of the original scopes.") + .build(); + Response response = Response.status(Response.Status.BAD_REQUEST).entity(error).build(); + throw new WebApplicationException(response); + } + } else { + requestedScopes = approvedScopes; + } + + String accessToken = getAccessToken(clientId, subject, requestedScopes); + return Json.createObjectBuilder() + .add("token_type", "Bearer") + .add("access_token", accessToken) + .add("expires_in", expiresInMin * 60) + .add("scope", requestedScopes) + .add("refresh_token", refreshToken) + .build(); + } +} diff --git a/oauth2-framework-impl/oauth2-authorization-server/src/main/java/com/baeldung/oauth2/authorization/server/model/AppDataRepository.java b/security-modules/oauth2-framework-impl/oauth2-authorization-server/src/main/java/com/baeldung/oauth2/authorization/server/model/AppDataRepository.java similarity index 96% rename from oauth2-framework-impl/oauth2-authorization-server/src/main/java/com/baeldung/oauth2/authorization/server/model/AppDataRepository.java rename to security-modules/oauth2-framework-impl/oauth2-authorization-server/src/main/java/com/baeldung/oauth2/authorization/server/model/AppDataRepository.java index 6b827d6a3d..00f506fb41 100644 --- a/oauth2-framework-impl/oauth2-authorization-server/src/main/java/com/baeldung/oauth2/authorization/server/model/AppDataRepository.java +++ b/security-modules/oauth2-framework-impl/oauth2-authorization-server/src/main/java/com/baeldung/oauth2/authorization/server/model/AppDataRepository.java @@ -1,27 +1,27 @@ -package com.baeldung.oauth2.authorization.server.model; - -import javax.enterprise.context.ApplicationScoped; -import javax.persistence.EntityManager; -import javax.persistence.PersistenceContext; -import javax.transaction.Transactional; - -@ApplicationScoped -public class AppDataRepository { - - @PersistenceContext - private EntityManager entityManager; - - public Client getClient(String clientId) { - return entityManager.find(Client.class, clientId); - } - - public User getUser(String userId) { - return entityManager.find(User.class, userId); - } - - @Transactional - public AuthorizationCode save(AuthorizationCode authorizationCode) { - entityManager.persist(authorizationCode); - return authorizationCode; - } -} +package com.baeldung.oauth2.authorization.server.model; + +import javax.enterprise.context.ApplicationScoped; +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; +import javax.transaction.Transactional; + +@ApplicationScoped +public class AppDataRepository { + + @PersistenceContext + private EntityManager entityManager; + + public Client getClient(String clientId) { + return entityManager.find(Client.class, clientId); + } + + public User getUser(String userId) { + return entityManager.find(User.class, userId); + } + + @Transactional + public AuthorizationCode save(AuthorizationCode authorizationCode) { + entityManager.persist(authorizationCode); + return authorizationCode; + } +} diff --git a/oauth2-framework-impl/oauth2-authorization-server/src/main/java/com/baeldung/oauth2/authorization/server/model/AuthorizationCode.java b/security-modules/oauth2-framework-impl/oauth2-authorization-server/src/main/java/com/baeldung/oauth2/authorization/server/model/AuthorizationCode.java similarity index 95% rename from oauth2-framework-impl/oauth2-authorization-server/src/main/java/com/baeldung/oauth2/authorization/server/model/AuthorizationCode.java rename to security-modules/oauth2-framework-impl/oauth2-authorization-server/src/main/java/com/baeldung/oauth2/authorization/server/model/AuthorizationCode.java index a2ec088eb9..c830c561a6 100644 --- a/oauth2-framework-impl/oauth2-authorization-server/src/main/java/com/baeldung/oauth2/authorization/server/model/AuthorizationCode.java +++ b/security-modules/oauth2-framework-impl/oauth2-authorization-server/src/main/java/com/baeldung/oauth2/authorization/server/model/AuthorizationCode.java @@ -1,73 +1,73 @@ -package com.baeldung.oauth2.authorization.server.model; - -import javax.persistence.*; -import java.time.LocalDateTime; - -@Entity -@Table(name = "authorization_code") -public class AuthorizationCode { - @Id - @GeneratedValue(strategy = GenerationType.AUTO) - @Column(name = "code") - private String code; - @Column(name = "client_id") - private String clientId; - @Column(name = "user_id") - private String userId; - @Column(name = "approved_scopes") - private String approvedScopes; - - @Column(name = "redirect_uri") - private String redirectUri; - - @Column(name = "expiration_date") - private LocalDateTime expirationDate; - - public String getUserId() { - return userId; - } - - public void setUserId(String username) { - this.userId = username; - } - - public String getClientId() { - return clientId; - } - - public void setClientId(String clientId) { - this.clientId = clientId; - } - - public String getCode() { - return code; - } - - public void setCode(String code) { - this.code = code; - } - - public String getApprovedScopes() { - return approvedScopes; - } - - public void setApprovedScopes(String approvedScopes) { - this.approvedScopes = approvedScopes; - } - - public String getRedirectUri() { - return redirectUri; - } - - public void setRedirectUri(String redirectUri) { - this.redirectUri = redirectUri; - } - - public LocalDateTime getExpirationDate() { - return expirationDate; - } - - public void setExpirationDate(LocalDateTime expirationDate) { - this.expirationDate = expirationDate; - } -} +package com.baeldung.oauth2.authorization.server.model; + +import javax.persistence.*; +import java.time.LocalDateTime; + +@Entity +@Table(name = "authorization_code") +public class AuthorizationCode { + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name = "code") + private String code; + @Column(name = "client_id") + private String clientId; + @Column(name = "user_id") + private String userId; + @Column(name = "approved_scopes") + private String approvedScopes; + + @Column(name = "redirect_uri") + private String redirectUri; + + @Column(name = "expiration_date") + private LocalDateTime expirationDate; + + public String getUserId() { + return userId; + } + + public void setUserId(String username) { + this.userId = username; + } + + public String getClientId() { + return clientId; + } + + public void setClientId(String clientId) { + this.clientId = clientId; + } + + public String getCode() { + return code; + } + + public void setCode(String code) { + this.code = code; + } + + public String getApprovedScopes() { + return approvedScopes; + } + + public void setApprovedScopes(String approvedScopes) { + this.approvedScopes = approvedScopes; + } + + public String getRedirectUri() { + return redirectUri; + } + + public void setRedirectUri(String redirectUri) { + this.redirectUri = redirectUri; + } + + public LocalDateTime getExpirationDate() { + return expirationDate; + } + + public void setExpirationDate(LocalDateTime expirationDate) { + this.expirationDate = expirationDate; + } +} diff --git a/oauth2-framework-impl/oauth2-authorization-server/src/main/java/com/baeldung/oauth2/authorization/server/model/Client.java b/security-modules/oauth2-framework-impl/oauth2-authorization-server/src/main/java/com/baeldung/oauth2/authorization/server/model/Client.java similarity index 95% rename from oauth2-framework-impl/oauth2-authorization-server/src/main/java/com/baeldung/oauth2/authorization/server/model/Client.java rename to security-modules/oauth2-framework-impl/oauth2-authorization-server/src/main/java/com/baeldung/oauth2/authorization/server/model/Client.java index 9b5ad2f904..cb9276d99d 100644 --- a/oauth2-framework-impl/oauth2-authorization-server/src/main/java/com/baeldung/oauth2/authorization/server/model/Client.java +++ b/security-modules/oauth2-framework-impl/oauth2-authorization-server/src/main/java/com/baeldung/oauth2/authorization/server/model/Client.java @@ -1,62 +1,62 @@ -package com.baeldung.oauth2.authorization.server.model; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.Table; - -@Entity -@Table(name = "clients") -public class Client { - @Id - @Column(name = "client_id") - private String clientId; - @Column(name = "client_secret") - private String clientSecret; - @Column(name = "redirect_uri") - private String redirectUri; - @Column(name = "scope") - private String scope; - @Column(name = "authorized_grant_types") - private String authorizedGrantTypes; - - public String getClientId() { - return clientId; - } - - public void setClientId(String clientId) { - this.clientId = clientId; - } - - public String getClientSecret() { - return clientSecret; - } - - public void setClientSecret(String clientSecret) { - this.clientSecret = clientSecret; - } - - public String getRedirectUri() { - return redirectUri; - } - - public void setRedirectUri(String redirectUri) { - this.redirectUri = redirectUri; - } - - public String getScope() { - return scope; - } - - public void setScope(String scope) { - this.scope = scope; - } - - public String getAuthorizedGrantTypes() { - return authorizedGrantTypes; - } - - public void setAuthorizedGrantTypes(String authorizedGrantTypes) { - this.authorizedGrantTypes = authorizedGrantTypes; - } -} +package com.baeldung.oauth2.authorization.server.model; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Table; + +@Entity +@Table(name = "clients") +public class Client { + @Id + @Column(name = "client_id") + private String clientId; + @Column(name = "client_secret") + private String clientSecret; + @Column(name = "redirect_uri") + private String redirectUri; + @Column(name = "scope") + private String scope; + @Column(name = "authorized_grant_types") + private String authorizedGrantTypes; + + public String getClientId() { + return clientId; + } + + public void setClientId(String clientId) { + this.clientId = clientId; + } + + public String getClientSecret() { + return clientSecret; + } + + public void setClientSecret(String clientSecret) { + this.clientSecret = clientSecret; + } + + public String getRedirectUri() { + return redirectUri; + } + + public void setRedirectUri(String redirectUri) { + this.redirectUri = redirectUri; + } + + public String getScope() { + return scope; + } + + public void setScope(String scope) { + this.scope = scope; + } + + public String getAuthorizedGrantTypes() { + return authorizedGrantTypes; + } + + public void setAuthorizedGrantTypes(String authorizedGrantTypes) { + this.authorizedGrantTypes = authorizedGrantTypes; + } +} diff --git a/oauth2-framework-impl/oauth2-authorization-server/src/main/java/com/baeldung/oauth2/authorization/server/model/User.java b/security-modules/oauth2-framework-impl/oauth2-authorization-server/src/main/java/com/baeldung/oauth2/authorization/server/model/User.java similarity index 95% rename from oauth2-framework-impl/oauth2-authorization-server/src/main/java/com/baeldung/oauth2/authorization/server/model/User.java rename to security-modules/oauth2-framework-impl/oauth2-authorization-server/src/main/java/com/baeldung/oauth2/authorization/server/model/User.java index b3821715f4..55a60b2009 100644 --- a/oauth2-framework-impl/oauth2-authorization-server/src/main/java/com/baeldung/oauth2/authorization/server/model/User.java +++ b/security-modules/oauth2-framework-impl/oauth2-authorization-server/src/main/java/com/baeldung/oauth2/authorization/server/model/User.java @@ -1,58 +1,58 @@ -package com.baeldung.oauth2.authorization.server.model; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.Table; -import java.security.Principal; - -@Entity -@Table(name = "users") -public class User implements Principal { - @Id - @Column(name = "user_id") - private String userId; - @Column(name = "password") - private String password; - @Column(name = "roles") - private String roles; - @Column(name = "scopes") - private String scopes; - - public String getUserId() { - return userId; - } - - public void setUserId(String username) { - this.userId = username; - } - - public String getPassword() { - return password; - } - - public void setPassword(String password) { - this.password = password; - } - - public String getRoles() { - return roles; - } - - public void setRoles(String roles) { - this.roles = roles; - } - - public String getScopes() { - return scopes; - } - - public void setScopes(String scopes) { - this.scopes = scopes; - } - - @Override - public String getName() { - return getUserId(); - } -} +package com.baeldung.oauth2.authorization.server.model; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Table; +import java.security.Principal; + +@Entity +@Table(name = "users") +public class User implements Principal { + @Id + @Column(name = "user_id") + private String userId; + @Column(name = "password") + private String password; + @Column(name = "roles") + private String roles; + @Column(name = "scopes") + private String scopes; + + public String getUserId() { + return userId; + } + + public void setUserId(String username) { + this.userId = username; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public String getRoles() { + return roles; + } + + public void setRoles(String roles) { + this.roles = roles; + } + + public String getScopes() { + return scopes; + } + + public void setScopes(String scopes) { + this.scopes = scopes; + } + + @Override + public String getName() { + return getUserId(); + } +} diff --git a/oauth2-framework-impl/oauth2-authorization-server/src/main/java/com/baeldung/oauth2/authorization/server/security/UserIdentityStore.java b/security-modules/oauth2-framework-impl/oauth2-authorization-server/src/main/java/com/baeldung/oauth2/authorization/server/security/UserIdentityStore.java similarity index 97% rename from oauth2-framework-impl/oauth2-authorization-server/src/main/java/com/baeldung/oauth2/authorization/server/security/UserIdentityStore.java rename to security-modules/oauth2-framework-impl/oauth2-authorization-server/src/main/java/com/baeldung/oauth2/authorization/server/security/UserIdentityStore.java index a32ab32cd4..f1e07c7602 100644 --- a/oauth2-framework-impl/oauth2-authorization-server/src/main/java/com/baeldung/oauth2/authorization/server/security/UserIdentityStore.java +++ b/security-modules/oauth2-framework-impl/oauth2-authorization-server/src/main/java/com/baeldung/oauth2/authorization/server/security/UserIdentityStore.java @@ -1,37 +1,37 @@ -package com.baeldung.oauth2.authorization.server.security; - -import com.baeldung.oauth2.authorization.server.model.AppDataRepository; -import com.baeldung.oauth2.authorization.server.model.User; - -import javax.enterprise.context.ApplicationScoped; -import javax.inject.Inject; -import javax.security.enterprise.credential.Credential; -import javax.security.enterprise.credential.UsernamePasswordCredential; -import javax.security.enterprise.identitystore.CredentialValidationResult; -import javax.security.enterprise.identitystore.IdentityStore; -import javax.transaction.Transactional; -import java.util.Arrays; -import java.util.HashSet; -import java.util.Objects; - -import static javax.security.enterprise.identitystore.CredentialValidationResult.INVALID_RESULT; - -@ApplicationScoped -@Transactional -public class UserIdentityStore implements IdentityStore { - - @Inject - private AppDataRepository appDataRepository; - - @Override - public CredentialValidationResult validate(Credential credential) { - UsernamePasswordCredential usernamePasswordCredential = (UsernamePasswordCredential) credential; - String userId = usernamePasswordCredential.getCaller(); - User user = appDataRepository.getUser(userId); - Objects.requireNonNull(user, "User should be not null"); - if (usernamePasswordCredential.getPasswordAsString().equals(user.getPassword())) { - return new CredentialValidationResult(userId, new HashSet<>(Arrays.asList(user.getRoles().split(",")))); - } - return INVALID_RESULT; - } +package com.baeldung.oauth2.authorization.server.security; + +import com.baeldung.oauth2.authorization.server.model.AppDataRepository; +import com.baeldung.oauth2.authorization.server.model.User; + +import javax.enterprise.context.ApplicationScoped; +import javax.inject.Inject; +import javax.security.enterprise.credential.Credential; +import javax.security.enterprise.credential.UsernamePasswordCredential; +import javax.security.enterprise.identitystore.CredentialValidationResult; +import javax.security.enterprise.identitystore.IdentityStore; +import javax.transaction.Transactional; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Objects; + +import static javax.security.enterprise.identitystore.CredentialValidationResult.INVALID_RESULT; + +@ApplicationScoped +@Transactional +public class UserIdentityStore implements IdentityStore { + + @Inject + private AppDataRepository appDataRepository; + + @Override + public CredentialValidationResult validate(Credential credential) { + UsernamePasswordCredential usernamePasswordCredential = (UsernamePasswordCredential) credential; + String userId = usernamePasswordCredential.getCaller(); + User user = appDataRepository.getUser(userId); + Objects.requireNonNull(user, "User should be not null"); + if (usernamePasswordCredential.getPasswordAsString().equals(user.getPassword())) { + return new CredentialValidationResult(userId, new HashSet<>(Arrays.asList(user.getRoles().split(",")))); + } + return INVALID_RESULT; + } } \ No newline at end of file diff --git a/oauth2-framework-impl/oauth2-authorization-server/src/main/liberty/config/server.xml b/security-modules/oauth2-framework-impl/oauth2-authorization-server/src/main/liberty/config/server.xml similarity index 100% rename from oauth2-framework-impl/oauth2-authorization-server/src/main/liberty/config/server.xml rename to security-modules/oauth2-framework-impl/oauth2-authorization-server/src/main/liberty/config/server.xml diff --git a/oauth2-framework-impl/oauth2-authorization-server/src/main/resources/META-INF/microprofile-config.properties b/security-modules/oauth2-framework-impl/oauth2-authorization-server/src/main/resources/META-INF/microprofile-config.properties similarity index 100% rename from oauth2-framework-impl/oauth2-authorization-server/src/main/resources/META-INF/microprofile-config.properties rename to security-modules/oauth2-framework-impl/oauth2-authorization-server/src/main/resources/META-INF/microprofile-config.properties diff --git a/oauth2-framework-impl/oauth2-authorization-server/src/main/resources/META-INF/persistence.xml b/security-modules/oauth2-framework-impl/oauth2-authorization-server/src/main/resources/META-INF/persistence.xml similarity index 98% rename from oauth2-framework-impl/oauth2-authorization-server/src/main/resources/META-INF/persistence.xml rename to security-modules/oauth2-framework-impl/oauth2-authorization-server/src/main/resources/META-INF/persistence.xml index a10ad3c886..9d7fc96426 100644 --- a/oauth2-framework-impl/oauth2-authorization-server/src/main/resources/META-INF/persistence.xml +++ b/security-modules/oauth2-framework-impl/oauth2-authorization-server/src/main/resources/META-INF/persistence.xml @@ -1,14 +1,14 @@ - - - - jdbc/OAuth2_DS - - - - - + + + + jdbc/OAuth2_DS + + + + + \ No newline at end of file diff --git a/oauth2-framework-impl/oauth2-authorization-server/src/main/resources/META-INF/private-key.pem b/security-modules/oauth2-framework-impl/oauth2-authorization-server/src/main/resources/META-INF/private-key.pem similarity index 100% rename from oauth2-framework-impl/oauth2-authorization-server/src/main/resources/META-INF/private-key.pem rename to security-modules/oauth2-framework-impl/oauth2-authorization-server/src/main/resources/META-INF/private-key.pem diff --git a/oauth2-framework-impl/oauth2-authorization-server/src/main/resources/META-INF/public-key.pem b/security-modules/oauth2-framework-impl/oauth2-authorization-server/src/main/resources/META-INF/public-key.pem similarity index 100% rename from oauth2-framework-impl/oauth2-authorization-server/src/main/resources/META-INF/public-key.pem rename to security-modules/oauth2-framework-impl/oauth2-authorization-server/src/main/resources/META-INF/public-key.pem diff --git a/oauth2-framework-impl/oauth2-authorization-server/src/main/resources/data.sql b/security-modules/oauth2-framework-impl/oauth2-authorization-server/src/main/resources/data.sql similarity index 99% rename from oauth2-framework-impl/oauth2-authorization-server/src/main/resources/data.sql rename to security-modules/oauth2-framework-impl/oauth2-authorization-server/src/main/resources/data.sql index ecda0fa2ad..b3342a2168 100644 --- a/oauth2-framework-impl/oauth2-authorization-server/src/main/resources/data.sql +++ b/security-modules/oauth2-framework-impl/oauth2-authorization-server/src/main/resources/data.sql @@ -1,3 +1,3 @@ -INSERT INTO `users` (`user_id`, `password`, `roles`, `scopes`) VALUES ('appuser', 'appusersecret', 'USER', 'resource.read resource.write'); - +INSERT INTO `users` (`user_id`, `password`, `roles`, `scopes`) VALUES ('appuser', 'appusersecret', 'USER', 'resource.read resource.write'); + INSERT INTO `clients` (`client_id`, `client_secret`, `redirect_uri`,`scope`,`authorized_grant_types`) VALUES ('webappclient', 'webappclientsecret', 'http://localhost:9180/callback', 'resource.read resource.write', 'authorization_code refresh_token'); \ No newline at end of file diff --git a/oauth2-framework-impl/oauth2-authorization-server/src/main/webapp/WEB-INF/beans.xml b/security-modules/oauth2-framework-impl/oauth2-authorization-server/src/main/webapp/WEB-INF/beans.xml similarity index 100% rename from oauth2-framework-impl/oauth2-authorization-server/src/main/webapp/WEB-INF/beans.xml rename to security-modules/oauth2-framework-impl/oauth2-authorization-server/src/main/webapp/WEB-INF/beans.xml diff --git a/oauth2-framework-impl/oauth2-authorization-server/src/main/webapp/authorize.jsp b/security-modules/oauth2-framework-impl/oauth2-authorization-server/src/main/webapp/authorize.jsp similarity index 96% rename from oauth2-framework-impl/oauth2-authorization-server/src/main/webapp/authorize.jsp rename to security-modules/oauth2-framework-impl/oauth2-authorization-server/src/main/webapp/authorize.jsp index 41b0582c03..51bad3565e 100644 --- a/oauth2-framework-impl/oauth2-authorization-server/src/main/webapp/authorize.jsp +++ b/security-modules/oauth2-framework-impl/oauth2-authorization-server/src/main/webapp/authorize.jsp @@ -1,54 +1,54 @@ -<%@ page contentType="text/html;charset=UTF-8" language="java" %> -<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> - - - - Authorization - - - - -
-

Want to Authorize scopes for client : ${client.clientId} ?

-
- -
- - - - - - - - - -
Scopes : - - ${scope}
-
-
- - -
-
- -
- - - +<%@ page contentType="text/html;charset=UTF-8" language="java" %> +<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> + + + + Authorization + + + + +
+

Want to Authorize scopes for client : ${client.clientId} ?

+
+ +
+ + + + + + + + + +
Scopes : + + ${scope}
+
+
+ + +
+
+ +
+ + + diff --git a/oauth2-framework-impl/oauth2-authorization-server/src/main/webapp/error.jsp b/security-modules/oauth2-framework-impl/oauth2-authorization-server/src/main/webapp/error.jsp similarity index 94% rename from oauth2-framework-impl/oauth2-authorization-server/src/main/webapp/error.jsp rename to security-modules/oauth2-framework-impl/oauth2-authorization-server/src/main/webapp/error.jsp index edb0bf28b7..db996ea814 100644 --- a/oauth2-framework-impl/oauth2-authorization-server/src/main/webapp/error.jsp +++ b/security-modules/oauth2-framework-impl/oauth2-authorization-server/src/main/webapp/error.jsp @@ -1,25 +1,25 @@ -<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1" %> - - - - - - Error - - - - - - -
-

${error}

-
- - +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1" %> + + + + + + Error + + + + + + +
+

${error}

+
+ + \ No newline at end of file diff --git a/oauth2-framework-impl/oauth2-authorization-server/src/main/webapp/login-error.jsp b/security-modules/oauth2-framework-impl/oauth2-authorization-server/src/main/webapp/login-error.jsp similarity index 100% rename from oauth2-framework-impl/oauth2-authorization-server/src/main/webapp/login-error.jsp rename to security-modules/oauth2-framework-impl/oauth2-authorization-server/src/main/webapp/login-error.jsp diff --git a/oauth2-framework-impl/oauth2-authorization-server/src/main/webapp/login.jsp b/security-modules/oauth2-framework-impl/oauth2-authorization-server/src/main/webapp/login.jsp similarity index 96% rename from oauth2-framework-impl/oauth2-authorization-server/src/main/webapp/login.jsp rename to security-modules/oauth2-framework-impl/oauth2-authorization-server/src/main/webapp/login.jsp index 1d2dd93fd0..c2caed961f 100644 --- a/oauth2-framework-impl/oauth2-authorization-server/src/main/webapp/login.jsp +++ b/security-modules/oauth2-framework-impl/oauth2-authorization-server/src/main/webapp/login.jsp @@ -1,49 +1,49 @@ -<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1" %> - - - - - Login Form - - - - -
-

Login Form

-
-
- - - - - - - - - - - - - -
Username
Password
-
- -
- - +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1" %> + + + + + Login Form + + + + +
+

Login Form

+
+
+ + + + + + + + + + + + + +
Username
Password
+
+ +
+ + \ No newline at end of file diff --git a/oauth2-framework-impl/oauth2-client/pom.xml b/security-modules/oauth2-framework-impl/oauth2-client/pom.xml similarity index 100% rename from oauth2-framework-impl/oauth2-client/pom.xml rename to security-modules/oauth2-framework-impl/oauth2-client/pom.xml diff --git a/oauth2-framework-impl/oauth2-client/src/main/java/com/baeldung/oauth2/client/AbstractServlet.java b/security-modules/oauth2-framework-impl/oauth2-client/src/main/java/com/baeldung/oauth2/client/AbstractServlet.java similarity index 97% rename from oauth2-framework-impl/oauth2-client/src/main/java/com/baeldung/oauth2/client/AbstractServlet.java rename to security-modules/oauth2-framework-impl/oauth2-client/src/main/java/com/baeldung/oauth2/client/AbstractServlet.java index 7059c4f7e1..6e3d958dbd 100644 --- a/oauth2-framework-impl/oauth2-client/src/main/java/com/baeldung/oauth2/client/AbstractServlet.java +++ b/security-modules/oauth2-framework-impl/oauth2-client/src/main/java/com/baeldung/oauth2/client/AbstractServlet.java @@ -1,23 +1,23 @@ -package com.baeldung.oauth2.client; - -import javax.servlet.RequestDispatcher; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; -import java.util.Base64; - -public abstract class AbstractServlet extends HttpServlet { - - protected void dispatch(String location, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - RequestDispatcher requestDispatcher = request.getRequestDispatcher(location); - requestDispatcher.forward(request, response); - } - - protected String getAuthorizationHeaderValue(String clientId, String clientSecret) { - String token = clientId + ":" + clientSecret; - String encodedString = Base64.getEncoder().encodeToString(token.getBytes()); - return "Basic " + encodedString; - } -} +package com.baeldung.oauth2.client; + +import javax.servlet.RequestDispatcher; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.util.Base64; + +public abstract class AbstractServlet extends HttpServlet { + + protected void dispatch(String location, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + RequestDispatcher requestDispatcher = request.getRequestDispatcher(location); + requestDispatcher.forward(request, response); + } + + protected String getAuthorizationHeaderValue(String clientId, String clientSecret) { + String token = clientId + ":" + clientSecret; + String encodedString = Base64.getEncoder().encodeToString(token.getBytes()); + return "Basic " + encodedString; + } +} diff --git a/oauth2-framework-impl/oauth2-client/src/main/java/com/baeldung/oauth2/client/AuthorizationCodeServlet.java b/security-modules/oauth2-framework-impl/oauth2-client/src/main/java/com/baeldung/oauth2/client/AuthorizationCodeServlet.java similarity index 97% rename from oauth2-framework-impl/oauth2-client/src/main/java/com/baeldung/oauth2/client/AuthorizationCodeServlet.java rename to security-modules/oauth2-framework-impl/oauth2-client/src/main/java/com/baeldung/oauth2/client/AuthorizationCodeServlet.java index a5fdaf07f2..56a72586c8 100644 --- a/oauth2-framework-impl/oauth2-client/src/main/java/com/baeldung/oauth2/client/AuthorizationCodeServlet.java +++ b/security-modules/oauth2-framework-impl/oauth2-client/src/main/java/com/baeldung/oauth2/client/AuthorizationCodeServlet.java @@ -1,39 +1,39 @@ -package com.baeldung.oauth2.client; - -import org.eclipse.microprofile.config.Config; - -import javax.inject.Inject; -import javax.servlet.ServletException; -import javax.servlet.annotation.WebServlet; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; -import java.util.UUID; - -@WebServlet(urlPatterns = "/authorize") -public class AuthorizationCodeServlet extends HttpServlet { - - @Inject - private Config config; - - @Override - protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - //... - request.getSession().removeAttribute("tokenResponse"); - String state = UUID.randomUUID().toString(); - request.getSession().setAttribute("CLIENT_LOCAL_STATE", state); - - String authorizationUri = config.getValue("provider.authorizationUri", String.class); - String clientId = config.getValue("client.clientId", String.class); - String redirectUri = config.getValue("client.redirectUri", String.class); - String scope = config.getValue("client.scope", String.class); - - String authorizationLocation = authorizationUri + "?response_type=code" - + "&client_id=" + clientId - + "&redirect_uri=" + redirectUri - + "&scope=" + scope - + "&state=" + state; - response.sendRedirect(authorizationLocation); - } -} +package com.baeldung.oauth2.client; + +import org.eclipse.microprofile.config.Config; + +import javax.inject.Inject; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.util.UUID; + +@WebServlet(urlPatterns = "/authorize") +public class AuthorizationCodeServlet extends HttpServlet { + + @Inject + private Config config; + + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + //... + request.getSession().removeAttribute("tokenResponse"); + String state = UUID.randomUUID().toString(); + request.getSession().setAttribute("CLIENT_LOCAL_STATE", state); + + String authorizationUri = config.getValue("provider.authorizationUri", String.class); + String clientId = config.getValue("client.clientId", String.class); + String redirectUri = config.getValue("client.redirectUri", String.class); + String scope = config.getValue("client.scope", String.class); + + String authorizationLocation = authorizationUri + "?response_type=code" + + "&client_id=" + clientId + + "&redirect_uri=" + redirectUri + + "&scope=" + scope + + "&state=" + state; + response.sendRedirect(authorizationLocation); + } +} diff --git a/oauth2-framework-impl/oauth2-client/src/main/java/com/baeldung/oauth2/client/CallbackServlet.java b/security-modules/oauth2-framework-impl/oauth2-client/src/main/java/com/baeldung/oauth2/client/CallbackServlet.java similarity index 97% rename from oauth2-framework-impl/oauth2-client/src/main/java/com/baeldung/oauth2/client/CallbackServlet.java rename to security-modules/oauth2-framework-impl/oauth2-client/src/main/java/com/baeldung/oauth2/client/CallbackServlet.java index e72877076c..77f8197b9b 100644 --- a/oauth2-framework-impl/oauth2-client/src/main/java/com/baeldung/oauth2/client/CallbackServlet.java +++ b/security-modules/oauth2-framework-impl/oauth2-client/src/main/java/com/baeldung/oauth2/client/CallbackServlet.java @@ -1,67 +1,67 @@ -package com.baeldung.oauth2.client; - -import org.eclipse.microprofile.config.Config; - -import javax.inject.Inject; -import javax.json.JsonObject; -import javax.servlet.ServletException; -import javax.servlet.annotation.WebServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.ws.rs.client.Client; -import javax.ws.rs.client.ClientBuilder; -import javax.ws.rs.client.Entity; -import javax.ws.rs.client.WebTarget; -import javax.ws.rs.core.Form; -import javax.ws.rs.core.HttpHeaders; -import javax.ws.rs.core.MediaType; -import java.io.IOException; - -@WebServlet(urlPatterns = "/callback") -public class CallbackServlet extends AbstractServlet { - - @Inject - private Config config; - - @Override - protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - - String clientId = config.getValue("client.clientId", String.class); - String clientSecret = config.getValue("client.clientSecret", String.class); - - //Error: - String error = request.getParameter("error"); - if (error != null) { - request.setAttribute("error", error); - dispatch("/", request, response); - return; - } - String localState = (String) request.getSession().getAttribute("CLIENT_LOCAL_STATE"); - if (!localState.equals(request.getParameter("state"))) { - request.setAttribute("error", "The state attribute doesn't match !!"); - dispatch("/", request, response); - return; - } - - String code = request.getParameter("code"); - - Client client = ClientBuilder.newClient(); - WebTarget target = client.target(config.getValue("provider.tokenUri", String.class)); - - Form form = new Form(); - form.param("grant_type", "authorization_code"); - form.param("code", code); - form.param("redirect_uri", config.getValue("client.redirectUri", String.class)); - - try { - JsonObject tokenResponse = target.request(MediaType.APPLICATION_JSON_TYPE) - .header(HttpHeaders.AUTHORIZATION, getAuthorizationHeaderValue(clientId, clientSecret)) - .post(Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED_TYPE), JsonObject.class); - request.getSession().setAttribute("tokenResponse", tokenResponse); - } catch (Exception ex) { - System.out.println(ex.getMessage()); - request.setAttribute("error", ex.getMessage()); - } - dispatch("/", request, response); - } -} +package com.baeldung.oauth2.client; + +import org.eclipse.microprofile.config.Config; + +import javax.inject.Inject; +import javax.json.JsonObject; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.Entity; +import javax.ws.rs.client.WebTarget; +import javax.ws.rs.core.Form; +import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.MediaType; +import java.io.IOException; + +@WebServlet(urlPatterns = "/callback") +public class CallbackServlet extends AbstractServlet { + + @Inject + private Config config; + + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + + String clientId = config.getValue("client.clientId", String.class); + String clientSecret = config.getValue("client.clientSecret", String.class); + + //Error: + String error = request.getParameter("error"); + if (error != null) { + request.setAttribute("error", error); + dispatch("/", request, response); + return; + } + String localState = (String) request.getSession().getAttribute("CLIENT_LOCAL_STATE"); + if (!localState.equals(request.getParameter("state"))) { + request.setAttribute("error", "The state attribute doesn't match !!"); + dispatch("/", request, response); + return; + } + + String code = request.getParameter("code"); + + Client client = ClientBuilder.newClient(); + WebTarget target = client.target(config.getValue("provider.tokenUri", String.class)); + + Form form = new Form(); + form.param("grant_type", "authorization_code"); + form.param("code", code); + form.param("redirect_uri", config.getValue("client.redirectUri", String.class)); + + try { + JsonObject tokenResponse = target.request(MediaType.APPLICATION_JSON_TYPE) + .header(HttpHeaders.AUTHORIZATION, getAuthorizationHeaderValue(clientId, clientSecret)) + .post(Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED_TYPE), JsonObject.class); + request.getSession().setAttribute("tokenResponse", tokenResponse); + } catch (Exception ex) { + System.out.println(ex.getMessage()); + request.setAttribute("error", ex.getMessage()); + } + dispatch("/", request, response); + } +} diff --git a/oauth2-framework-impl/oauth2-client/src/main/java/com/baeldung/oauth2/client/DownstreamCallServlet.java b/security-modules/oauth2-framework-impl/oauth2-client/src/main/java/com/baeldung/oauth2/client/DownstreamCallServlet.java similarity index 97% rename from oauth2-framework-impl/oauth2-client/src/main/java/com/baeldung/oauth2/client/DownstreamCallServlet.java rename to security-modules/oauth2-framework-impl/oauth2-client/src/main/java/com/baeldung/oauth2/client/DownstreamCallServlet.java index bbe850917b..c6a7f8b08b 100644 --- a/oauth2-framework-impl/oauth2-client/src/main/java/com/baeldung/oauth2/client/DownstreamCallServlet.java +++ b/security-modules/oauth2-framework-impl/oauth2-client/src/main/java/com/baeldung/oauth2/client/DownstreamCallServlet.java @@ -1,49 +1,49 @@ -package com.baeldung.oauth2.client; - -import org.eclipse.microprofile.config.Config; - -import javax.inject.Inject; -import javax.json.JsonObject; -import javax.servlet.ServletException; -import javax.servlet.annotation.WebServlet; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.ws.rs.client.*; -import java.io.IOException; -import java.io.PrintWriter; - -@WebServlet(urlPatterns = "/downstream") -public class DownstreamCallServlet extends HttpServlet { - - @Inject - private Config config; - - @Override - protected void doGet(HttpServletRequest request, HttpServletResponse resp) throws ServletException, IOException { - resp.setContentType("text/html;charset=UTF-8"); - String action = request.getParameter("action"); - Client client = ClientBuilder.newClient(); - WebTarget webTarget = client.target(config.getValue("resourceServerUri", String.class)); - WebTarget resourceWebTarget; - String response = null; - JsonObject tokenResponse = (JsonObject) request.getSession().getAttribute("tokenResponse"); - if ("read".equals(action)) { - resourceWebTarget = webTarget.path("resource/read"); - Invocation.Builder invocationBuilder = resourceWebTarget.request(); - response = invocationBuilder - .header("authorization", tokenResponse.getString("access_token")) - .get(String.class); - } else if ("write".equals(action)) { - resourceWebTarget = webTarget.path("resource/write"); - Invocation.Builder invocationBuilder = resourceWebTarget.request(); - response = invocationBuilder - .header("authorization", tokenResponse.getString("access_token")) - .post(Entity.text("body string"), String.class); - } - PrintWriter out = resp.getWriter(); - out.println(response); - out.flush(); - out.close(); - } -} +package com.baeldung.oauth2.client; + +import org.eclipse.microprofile.config.Config; + +import javax.inject.Inject; +import javax.json.JsonObject; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.ws.rs.client.*; +import java.io.IOException; +import java.io.PrintWriter; + +@WebServlet(urlPatterns = "/downstream") +public class DownstreamCallServlet extends HttpServlet { + + @Inject + private Config config; + + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse resp) throws ServletException, IOException { + resp.setContentType("text/html;charset=UTF-8"); + String action = request.getParameter("action"); + Client client = ClientBuilder.newClient(); + WebTarget webTarget = client.target(config.getValue("resourceServerUri", String.class)); + WebTarget resourceWebTarget; + String response = null; + JsonObject tokenResponse = (JsonObject) request.getSession().getAttribute("tokenResponse"); + if ("read".equals(action)) { + resourceWebTarget = webTarget.path("resource/read"); + Invocation.Builder invocationBuilder = resourceWebTarget.request(); + response = invocationBuilder + .header("authorization", tokenResponse.getString("access_token")) + .get(String.class); + } else if ("write".equals(action)) { + resourceWebTarget = webTarget.path("resource/write"); + Invocation.Builder invocationBuilder = resourceWebTarget.request(); + response = invocationBuilder + .header("authorization", tokenResponse.getString("access_token")) + .post(Entity.text("body string"), String.class); + } + PrintWriter out = resp.getWriter(); + out.println(response); + out.flush(); + out.close(); + } +} diff --git a/oauth2-framework-impl/oauth2-client/src/main/java/com/baeldung/oauth2/client/RefreshTokenServlet.java b/security-modules/oauth2-framework-impl/oauth2-client/src/main/java/com/baeldung/oauth2/client/RefreshTokenServlet.java similarity index 97% rename from oauth2-framework-impl/oauth2-client/src/main/java/com/baeldung/oauth2/client/RefreshTokenServlet.java rename to security-modules/oauth2-framework-impl/oauth2-client/src/main/java/com/baeldung/oauth2/client/RefreshTokenServlet.java index a519a53070..af01beaa28 100644 --- a/oauth2-framework-impl/oauth2-client/src/main/java/com/baeldung/oauth2/client/RefreshTokenServlet.java +++ b/security-modules/oauth2-framework-impl/oauth2-client/src/main/java/com/baeldung/oauth2/client/RefreshTokenServlet.java @@ -1,57 +1,57 @@ -package com.baeldung.oauth2.client; - -import org.eclipse.microprofile.config.Config; - -import javax.inject.Inject; -import javax.json.JsonObject; -import javax.servlet.ServletException; -import javax.servlet.annotation.WebServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.ws.rs.client.Client; -import javax.ws.rs.client.ClientBuilder; -import javax.ws.rs.client.Entity; -import javax.ws.rs.client.WebTarget; -import javax.ws.rs.core.Form; -import javax.ws.rs.core.HttpHeaders; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import java.io.IOException; - -@WebServlet(urlPatterns = "/refreshtoken") -public class RefreshTokenServlet extends AbstractServlet { - - @Inject - private Config config; - - @Override - protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - - String clientId = config.getValue("client.clientId", String.class); - String clientSecret = config.getValue("client.clientSecret", String.class); - - JsonObject actualTokenResponse = (JsonObject) request.getSession().getAttribute("tokenResponse"); - Client client = ClientBuilder.newClient(); - WebTarget target = client.target(config.getValue("provider.tokenUri", String.class)); - - Form form = new Form(); - form.param("grant_type", "refresh_token"); - form.param("refresh_token", actualTokenResponse.getString("refresh_token")); - - String scope = request.getParameter("scope"); - if (scope != null && !scope.isEmpty()) { - form.param("scope", scope); - } - - Response jaxrsResponse = target.request(MediaType.APPLICATION_JSON_TYPE) - .header(HttpHeaders.AUTHORIZATION, getAuthorizationHeaderValue(clientId, clientSecret)) - .post(Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED_TYPE), Response.class); - JsonObject tokenResponse = jaxrsResponse.readEntity(JsonObject.class); - if (jaxrsResponse.getStatus() == 200) { - request.getSession().setAttribute("tokenResponse", tokenResponse); - } else { - request.setAttribute("error", tokenResponse.getString("error_description", "error!")); - } - dispatch("/", request, response); - } -} +package com.baeldung.oauth2.client; + +import org.eclipse.microprofile.config.Config; + +import javax.inject.Inject; +import javax.json.JsonObject; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.Entity; +import javax.ws.rs.client.WebTarget; +import javax.ws.rs.core.Form; +import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import java.io.IOException; + +@WebServlet(urlPatterns = "/refreshtoken") +public class RefreshTokenServlet extends AbstractServlet { + + @Inject + private Config config; + + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + + String clientId = config.getValue("client.clientId", String.class); + String clientSecret = config.getValue("client.clientSecret", String.class); + + JsonObject actualTokenResponse = (JsonObject) request.getSession().getAttribute("tokenResponse"); + Client client = ClientBuilder.newClient(); + WebTarget target = client.target(config.getValue("provider.tokenUri", String.class)); + + Form form = new Form(); + form.param("grant_type", "refresh_token"); + form.param("refresh_token", actualTokenResponse.getString("refresh_token")); + + String scope = request.getParameter("scope"); + if (scope != null && !scope.isEmpty()) { + form.param("scope", scope); + } + + Response jaxrsResponse = target.request(MediaType.APPLICATION_JSON_TYPE) + .header(HttpHeaders.AUTHORIZATION, getAuthorizationHeaderValue(clientId, clientSecret)) + .post(Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED_TYPE), Response.class); + JsonObject tokenResponse = jaxrsResponse.readEntity(JsonObject.class); + if (jaxrsResponse.getStatus() == 200) { + request.getSession().setAttribute("tokenResponse", tokenResponse); + } else { + request.setAttribute("error", tokenResponse.getString("error_description", "error!")); + } + dispatch("/", request, response); + } +} diff --git a/oauth2-framework-impl/oauth2-client/src/main/liberty/config/server.xml b/security-modules/oauth2-framework-impl/oauth2-client/src/main/liberty/config/server.xml similarity index 100% rename from oauth2-framework-impl/oauth2-client/src/main/liberty/config/server.xml rename to security-modules/oauth2-framework-impl/oauth2-client/src/main/liberty/config/server.xml diff --git a/oauth2-framework-impl/oauth2-client/src/main/resources/META-INF/microprofile-config.properties b/security-modules/oauth2-framework-impl/oauth2-client/src/main/resources/META-INF/microprofile-config.properties similarity index 100% rename from oauth2-framework-impl/oauth2-client/src/main/resources/META-INF/microprofile-config.properties rename to security-modules/oauth2-framework-impl/oauth2-client/src/main/resources/META-INF/microprofile-config.properties diff --git a/oauth2-framework-impl/oauth2-client/src/main/webapp/WEB-INF/beans.xml b/security-modules/oauth2-framework-impl/oauth2-client/src/main/webapp/WEB-INF/beans.xml similarity index 100% rename from oauth2-framework-impl/oauth2-client/src/main/webapp/WEB-INF/beans.xml rename to security-modules/oauth2-framework-impl/oauth2-client/src/main/webapp/WEB-INF/beans.xml diff --git a/oauth2-framework-impl/oauth2-client/src/main/webapp/WEB-INF/web.xml b/security-modules/oauth2-framework-impl/oauth2-client/src/main/webapp/WEB-INF/web.xml similarity index 97% rename from oauth2-framework-impl/oauth2-client/src/main/webapp/WEB-INF/web.xml rename to security-modules/oauth2-framework-impl/oauth2-client/src/main/webapp/WEB-INF/web.xml index 0203894c1b..c9e4658ab4 100644 --- a/oauth2-framework-impl/oauth2-client/src/main/webapp/WEB-INF/web.xml +++ b/security-modules/oauth2-framework-impl/oauth2-client/src/main/webapp/WEB-INF/web.xml @@ -1,5 +1,5 @@ - - - index.jsp - + + + index.jsp + \ No newline at end of file diff --git a/oauth2-framework-impl/oauth2-client/src/main/webapp/index.jsp b/security-modules/oauth2-framework-impl/oauth2-client/src/main/webapp/index.jsp similarity index 100% rename from oauth2-framework-impl/oauth2-client/src/main/webapp/index.jsp rename to security-modules/oauth2-framework-impl/oauth2-client/src/main/webapp/index.jsp diff --git a/oauth2-framework-impl/oauth2-resource-server/pom.xml b/security-modules/oauth2-framework-impl/oauth2-resource-server/pom.xml similarity index 97% rename from oauth2-framework-impl/oauth2-resource-server/pom.xml rename to security-modules/oauth2-framework-impl/oauth2-resource-server/pom.xml index d3af2cfd80..d9146c7522 100644 --- a/oauth2-framework-impl/oauth2-resource-server/pom.xml +++ b/security-modules/oauth2-framework-impl/oauth2-resource-server/pom.xml @@ -1,42 +1,42 @@ - - - 4.0.0 - oauth2-resource-server - oauth2-resource-server - war - - - com.baeldung.oauth2 - oauth2-framework-impl - 1.0-SNAPSHOT - - - - - org.eclipse.microprofile.jwt - microprofile-jwt-auth-api - ${microprofile-jwt-auth-api.version} - provided - - - - - - - net.wasdev.wlp.maven.plugins - liberty-maven-plugin - - - - - - 9280 - 8643 - http://localhost:9080 - http://localhost:9280 - 1.1 - - + + + 4.0.0 + oauth2-resource-server + oauth2-resource-server + war + + + com.baeldung.oauth2 + oauth2-framework-impl + 1.0-SNAPSHOT + + + + + org.eclipse.microprofile.jwt + microprofile-jwt-auth-api + ${microprofile-jwt-auth-api.version} + provided + + + + + + + net.wasdev.wlp.maven.plugins + liberty-maven-plugin + + + + + + 9280 + 8643 + http://localhost:9080 + http://localhost:9280 + 1.1 + + \ No newline at end of file diff --git a/oauth2-framework-impl/oauth2-resource-server/src/main/java/com/baeldung/oauth2/resource/server/OAuth2ResourceServerApplication.java b/security-modules/oauth2-framework-impl/oauth2-resource-server/src/main/java/com/baeldung/oauth2/resource/server/OAuth2ResourceServerApplication.java similarity index 100% rename from oauth2-framework-impl/oauth2-resource-server/src/main/java/com/baeldung/oauth2/resource/server/OAuth2ResourceServerApplication.java rename to security-modules/oauth2-framework-impl/oauth2-resource-server/src/main/java/com/baeldung/oauth2/resource/server/OAuth2ResourceServerApplication.java diff --git a/oauth2-framework-impl/oauth2-resource-server/src/main/java/com/baeldung/oauth2/resource/server/secure/ProtectedResource.java b/security-modules/oauth2-framework-impl/oauth2-resource-server/src/main/java/com/baeldung/oauth2/resource/server/secure/ProtectedResource.java similarity index 100% rename from oauth2-framework-impl/oauth2-resource-server/src/main/java/com/baeldung/oauth2/resource/server/secure/ProtectedResource.java rename to security-modules/oauth2-framework-impl/oauth2-resource-server/src/main/java/com/baeldung/oauth2/resource/server/secure/ProtectedResource.java diff --git a/oauth2-framework-impl/oauth2-resource-server/src/main/liberty/config/server.xml b/security-modules/oauth2-framework-impl/oauth2-resource-server/src/main/liberty/config/server.xml similarity index 100% rename from oauth2-framework-impl/oauth2-resource-server/src/main/liberty/config/server.xml rename to security-modules/oauth2-framework-impl/oauth2-resource-server/src/main/liberty/config/server.xml diff --git a/oauth2-framework-impl/oauth2-resource-server/src/main/resources/META-INF/microprofile-config.properties b/security-modules/oauth2-framework-impl/oauth2-resource-server/src/main/resources/META-INF/microprofile-config.properties similarity index 99% rename from oauth2-framework-impl/oauth2-resource-server/src/main/resources/META-INF/microprofile-config.properties rename to security-modules/oauth2-framework-impl/oauth2-resource-server/src/main/resources/META-INF/microprofile-config.properties index be6919ec50..b6811fa8a3 100644 --- a/oauth2-framework-impl/oauth2-resource-server/src/main/resources/META-INF/microprofile-config.properties +++ b/security-modules/oauth2-framework-impl/oauth2-resource-server/src/main/resources/META-INF/microprofile-config.properties @@ -1,2 +1,2 @@ -mp.jwt.verify.publickey.location=/META-INF/public-key.pem +mp.jwt.verify.publickey.location=/META-INF/public-key.pem mp.jwt.verify.issuer=http://localhost:9080 \ No newline at end of file diff --git a/oauth2-framework-impl/oauth2-resource-server/src/main/resources/META-INF/public-key.pem b/security-modules/oauth2-framework-impl/oauth2-resource-server/src/main/resources/META-INF/public-key.pem similarity index 100% rename from oauth2-framework-impl/oauth2-resource-server/src/main/resources/META-INF/public-key.pem rename to security-modules/oauth2-framework-impl/oauth2-resource-server/src/main/resources/META-INF/public-key.pem diff --git a/oauth2-framework-impl/oauth2-resource-server/src/main/webapp/WEB-INF/beans.xml b/security-modules/oauth2-framework-impl/oauth2-resource-server/src/main/webapp/WEB-INF/beans.xml similarity index 100% rename from oauth2-framework-impl/oauth2-resource-server/src/main/webapp/WEB-INF/beans.xml rename to security-modules/oauth2-framework-impl/oauth2-resource-server/src/main/webapp/WEB-INF/beans.xml diff --git a/oauth2-framework-impl/oauth2-resource-server/src/main/webapp/index.html b/security-modules/oauth2-framework-impl/oauth2-resource-server/src/main/webapp/index.html similarity index 100% rename from oauth2-framework-impl/oauth2-resource-server/src/main/webapp/index.html rename to security-modules/oauth2-framework-impl/oauth2-resource-server/src/main/webapp/index.html diff --git a/oauth2-framework-impl/pom.xml b/security-modules/oauth2-framework-impl/pom.xml similarity index 96% rename from oauth2-framework-impl/pom.xml rename to security-modules/oauth2-framework-impl/pom.xml index 5cfcb22fab..78567c14fd 100644 --- a/oauth2-framework-impl/pom.xml +++ b/security-modules/oauth2-framework-impl/pom.xml @@ -9,6 +9,12 @@ oauth2-framework-impl pom + + com.baeldung + security-modules + 1.0.0-SNAPSHOT + + oauth2-authorization-server oauth2-resource-server diff --git a/security-modules/pom.xml b/security-modules/pom.xml new file mode 100644 index 0000000000..480ee0819e --- /dev/null +++ b/security-modules/pom.xml @@ -0,0 +1,27 @@ + + + 4.0.0 + security-modules + security-modules + pom + + + com.baeldung + parent-modules + 1.0.0-SNAPSHOT + + + + apache-shiro + cas + cloud-foundry-uaa + + jee-7-security + jjwt + oauth2-framework-impl + sql-injection-samples + + + \ No newline at end of file diff --git a/software-security/sql-injection-samples/.gitignore b/security-modules/sql-injection-samples/.gitignore similarity index 100% rename from software-security/sql-injection-samples/.gitignore rename to security-modules/sql-injection-samples/.gitignore diff --git a/software-security/sql-injection-samples/README.md b/security-modules/sql-injection-samples/README.md similarity index 100% rename from software-security/sql-injection-samples/README.md rename to security-modules/sql-injection-samples/README.md diff --git a/security-modules/sql-injection-samples/derby.log b/security-modules/sql-injection-samples/derby.log new file mode 100644 index 0000000000..67eaae4238 --- /dev/null +++ b/security-modules/sql-injection-samples/derby.log @@ -0,0 +1,13 @@ +---------------------------------------------------------------- +Fri Aug 19 19:44:34 IST 2022: +Booting Derby version The Apache Software Foundation - Apache Derby - 10.14.2.0 - (1828579): instance a816c00e-0182-b674-a779-000005b040a8 +on database directory memory:E:\tutorials\security-modules\sql-injection-samples\cea8e259-4b4e-438e-8ffc-52ce09fc5b49 with class loader sun.misc.Launcher$AppClassLoader@42a57993 +Loaded from file:/C:/Users/DELL/.m2/repository/org/apache/derby/derby/10.14.2.0/derby-10.14.2.0.jar +java.vendor=Oracle Corporation +java.runtime.version=1.8.0_311-b11 +user.dir=E:\tutorials\security-modules\sql-injection-samples +os.name=Windows 10 +os.arch=amd64 +os.version=10.0 +derby.system.home=null +Database Class Loader started - derby.database.classpath='' diff --git a/software-security/sql-injection-samples/pom.xml b/security-modules/sql-injection-samples/pom.xml similarity index 100% rename from software-security/sql-injection-samples/pom.xml rename to security-modules/sql-injection-samples/pom.xml diff --git a/software-security/sql-injection-samples/src/main/java/com/baeldung/examples/security/sql/Account.java b/security-modules/sql-injection-samples/src/main/java/com/baeldung/examples/security/sql/Account.java similarity index 100% rename from software-security/sql-injection-samples/src/main/java/com/baeldung/examples/security/sql/Account.java rename to security-modules/sql-injection-samples/src/main/java/com/baeldung/examples/security/sql/Account.java diff --git a/software-security/sql-injection-samples/src/main/java/com/baeldung/examples/security/sql/AccountDAO.java b/security-modules/sql-injection-samples/src/main/java/com/baeldung/examples/security/sql/AccountDAO.java similarity index 100% rename from software-security/sql-injection-samples/src/main/java/com/baeldung/examples/security/sql/AccountDAO.java rename to security-modules/sql-injection-samples/src/main/java/com/baeldung/examples/security/sql/AccountDAO.java diff --git a/software-security/sql-injection-samples/src/main/java/com/baeldung/examples/security/sql/AccountDTO.java b/security-modules/sql-injection-samples/src/main/java/com/baeldung/examples/security/sql/AccountDTO.java similarity index 100% rename from software-security/sql-injection-samples/src/main/java/com/baeldung/examples/security/sql/AccountDTO.java rename to security-modules/sql-injection-samples/src/main/java/com/baeldung/examples/security/sql/AccountDTO.java diff --git a/software-security/sql-injection-samples/src/main/java/com/baeldung/examples/security/sql/SqlInjectionSamplesApplication.java b/security-modules/sql-injection-samples/src/main/java/com/baeldung/examples/security/sql/SqlInjectionSamplesApplication.java similarity index 100% rename from software-security/sql-injection-samples/src/main/java/com/baeldung/examples/security/sql/SqlInjectionSamplesApplication.java rename to security-modules/sql-injection-samples/src/main/java/com/baeldung/examples/security/sql/SqlInjectionSamplesApplication.java diff --git a/software-security/sql-injection-samples/src/main/resources/application.properties b/security-modules/sql-injection-samples/src/main/resources/application.properties similarity index 100% rename from software-security/sql-injection-samples/src/main/resources/application.properties rename to security-modules/sql-injection-samples/src/main/resources/application.properties diff --git a/software-security/sql-injection-samples/src/main/resources/logback.xml b/security-modules/sql-injection-samples/src/main/resources/logback.xml similarity index 100% rename from software-security/sql-injection-samples/src/main/resources/logback.xml rename to security-modules/sql-injection-samples/src/main/resources/logback.xml diff --git a/software-security/sql-injection-samples/src/test/java/com/baeldung/examples/security/sql/SqlInjectionSamplesApplicationUnitTest.java b/security-modules/sql-injection-samples/src/test/java/com/baeldung/examples/security/sql/SqlInjectionSamplesApplicationUnitTest.java similarity index 100% rename from software-security/sql-injection-samples/src/test/java/com/baeldung/examples/security/sql/SqlInjectionSamplesApplicationUnitTest.java rename to security-modules/sql-injection-samples/src/test/java/com/baeldung/examples/security/sql/SqlInjectionSamplesApplicationUnitTest.java diff --git a/software-security/sql-injection-samples/src/test/resources/application-test.yml b/security-modules/sql-injection-samples/src/test/resources/application-test.yml similarity index 100% rename from software-security/sql-injection-samples/src/test/resources/application-test.yml rename to security-modules/sql-injection-samples/src/test/resources/application-test.yml diff --git a/software-security/sql-injection-samples/src/test/resources/data.sql b/security-modules/sql-injection-samples/src/test/resources/data.sql similarity index 100% rename from software-security/sql-injection-samples/src/test/resources/data.sql rename to security-modules/sql-injection-samples/src/test/resources/data.sql diff --git a/software-security/sql-injection-samples/src/test/resources/logback-test.xml b/security-modules/sql-injection-samples/src/test/resources/logback-test.xml similarity index 100% rename from software-security/sql-injection-samples/src/test/resources/logback-test.xml rename to security-modules/sql-injection-samples/src/test/resources/logback-test.xml diff --git a/software-security/sql-injection-samples/src/test/resources/schema.sql b/security-modules/sql-injection-samples/src/test/resources/schema.sql similarity index 100% rename from software-security/sql-injection-samples/src/test/resources/schema.sql rename to security-modules/sql-injection-samples/src/test/resources/schema.sql