diff --git a/eng/versioning/version_client.txt b/eng/versioning/version_client.txt index 5b180d642ed04..2d52e3acfbe52 100644 --- a/eng/versioning/version_client.txt +++ b/eng/versioning/version_client.txt @@ -142,6 +142,8 @@ com.azure.spring:azure-spring-data-gremlin;2.3.1-beta.1;2.3.1-beta.1 com.azure.spring:azure-spring-boot-starter-data-gremlin;3.0.0-beta.1;3.0.0-beta.1 com.azure.spring:azure-spring-boot-test-aad;1.0.0;1.0.0 com.azure.spring:azure-spring-boot-test-aad-obo;1.0.0;1.0.0 +com.azure.spring:azure-spring-boot-test-aad-resource-server;1.0.0;1.0.0 +com.azure.spring:azure-spring-boot-test-aad-resource-server-by-filter;1.0.0;1.0.0 com.azure.spring:azure-spring-boot-test-core;1.0.0;1.0.0 com.azure.spring:azure-spring-boot-test-cosmosdb;1.0.0;1.0.0 com.azure.spring:azure-spring-boot-test-keyvault;1.0.0;1.0.0 diff --git a/sdk/spring/azure-spring-boot-test-aad/HOW_TO_RUN_AAD_INTEGRATION_TEST_IN_LOCALHOST.md b/sdk/spring/HOW_TO_RUN_AAD_INTEGRATION_TEST_IN_LOCALHOST.md similarity index 86% rename from sdk/spring/azure-spring-boot-test-aad/HOW_TO_RUN_AAD_INTEGRATION_TEST_IN_LOCALHOST.md rename to sdk/spring/HOW_TO_RUN_AAD_INTEGRATION_TEST_IN_LOCALHOST.md index 254a45264f197..a568f9250a413 100644 --- a/sdk/spring/azure-spring-boot-test-aad/HOW_TO_RUN_AAD_INTEGRATION_TEST_IN_LOCALHOST.md +++ b/sdk/spring/HOW_TO_RUN_AAD_INTEGRATION_TEST_IN_LOCALHOST.md @@ -60,8 +60,11 @@ Get `AAD_TENANT_ID_2`, `AAD_USER_NAME_2`, `AAD_USER_PASSWORD_2` with the same me 4. Add API permissions. Grant admin consent. ![add-api-permission](images/add-api-permission.png) + +5. Expose API: `ResourceAccessGraph.Read`, `TestScope1`, `TestScope2`. +![expose-api](images/expose-api.png) -5. Now we get value of `AAD_MULTI_TENANT_CLIENT_ID`, `AAD_MULTI_TENANT_CLIENT_SECRET`. +6. Now we get value of `AAD_MULTI_TENANT_CLIENT_ID`, `AAD_MULTI_TENANT_CLIENT_SECRET`. ### `AAD_SINGLE_TENANT_CLIENT_ID`, `AAD_SINGLE_TENANT_CLIENT_SECRET` Get `AAD_SINGLE_TENANT_CLIENT_ID`, `AAD_SINGLE_TENANT_CLIENT_SECRET` with the same method. @@ -102,10 +105,22 @@ $env:AAD_SINGLE_TENANT_CLIENT_SECRET_WITH_ROLE='xxxxxxxx' ``` ## Run AAD integration test by maven. -Command: +azure-spring-boot-test-aad: ``` mvn -f .\sdk\spring\azure-spring-boot-test-aad\pom.xml --fail-at-end "-Dmaven.javadoc.skip=true" "-Drevapi.skip=true" "-DskipSpringITs=false" verify ``` +azure-spring-boot-test-aad-obo: +``` +mvn -f .\sdk\spring\azure-spring-boot-test-aad-obo\pom.xml --fail-at-end "-Dmaven.javadoc.skip=true" "-Drevapi.skip=true" "-DskipSpringITs=false" verify +``` +azure-spring-boot-test-aad-resource-server: +``` +mvn -f .\sdk\spring\azure-spring-boot-test-aad-resource-server\pom.xml --fail-at-end "-Dmaven.javadoc.skip=true" "-Drevapi.skip=true" "-DskipSpringITs=false" verify +``` +azure-spring-boot-test-aad-resource-server-by-filter: +``` +mvn -f .\sdk\spring\azure-spring-boot-test-aad-resource-server-by-filter\pom.xml --fail-at-end "-Dmaven.javadoc.skip=true" "-Drevapi.skip=true" "-DskipSpringITs=false" verify +``` [Create a new tenant in Azure Active Directory]: https://docs.microsoft.com/azure/active-directory/fundamentals/active-directory-access-create-new-tenant diff --git a/sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-stateless/README.md b/sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-by-filter-stateless/README.md similarity index 98% rename from sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-stateless/README.md rename to sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-by-filter-stateless/README.md index 08d21c5bf65d7..332332db72b68 100644 --- a/sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-stateless/README.md +++ b/sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-by-filter-stateless/README.md @@ -91,7 +91,7 @@ data: { ### Run with Maven ```shell -cd azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-stateless +cd azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-by-filter-stateless mvn spring-boot:run ``` diff --git a/sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-stateless/docs/demo.webp b/sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-by-filter-stateless/docs/demo.webp similarity index 100% rename from sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-stateless/docs/demo.webp rename to sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-by-filter-stateless/docs/demo.webp diff --git a/sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-stateless/pom.xml b/sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-by-filter-stateless/pom.xml similarity index 97% rename from sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-stateless/pom.xml rename to sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-by-filter-stateless/pom.xml index 040dce199fece..bb3fcfeb02450 100644 --- a/sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-stateless/pom.xml +++ b/sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-by-filter-stateless/pom.xml @@ -11,7 +11,7 @@ com.azure.spring - azure-spring-boot-sample-active-directory-resource-server-stateless + azure-spring-boot-sample-active-directory-resource-server-by-filter-stateless 1.0.0 Azure Spring Boot Starter Sample - Azure AD Stateless Spring Security Integration diff --git a/sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-stateless/src/main/java/com/azure/spring/sample/aad/AzureADStatelessBackendSampleApplication.java b/sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-by-filter-stateless/src/main/java/com/azure/spring/sample/aad/AzureADStatelessBackendSampleApplication.java similarity index 100% rename from sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-stateless/src/main/java/com/azure/spring/sample/aad/AzureADStatelessBackendSampleApplication.java rename to sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-by-filter-stateless/src/main/java/com/azure/spring/sample/aad/AzureADStatelessBackendSampleApplication.java diff --git a/sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-stateless/src/main/java/com/azure/spring/sample/aad/controller/MainController.java b/sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-by-filter-stateless/src/main/java/com/azure/spring/sample/aad/controller/MainController.java similarity index 100% rename from sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-stateless/src/main/java/com/azure/spring/sample/aad/controller/MainController.java rename to sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-by-filter-stateless/src/main/java/com/azure/spring/sample/aad/controller/MainController.java diff --git a/sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-stateless/src/main/java/com/azure/spring/sample/aad/security/AADWebSecurityConfig.java b/sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-by-filter-stateless/src/main/java/com/azure/spring/sample/aad/security/AADWebSecurityConfig.java similarity index 100% rename from sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-stateless/src/main/java/com/azure/spring/sample/aad/security/AADWebSecurityConfig.java rename to sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-by-filter-stateless/src/main/java/com/azure/spring/sample/aad/security/AADWebSecurityConfig.java diff --git a/sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-stateless/src/main/resources/application.properties b/sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-by-filter-stateless/src/main/resources/application.properties similarity index 100% rename from sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-stateless/src/main/resources/application.properties rename to sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-by-filter-stateless/src/main/resources/application.properties diff --git a/sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-stateless/src/main/resources/static/index.html b/sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-by-filter-stateless/src/main/resources/static/index.html similarity index 100% rename from sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-stateless/src/main/resources/static/index.html rename to sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-by-filter-stateless/src/main/resources/static/index.html diff --git a/sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-with-filter/README.md b/sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-by-filter/README.md similarity index 98% rename from sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-with-filter/README.md rename to sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-by-filter/README.md index 8ec91c5cc8384..f8a5734ef58e7 100644 --- a/sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-with-filter/README.md +++ b/sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-by-filter/README.md @@ -37,7 +37,7 @@ From your command line: ```command line git clone https://github.com/Azure/azure-sdk-for-java.git ``` -or download and extract the repository .zip file, and navigate to `azure-spring-boot-sample-active-directory-resource-server-with-filter` from the list of samples. +or download and extract the repository .zip file, and navigate to `azure-spring-boot-sample-active-directory-resource-server-by-filter` from the list of samples. --- ### Step 2: Register the sample with your Azure Active Directory tenant @@ -140,7 +140,7 @@ msalProvider.init( * Run with Maven ``` - cd azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-with-filter + cd azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-by-filter mvn spring-boot:run ``` diff --git a/sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-with-filter/pom.xml b/sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-by-filter/pom.xml similarity index 97% rename from sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-with-filter/pom.xml rename to sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-by-filter/pom.xml index 19991f2e3ab28..b92d09c76d922 100644 --- a/sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-with-filter/pom.xml +++ b/sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-by-filter/pom.xml @@ -10,7 +10,7 @@ com.azure.spring - azure-spring-boot-sample-active-directory-resource-server-with-filter + azure-spring-boot-sample-active-directory-resource-server-by-filter 1.0.0 jar diff --git a/sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-with-filter/src/main/java/com/azure/spring/sample/aad/AzureAdIntegrationSpringBootAutoconfigureSampleApplication.java b/sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-by-filter/src/main/java/com/azure/spring/sample/aad/AzureAdIntegrationSpringBootAutoconfigureSampleApplication.java similarity index 100% rename from sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-with-filter/src/main/java/com/azure/spring/sample/aad/AzureAdIntegrationSpringBootAutoconfigureSampleApplication.java rename to sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-by-filter/src/main/java/com/azure/spring/sample/aad/AzureAdIntegrationSpringBootAutoconfigureSampleApplication.java diff --git a/sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-with-filter/src/main/java/com/azure/spring/sample/aad/controller/TodoListController.java b/sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-by-filter/src/main/java/com/azure/spring/sample/aad/controller/TodoListController.java similarity index 100% rename from sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-with-filter/src/main/java/com/azure/spring/sample/aad/controller/TodoListController.java rename to sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-by-filter/src/main/java/com/azure/spring/sample/aad/controller/TodoListController.java diff --git a/sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-with-filter/src/main/java/com/azure/spring/sample/aad/model/TodoItem.java b/sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-by-filter/src/main/java/com/azure/spring/sample/aad/model/TodoItem.java similarity index 100% rename from sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-with-filter/src/main/java/com/azure/spring/sample/aad/model/TodoItem.java rename to sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-by-filter/src/main/java/com/azure/spring/sample/aad/model/TodoItem.java diff --git a/sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-with-filter/src/main/java/com/azure/spring/sample/aad/security/WebSecurityConfig.java b/sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-by-filter/src/main/java/com/azure/spring/sample/aad/security/WebSecurityConfig.java similarity index 100% rename from sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-with-filter/src/main/java/com/azure/spring/sample/aad/security/WebSecurityConfig.java rename to sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-by-filter/src/main/java/com/azure/spring/sample/aad/security/WebSecurityConfig.java diff --git a/sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-with-filter/src/main/resources/application.properties b/sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-by-filter/src/main/resources/application.properties similarity index 100% rename from sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-with-filter/src/main/resources/application.properties rename to sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-by-filter/src/main/resources/application.properties diff --git a/sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-with-filter/src/main/resources/static/App/Scripts/app.js b/sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-by-filter/src/main/resources/static/App/Scripts/app.js similarity index 100% rename from sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-with-filter/src/main/resources/static/App/Scripts/app.js rename to sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-by-filter/src/main/resources/static/App/Scripts/app.js diff --git a/sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-with-filter/src/main/resources/static/App/Scripts/homeCtrl.js b/sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-by-filter/src/main/resources/static/App/Scripts/homeCtrl.js similarity index 100% rename from sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-with-filter/src/main/resources/static/App/Scripts/homeCtrl.js rename to sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-by-filter/src/main/resources/static/App/Scripts/homeCtrl.js diff --git a/sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-with-filter/src/main/resources/static/App/Scripts/indexCtrl.js b/sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-by-filter/src/main/resources/static/App/Scripts/indexCtrl.js similarity index 100% rename from sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-with-filter/src/main/resources/static/App/Scripts/indexCtrl.js rename to sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-by-filter/src/main/resources/static/App/Scripts/indexCtrl.js diff --git a/sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-with-filter/src/main/resources/static/App/Scripts/msal.js b/sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-by-filter/src/main/resources/static/App/Scripts/msal.js similarity index 100% rename from sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-with-filter/src/main/resources/static/App/Scripts/msal.js rename to sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-by-filter/src/main/resources/static/App/Scripts/msal.js diff --git a/sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-with-filter/src/main/resources/static/App/Scripts/msalModule.js b/sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-by-filter/src/main/resources/static/App/Scripts/msalModule.js similarity index 100% rename from sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-with-filter/src/main/resources/static/App/Scripts/msalModule.js rename to sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-by-filter/src/main/resources/static/App/Scripts/msalModule.js diff --git a/sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-with-filter/src/main/resources/static/App/Scripts/todoListCtrl.js b/sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-by-filter/src/main/resources/static/App/Scripts/todoListCtrl.js similarity index 100% rename from sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-with-filter/src/main/resources/static/App/Scripts/todoListCtrl.js rename to sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-by-filter/src/main/resources/static/App/Scripts/todoListCtrl.js diff --git a/sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-with-filter/src/main/resources/static/App/Scripts/todoListSvc.js b/sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-by-filter/src/main/resources/static/App/Scripts/todoListSvc.js similarity index 100% rename from sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-with-filter/src/main/resources/static/App/Scripts/todoListSvc.js rename to sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-by-filter/src/main/resources/static/App/Scripts/todoListSvc.js diff --git a/sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-with-filter/src/main/resources/static/App/Scripts/userDataCtrl.js b/sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-by-filter/src/main/resources/static/App/Scripts/userDataCtrl.js similarity index 100% rename from sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-with-filter/src/main/resources/static/App/Scripts/userDataCtrl.js rename to sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-by-filter/src/main/resources/static/App/Scripts/userDataCtrl.js diff --git a/sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-with-filter/src/main/resources/static/App/Views/Home.html b/sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-by-filter/src/main/resources/static/App/Views/Home.html similarity index 100% rename from sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-with-filter/src/main/resources/static/App/Views/Home.html rename to sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-by-filter/src/main/resources/static/App/Views/Home.html diff --git a/sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-with-filter/src/main/resources/static/App/Views/TodoList.html b/sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-by-filter/src/main/resources/static/App/Views/TodoList.html similarity index 100% rename from sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-with-filter/src/main/resources/static/App/Views/TodoList.html rename to sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-by-filter/src/main/resources/static/App/Views/TodoList.html diff --git a/sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-with-filter/src/main/resources/static/App/Views/UserData.html b/sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-by-filter/src/main/resources/static/App/Views/UserData.html similarity index 100% rename from sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-with-filter/src/main/resources/static/App/Views/UserData.html rename to sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-by-filter/src/main/resources/static/App/Views/UserData.html diff --git a/sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-with-filter/src/main/resources/static/index.html b/sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-by-filter/src/main/resources/static/index.html similarity index 100% rename from sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-with-filter/src/main/resources/static/index.html rename to sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-by-filter/src/main/resources/static/index.html diff --git a/sdk/spring/azure-spring-boot-starter-active-directory/README.md b/sdk/spring/azure-spring-boot-starter-active-directory/README.md index 2ab516a86737a..cd555eea1f6b8 100644 --- a/sdk/spring/azure-spring-boot-starter-active-directory/README.md +++ b/sdk/spring/azure-spring-boot-starter-active-directory/README.md @@ -16,7 +16,7 @@ With Spring Starter for Azure Active Directory, now you can get started quickly * **Create a client secret key for the application**: Go to API ACCESS - Keys to create a secret key (`client-secret`). ### Include the package -To use this starter in an web application, please add following packages: +To use this starter in a web application, please add following packages: [//]: # "{x-version-update-start;com.azure.spring:azure-spring-boot-starter-active-directory;current}" ```xml @@ -26,13 +26,13 @@ To use this starter in an web application, please add following packages: 3.2.0-beta.1 - org.springframework.security - spring-security-oauth2-client + org.springframework.boot + spring-boot-starter-oauth2-client ``` [//]: # "{x-version-update-end}" -To use this starter in a resource server, please add following packages: +To use this starter in a resource server without OBO function, please add following packages: [//]: # "{x-version-update-start;com.azure.spring:azure-spring-boot-starter-active-directory;current}" ```xml @@ -42,12 +42,28 @@ To use this starter in a resource server, please add following packages: 3.2.0-beta.1 - org.springframework.security - spring-security-oauth2-client + org.springframework.boot + spring-boot-starter-oauth2-resource-server + +``` +[//]: # "{x-version-update-end}" + +To use this starter in a resource server with OBO function, please add following packages: + +[//]: # "{x-version-update-start;com.azure.spring:azure-spring-boot-starter-active-directory;current}" +```xml + + com.azure.spring + azure-spring-boot-starter-active-directory + 3.0.0-beta.1 + + + org.springframework.boot + spring-boot-starter-oauth2-resource-server - org.springframework.security - spring-security-oauth2-resource-server + org.springframework.boot + spring-boot-starter-oauth2-client ``` [//]: # "{x-version-update-end}" @@ -299,7 +315,7 @@ azure: ``` ### Authenticate in web APIs [Web APIs] -Please refer to [azure-spring-boot-sample-active-directory-resource-server-with-filter] for how to integrate Spring Security and Azure AD for authentication and authorization in a Single Page Application (SPA) scenario. +Please refer to [azure-spring-boot-sample-active-directory-resource-server-by-filter] for how to integrate Spring Security and Azure AD for authentication and authorization in a Single Page Application (SPA) scenario. #### Configure application.yml: ```yaml @@ -402,7 +418,7 @@ The following section provides sample projects illustrating how to use the start - [Azure Active Directory for Web apps][azure-spring-boot-sample-active-directory-webapp] - [Azure Active Directory for Web APIs][azure-spring-boot-sample-active-directory-resource-server] - [Azure Active Directory for On-Behalf-Of flow][azure-spring-boot-sample-active-directory-resource-server-obo] -- [Azure Active Directory for Resource Server with Filter(Deprecated)][azure-spring-boot-sample-active-directory-resource-server-with-filter] +- [Azure Active Directory for Resource Server by Filter(Deprecated)][azure-spring-boot-sample-active-directory-resource-server-by-filter] ## Contributing This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com. @@ -414,7 +430,7 @@ Please follow [instructions here] to build from source or contribute. [azure-spring-boot-sample-active-directory-webapp]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-webapp [azure-spring-boot-sample-active-directory-resource-server]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server/README.md [azure-spring-boot-sample-active-directory-resource-server-obo]: https://github.com/ZhuXiaoBing-cn/azure-sdk-for-java/tree/master/sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-obo -[azure-spring-boot-sample-active-directory-resource-server-with-filter]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-with-filter +[azure-spring-boot-sample-active-directory-resource-server-by-filter]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-by-filter [AAD App Roles feature]: https://docs.microsoft.com/azure/architecture/multitenant-identity/app-roles#roles-using-azure-ad-app-roles [client credentials grant flow]: https://docs.microsoft.com/azure/active-directory/develop/v1-oauth2-client-creds-grant-flow [configured in your manifest]: https://docs.microsoft.com/azure/active-directory/develop/howto-add-app-roles-in-azure-ad-apps#examples diff --git a/sdk/spring/azure-spring-boot-starter/README.md b/sdk/spring/azure-spring-boot-starter/README.md index f2e2f864f6275..ba683d385646e 100644 --- a/sdk/spring/azure-spring-boot-starter/README.md +++ b/sdk/spring/azure-spring-boot-starter/README.md @@ -27,7 +27,7 @@ This starter brings auto configuration code for all Azure Spring modules, but to ## Examples The following section provides sample projects illustrating how to use the Azure Spring Boot starters. ### More sample code -- [Azure Active Directory for Resource Server with Filter(Deprecated)](https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-with-filter) +- [Azure Active Directory for Resource Server by Filter(Deprecated)](https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-by-filter) - [Azure Active Directory for Web Application](https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-webapp) - [Azure Active Directory B2C](https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-b2c-oidc) - [Cosmos DB SQL API](https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-cosmos) @@ -57,7 +57,7 @@ For more information about setting logging in spring, please refer to the [offic ## Next steps The following section provides sample projects illustrating how to use the Azure Spring Boot starters. ### More sample code -- [Azure Active Directory for Resource Server with Filter(Deprecated)](https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-with-filter) +- [Azure Active Directory for Resource Server by Filter(Deprecated)](https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-by-filter) - [Azure Active Directory for Web Application](https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-webapp) - [Azure Active Directory B2C](https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-b2c-oidc) - [Cosmos DB SQL API](https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-cosmos) diff --git a/sdk/spring/azure-spring-boot-test-aad-obo/pom.xml b/sdk/spring/azure-spring-boot-test-aad-obo/pom.xml index 6e1b42bfe23f5..2d10e275df57d 100644 --- a/sdk/spring/azure-spring-boot-test-aad-obo/pom.xml +++ b/sdk/spring/azure-spring-boot-test-aad-obo/pom.xml @@ -15,32 +15,37 @@ 1.0.0 - - com.azure.spring - azure-spring-boot-test-core - 1.0.0 - com.azure.spring azure-spring-boot-starter-active-directory 3.2.0-beta.1 + + - org.springframework.security - spring-security-oauth2-resource-server + org.springframework.boot + spring-boot-starter-oauth2-client org.springframework.boot - spring-boot-starter-test - test + spring-boot-starter-oauth2-resource-server org.springframework.boot spring-boot-starter-web + + + + com.azure.spring + azure-spring-boot-test-core + 1.0.0 + test + org.springframework.boot - spring-boot-starter-oauth2-client + spring-boot-starter-test + test diff --git a/sdk/spring/azure-spring-boot-test-aad-obo/src/test/java/com/azure/test/aad/webapi/AADWebApiOboIT.java b/sdk/spring/azure-spring-boot-test-aad-obo/src/test/java/com/azure/test/aad/webapi/AADWebApiOboIT.java index 205e757d069b1..346cb152eda7a 100644 --- a/sdk/spring/azure-spring-boot-test-aad-obo/src/test/java/com/azure/test/aad/webapi/AADWebApiOboIT.java +++ b/sdk/spring/azure-spring-boot-test-aad-obo/src/test/java/com/azure/test/aad/webapi/AADWebApiOboIT.java @@ -3,20 +3,15 @@ package com.azure.test.aad.webapi; -import com.azure.test.oauth.OAuthResponse; -import com.azure.test.oauth.OAuthUtils; -import com.azure.test.utils.AppRunner; +import com.azure.spring.test.aad.AADWebApiITHelper; +import com.azure.spring.test.AppRunner; +import org.junit.Before; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.Bean; -import org.springframework.http.HttpEntity; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpMethod; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; import org.springframework.security.config.annotation.web.builders.HttpSecurity; @@ -34,56 +29,49 @@ import org.springframework.security.oauth2.client.web.reactive.function.client.ServletOAuth2AuthorizedClientExchangeFilterFunction; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; -import org.springframework.web.client.RestTemplate; import org.springframework.web.reactive.function.client.WebClient; +import java.util.Collections; import java.util.HashMap; +import java.util.Map; import java.util.function.Consumer; -import static com.azure.test.oauth.OAuthUtils.AAD_MULTI_TENANT_CLIENT_ID; -import static com.azure.test.oauth.OAuthUtils.AAD_MULTI_TENANT_CLIENT_SECRET; +import static com.azure.spring.test.aad.EnvironmentVariables.AAD_MULTI_TENANT_CLIENT_ID; +import static com.azure.spring.test.aad.EnvironmentVariables.AAD_MULTI_TENANT_CLIENT_SECRET; +import static com.azure.spring.test.aad.EnvironmentVariables.MULTI_TENANT_SCOPE_GRAPH_READ; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; import static org.springframework.security.oauth2.client.web.reactive.function.client.ServletOAuth2AuthorizedClientExchangeFilterFunction.oauth2AuthorizedClient; public class AADWebApiOboIT { private static final Logger LOGGER = LoggerFactory.getLogger(AADWebApiOboIT.class); - private static final String GRAPH_ME_ENDPOINT = "https://graph.microsoft.com/v1.0/me"; - private final RestTemplate restTemplate = new RestTemplate(); + private AADWebApiITHelper aadWebApiITHelper; + + @Before + public void init() { + Map properties = new HashMap<>(); + properties.put("azure.activedirectory.client-id", AAD_MULTI_TENANT_CLIENT_ID); + properties.put("azure.activedirectory.client-secret", AAD_MULTI_TENANT_CLIENT_SECRET); + properties.put("azure.activedirectory.app-id-uri", "api://" + AAD_MULTI_TENANT_CLIENT_ID); + properties.put("azure.activedirectory.authorization-clients.graph.scopes", + "https://graph.microsoft.com/User.Read"); + aadWebApiITHelper = new AADWebApiITHelper( + DumbApp.class, + properties, + AAD_MULTI_TENANT_CLIENT_ID, + AAD_MULTI_TENANT_CLIENT_SECRET, + Collections.singletonList(MULTI_TENANT_SCOPE_GRAPH_READ)); + } @Test public void testCallGraph() { - this.runApp(app -> { - final OAuthResponse authResponse = OAuthUtils.executeOAuth2ROPCFlow( - System.getenv(AAD_MULTI_TENANT_CLIENT_ID), System.getenv(AAD_MULTI_TENANT_CLIENT_SECRET)); - assertNotNull(authResponse); - - final HttpHeaders headers = new HttpHeaders(); - headers.set("Authorization", String.format("Bearer %s", authResponse.getAccessToken())); - HttpEntity entity = new HttpEntity<>(headers); - final ResponseEntity response = restTemplate.exchange( - app.root() + "/call-graph", - HttpMethod.GET, - entity, - String.class, - new HashMap<>() - ); - assertEquals(HttpStatus.OK, response.getStatusCode()); - assertEquals("Graph response success.", response.getBody()); - }); + assertEquals("Graph response success.", aadWebApiITHelper.httpGetStringByAccessToken("call-graph")); } private void runApp(Consumer command) { try (AppRunner app = new AppRunner(AADWebApiOboIT.DumbApp.class)) { - final String clientId = System.getenv(AAD_MULTI_TENANT_CLIENT_ID); - final String clientSecret = System.getenv(AAD_MULTI_TENANT_CLIENT_SECRET); - app.property("azure.activedirectory.client-id", clientId); - app.property("azure.activedirectory.client-secret", clientSecret); - app.property("azure.activedirectory.app-id-uri", "api://" + clientId); - app.property("azure.activedirectory.authorization-clients.graph.scopes", "https://graph.microsoft.com/User.Read"); app.start(); command.accept(app); } diff --git a/sdk/spring/azure-spring-boot-test-aad-obo/src/test/java/com/azure/test/oauth/OAuthResponse.java b/sdk/spring/azure-spring-boot-test-aad-obo/src/test/java/com/azure/test/oauth/OAuthResponse.java deleted file mode 100644 index 484e08bb65990..0000000000000 --- a/sdk/spring/azure-spring-boot-test-aad-obo/src/test/java/com/azure/test/oauth/OAuthResponse.java +++ /dev/null @@ -1,75 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -package com.azure.test.oauth; - -import com.fasterxml.jackson.databind.PropertyNamingStrategy; -import com.fasterxml.jackson.databind.annotation.JsonNaming; - -@JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class) -public class OAuthResponse { - - private String tokenType; - private String scope; - private long expiresIn; - private long extExpiresIn; - private String accessToken; - private String refreshToken; - private String idToken; - - public String getTokenType() { - return tokenType; - } - - public void setTokenType(String tokenType) { - this.tokenType = tokenType; - } - - public String getScope() { - return scope; - } - - public void setScope(String scope) { - this.scope = scope; - } - - public long getExpiresIn() { - return expiresIn; - } - - public void setExpiresIn(long expiresIn) { - this.expiresIn = expiresIn; - } - - public long getExtExpiresIn() { - return extExpiresIn; - } - - public void setExtExpiresIn(long extExpiresIn) { - this.extExpiresIn = extExpiresIn; - } - - public String getAccessToken() { - return accessToken; - } - - public void setAccessToken(String accessToken) { - this.accessToken = accessToken; - } - - public String getRefreshToken() { - return refreshToken; - } - - public void setRefreshToken(String refreshToken) { - this.refreshToken = refreshToken; - } - - public String getIdToken() { - return idToken; - } - - public void setIdToken(String idToken) { - this.idToken = idToken; - } -} diff --git a/sdk/spring/azure-spring-boot-test-aad-obo/src/test/java/com/azure/test/oauth/OAuthUtils.java b/sdk/spring/azure-spring-boot-test-aad-obo/src/test/java/com/azure/test/oauth/OAuthUtils.java deleted file mode 100644 index c13309e64ae57..0000000000000 --- a/sdk/spring/azure-spring-boot-test-aad-obo/src/test/java/com/azure/test/oauth/OAuthUtils.java +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -package com.azure.test.oauth; - -import org.springframework.http.HttpEntity; -import org.springframework.http.HttpHeaders; -import org.springframework.util.LinkedMultiValueMap; -import org.springframework.util.MultiValueMap; -import org.springframework.web.client.RestTemplate; - -import static org.springframework.http.MediaType.APPLICATION_FORM_URLENCODED; - -public class OAuthUtils { - public static final String AAD_MULTI_TENANT_CLIENT_ID = "AAD_MULTI_TENANT_CLIENT_ID"; - public static final String AAD_MULTI_TENANT_CLIENT_SECRET = "AAD_MULTI_TENANT_CLIENT_SECRET"; - public static final String AAD_TENANT_ID_1 = "AAD_TENANT_ID_1"; - public static final String AAD_USER_NAME_1 = "AAD_USER_NAME_1"; - public static final String AAD_USER_PASSWORD_1 = "AAD_USER_PASSWORD_1"; - - private static final RestTemplate CLIENT = new RestTemplate(); - - public static OAuthResponse executeOAuth2ROPCFlow(String aadClientId, String aadClientSecret) { - final String aadUsername = System.getenv(AAD_USER_NAME_1); - final String aadUserPassword = System.getenv(AAD_USER_PASSWORD_1); - final String tenantId = System.getenv(AAD_TENANT_ID_1); - - assertNotEmpty(aadClientId, "client id"); - assertNotEmpty(aadClientSecret, "client secret"); - assertNotEmpty(aadUsername, AAD_USER_NAME_1); - assertNotEmpty(aadUserPassword, AAD_USER_PASSWORD_1); - - HttpHeaders headers = new HttpHeaders(); - headers.setContentType(APPLICATION_FORM_URLENCODED); - - MultiValueMap requestBody = new LinkedMultiValueMap<>(); - requestBody.add("scope", "api://" + aadClientId + "/ResourceAccessGraph.Read"); - requestBody.add("grant_type", "password"); - requestBody.add("client_id", aadClientId); - requestBody.add("client_secret", aadClientSecret); - requestBody.add("username", aadUsername); - requestBody.add("password", aadUserPassword); - - String url = String.format("https://login.microsoftonline.com/%s/oauth2/v2.0/token", tenantId); - - HttpEntity> requestEntity = new HttpEntity<>(requestBody, headers); - - return CLIENT.postForObject(url, requestEntity, OAuthResponse.class); - } - - private static void assertNotEmpty(String text, String key) { - if (text == null || text.isEmpty()) { - throw new IllegalArgumentException(String.format("%s is not set!", key)); - } - } -} diff --git a/sdk/spring/azure-spring-boot-test-aad-resource-server-by-filter/CHANGELOG.md b/sdk/spring/azure-spring-boot-test-aad-resource-server-by-filter/CHANGELOG.md new file mode 100644 index 0000000000000..3bae488de73c9 --- /dev/null +++ b/sdk/spring/azure-spring-boot-test-aad-resource-server-by-filter/CHANGELOG.md @@ -0,0 +1,3 @@ +# Release History + +## 1.0.0 (Unreleased) diff --git a/sdk/spring/azure-spring-boot-test-aad-resource-server-by-filter/README.md b/sdk/spring/azure-spring-boot-test-aad-resource-server-by-filter/README.md new file mode 100644 index 0000000000000..bc18d9e9c993c --- /dev/null +++ b/sdk/spring/azure-spring-boot-test-aad-resource-server-by-filter/README.md @@ -0,0 +1,8 @@ +# Azure Spring Boot Integration tests client library for Java + +## Key concepts +## Getting started +## Examples +## Troubleshooting +## Next steps +## Contributing diff --git a/sdk/spring/azure-spring-boot-test-aad-resource-server-by-filter/pom.xml b/sdk/spring/azure-spring-boot-test-aad-resource-server-by-filter/pom.xml new file mode 100644 index 0000000000000..aab79926ac53a --- /dev/null +++ b/sdk/spring/azure-spring-boot-test-aad-resource-server-by-filter/pom.xml @@ -0,0 +1,60 @@ + + + + org.springframework.boot + spring-boot-starter-parent + 2.3.7.RELEASE + + + 4.0.0 + + com.azure.spring + azure-spring-boot-test-aad-resource-server-by-filter + 1.0.0 + + + + com.azure.spring + azure-spring-boot-starter-active-directory + 3.2.0-beta.1 + + + + + org.springframework.boot + spring-boot-starter-web + + + + + com.azure.spring + azure-spring-boot-test-core + 1.0.0 + test + + + org.springframework.boot + spring-boot-starter-test + test + + + + + true + + + + + + org.apache.maven.plugins + maven-failsafe-plugin + 2.22.0 + + ${skipSpringITs} + + + + + diff --git a/sdk/spring/azure-spring-boot-test-aad/src/test/java/com/azure/test/aad/filter/group/count/AADGroupsCountIT.java b/sdk/spring/azure-spring-boot-test-aad-resource-server-by-filter/src/test/java/com/azure/test/aad/filter/group/count/AADGroupsCountIT.java similarity index 57% rename from sdk/spring/azure-spring-boot-test-aad/src/test/java/com/azure/test/aad/filter/group/count/AADGroupsCountIT.java rename to sdk/spring/azure-spring-boot-test-aad-resource-server-by-filter/src/test/java/com/azure/test/aad/filter/group/count/AADGroupsCountIT.java index e8d7ee8702512..4505b8e99ef18 100644 --- a/sdk/spring/azure-spring-boot-test-aad/src/test/java/com/azure/test/aad/filter/group/count/AADGroupsCountIT.java +++ b/sdk/spring/azure-spring-boot-test-aad-resource-server-by-filter/src/test/java/com/azure/test/aad/filter/group/count/AADGroupsCountIT.java @@ -3,17 +3,13 @@ package com.azure.test.aad.filter.group.count; +import com.azure.spring.test.aad.AADWebApiITHelper; import com.azure.spring.autoconfigure.aad.AADAuthenticationFilter; import com.azure.spring.autoconfigure.aad.UserPrincipal; -import com.azure.test.aad.AADTestUtils; -import com.azure.test.aad.filter.OAuthResponse; -import com.azure.test.utils.AppRunner; +import org.junit.Before; import org.junit.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.http.HttpEntity; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpMethod; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; @@ -23,46 +19,39 @@ import org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; -import org.springframework.web.client.RestTemplate; +import java.util.Collections; import java.util.HashMap; +import java.util.Map; import java.util.Optional; import java.util.Set; -import static com.azure.test.aad.AADTestUtils.AAD_SINGLE_TENANT_CLIENT_ID; -import static com.azure.test.aad.AADTestUtils.AAD_SINGLE_TENANT_CLIENT_SECRET; +import static com.azure.spring.test.aad.EnvironmentVariables.AAD_MULTI_TENANT_CLIENT_ID; +import static com.azure.spring.test.aad.EnvironmentVariables.AAD_MULTI_TENANT_CLIENT_SECRET; +import static com.azure.spring.test.aad.EnvironmentVariables.MULTI_TENANT_SCOPE_GRAPH_READ; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; public class AADGroupsCountIT { - private final RestTemplate restTemplate = new RestTemplate(); + private AADWebApiITHelper aadWebApiITHelper; + + @Before + public void init() { + Map properties = new HashMap<>(); + properties.put("azure.activedirectory.client-id", AAD_MULTI_TENANT_CLIENT_ID); + properties.put("azure.activedirectory.client-secret", AAD_MULTI_TENANT_CLIENT_SECRET); + properties.put("azure.activedirectory.user-group.allowed-groups", "group1,group2"); + aadWebApiITHelper = new AADWebApiITHelper( + DumbApp.class, + properties, + AAD_MULTI_TENANT_CLIENT_ID, + AAD_MULTI_TENANT_CLIENT_SECRET, + Collections.singletonList(MULTI_TENANT_SCOPE_GRAPH_READ)); + } @Test public void testGroupsCount() { - final String clientId = System.getenv(AAD_SINGLE_TENANT_CLIENT_ID); - final String clientSecret = System.getenv(AAD_SINGLE_TENANT_CLIENT_SECRET); - final OAuthResponse authResponse = AADTestUtils.executeOAuth2ROPCFlow(clientId, clientSecret); - assertNotNull(authResponse); - String idToken = authResponse.getIdToken(); - try (AppRunner app = new AppRunner(DumbApp.class)) { - app.property("azure.activedirectory.client-id", clientId); - app.property("azure.activedirectory.client-secret", clientSecret); - app.property("azure.activedirectory.user-group.allowed-groups", "group1,group2"); - app.start(); - final HttpHeaders headers = new HttpHeaders(); - headers.set("Authorization", String.format("Bearer %s", idToken)); - HttpEntity entity = new HttpEntity<>(headers); - final ResponseEntity response = restTemplate.exchange( - app.root() + "api/groupsCount", - HttpMethod.GET, - entity, - String.class, - new HashMap<>() - ); - assertEquals(HttpStatus.OK, response.getStatusCode()); - assertEquals("111", response.getBody()); - } + assertEquals("111", aadWebApiITHelper.httpGetStringByAccessToken("api/groupsCount")); } @EnableGlobalMethodSecurity(securedEnabled = true, prePostEnabled = true) diff --git a/sdk/spring/azure-spring-boot-test-aad-resource-server-by-filter/src/test/java/com/azure/test/aad/filter/stateful/AADAuthenticationFilterIT.java b/sdk/spring/azure-spring-boot-test-aad-resource-server-by-filter/src/test/java/com/azure/test/aad/filter/stateful/AADAuthenticationFilterIT.java new file mode 100644 index 0000000000000..15a4e78472cc0 --- /dev/null +++ b/sdk/spring/azure-spring-boot-test-aad-resource-server-by-filter/src/test/java/com/azure/test/aad/filter/stateful/AADAuthenticationFilterIT.java @@ -0,0 +1,152 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.test.aad.filter.stateful; + +import com.azure.spring.autoconfigure.aad.AADAuthenticationFilter; +import com.azure.spring.test.aad.AADWebApiITHelper; +import org.junit.Before; +import org.junit.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; +import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; +import org.springframework.security.web.csrf.CookieCsrfTokenRepository; +import org.springframework.security.web.util.matcher.AntPathRequestMatcher; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.client.HttpClientErrorException; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +import static com.azure.spring.test.aad.EnvironmentVariables.AAD_MULTI_TENANT_CLIENT_ID; +import static com.azure.spring.test.aad.EnvironmentVariables.AAD_MULTI_TENANT_CLIENT_SECRET; +import static com.azure.spring.test.aad.EnvironmentVariables.AAD_SINGLE_TENANT_CLIENT_ID; +import static com.azure.spring.test.aad.EnvironmentVariables.AAD_SINGLE_TENANT_CLIENT_SECRET; +import static com.azure.spring.test.aad.EnvironmentVariables.SCOPE_GRAPH_READ; +import static com.azure.spring.test.aad.EnvironmentVariables.toFullNameScope; +import static org.junit.Assert.assertEquals; + +public class AADAuthenticationFilterIT { + + private AADWebApiITHelper singleTenantITHelper; + private AADWebApiITHelper multiTenantITHelper; + + @Before + public void init() { + singleTenantITHelper = getAADWebApiITHelper(AAD_SINGLE_TENANT_CLIENT_ID, AAD_SINGLE_TENANT_CLIENT_SECRET); + multiTenantITHelper = getAADWebApiITHelper(AAD_MULTI_TENANT_CLIENT_ID, AAD_MULTI_TENANT_CLIENT_SECRET); + } + + private AADWebApiITHelper getAADWebApiITHelper(String clientId, String clientSecret) { + Map properties = new HashMap<>(); + properties.put("azure.activedirectory.client-id", clientId); + properties.put("azure.activedirectory.client-secret", clientSecret); + properties.put("azure.activedirectory.user-group.allowed-groups", "group1"); + return new AADWebApiITHelper( + DumbApp.class, + properties, + clientId, + clientSecret, + Collections.singletonList(toFullNameScope(clientId, SCOPE_GRAPH_READ))); + } + + @Test + public void testAllowedEndpointsForSingleTenantByAccessToken() { + assertEquals("home", singleTenantITHelper.httpGetStringByAccessToken("home")); + assertEquals("api/all", singleTenantITHelper.httpGetStringByAccessToken("api/all")); + assertEquals("api/group1", singleTenantITHelper.httpGetStringByAccessToken("api/group1")); + } + + @Test + public void testAllowedEndpointsForSingleTenantByCookie() { + assertEquals("home", + singleTenantITHelper.httpGetCookieByAccessTokenThenGetStringByCookie("home", "home")); + assertEquals("api/all", + singleTenantITHelper.httpGetCookieByAccessTokenThenGetStringByCookie("home", "api/all")); + assertEquals("api/group1", + singleTenantITHelper.httpGetCookieByAccessTokenThenGetStringByCookie("home", "api/group1")); + } + + @Test(expected = HttpClientErrorException.class) + public void testNotAllowedEndpointsForSingleTenant() { + singleTenantITHelper.httpGetStringByAccessToken("api/group2"); + } + + @Test + public void testAllowedEndpointsForMultiTenantByAccessToken() { + assertEquals("home", multiTenantITHelper.httpGetStringByAccessToken("home")); + assertEquals("api/all", multiTenantITHelper.httpGetStringByAccessToken("api/all")); + assertEquals("api/group1", multiTenantITHelper.httpGetStringByAccessToken("api/group1")); + } + + @Test + public void testAllowedEndpointsForMultipleTenantByCookie() { + assertEquals("home", + multiTenantITHelper.httpGetCookieByAccessTokenThenGetStringByCookie("home", "home")); + assertEquals("api/all", + multiTenantITHelper.httpGetCookieByAccessTokenThenGetStringByCookie("home", "api/all")); + assertEquals("api/group1", + multiTenantITHelper.httpGetCookieByAccessTokenThenGetStringByCookie("home", "api/group1")); + } + + @Test(expected = HttpClientErrorException.class) + public void testNotAllowedEndpointsForMultiTenant() { + multiTenantITHelper.httpGetStringByAccessToken("api/group2"); + } + + @EnableGlobalMethodSecurity(securedEnabled = true, prePostEnabled = true) + @SpringBootApplication + @RestController + public static class DumbApp extends WebSecurityConfigurerAdapter { + + @Autowired + private AADAuthenticationFilter aadAuthFilter; + + @Override + protected void configure(HttpSecurity http) throws Exception { + + http.authorizeRequests().antMatchers("home").permitAll(); + http.authorizeRequests().antMatchers("api/**").authenticated(); + + http.logout().logoutRequestMatcher(new AntPathRequestMatcher("/logout")) + .logoutSuccessUrl("/").deleteCookies("JSESSIONID").invalidateHttpSession(true); + + http.authorizeRequests().anyRequest().permitAll(); + + http.csrf().csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse()); + + http.addFilterBefore(aadAuthFilter, UsernamePasswordAuthenticationFilter.class); + } + + @GetMapping(value = "home") + public ResponseEntity getHome() { + return new ResponseEntity<>("home", HttpStatus.OK); + } + + @GetMapping(value = "api/all") + public ResponseEntity getAll() { + return new ResponseEntity<>("api/all", HttpStatus.OK); + } + + @PreAuthorize("hasRole('ROLE_group1')") + @GetMapping(value = "api/group1") + public ResponseEntity getRoleGroup1() { + return new ResponseEntity<>("api/group1", HttpStatus.OK); + } + + @PreAuthorize("hasRole('ROLE_group2')") + @GetMapping(value = "api/group2") + public ResponseEntity getRoleGroup2() { + return new ResponseEntity<>("api/group2", HttpStatus.OK); + } + } + +} diff --git a/sdk/spring/azure-spring-boot-test-aad-resource-server-by-filter/src/test/java/com/azure/test/aad/filter/stateless/AADAppRoleStatelessAuthenticationFilterIT.java b/sdk/spring/azure-spring-boot-test-aad-resource-server-by-filter/src/test/java/com/azure/test/aad/filter/stateless/AADAppRoleStatelessAuthenticationFilterIT.java new file mode 100644 index 0000000000000..6f2d526fbbbcd --- /dev/null +++ b/sdk/spring/azure-spring-boot-test-aad-resource-server-by-filter/src/test/java/com/azure/test/aad/filter/stateless/AADAppRoleStatelessAuthenticationFilterIT.java @@ -0,0 +1,100 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.test.aad.filter.stateless; + +import com.azure.spring.test.aad.AADWebApiITHelper; +import com.azure.spring.autoconfigure.aad.AADAppRoleStatelessAuthenticationFilter; +import org.junit.Before; +import org.junit.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; +import org.springframework.security.config.http.SessionCreationPolicy; +import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.client.HttpClientErrorException; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; + +import static com.azure.spring.test.aad.EnvironmentVariables.AAD_SINGLE_TENANT_CLIENT_ID_WITH_ROLE; +import static com.azure.spring.test.aad.EnvironmentVariables.AAD_SINGLE_TENANT_CLIENT_SECRET_WITH_ROLE; +import static org.junit.Assert.assertEquals; + +public class AADAppRoleStatelessAuthenticationFilterIT { + + private AADWebApiITHelper aadWebApiITHelper; + + @Before + public void init() { + String clientId = AAD_SINGLE_TENANT_CLIENT_ID_WITH_ROLE; + String clientSecret = AAD_SINGLE_TENANT_CLIENT_SECRET_WITH_ROLE; + Map properties = new HashMap<>(); + properties.put("azure.activedirectory.client-id", clientId); + properties.put("azure.activedirectory.client-secret", clientSecret); + properties.put("azure.activedirectory.session-stateless", "true"); + aadWebApiITHelper = new AADWebApiITHelper( + DumbApp.class, + properties, + clientId, + clientSecret, + Arrays.asList("user.read", "openid", "profile", "offline_access")); + } + + @Test + public void testAllowedEndpoints() { + assertEquals("public", aadWebApiITHelper.httpGetStringByIdToken("public")); + assertEquals("userRole", aadWebApiITHelper.httpGetStringByIdToken("userRole")); + } + + @Test(expected = HttpClientErrorException.class) + public void testNotAllowedEndpoints() { + aadWebApiITHelper.httpGetStringByIdToken("adminRole"); + } + + @EnableGlobalMethodSecurity(prePostEnabled = true) + @SpringBootApplication + @RestController + public static class DumbApp extends WebSecurityConfigurerAdapter { + + @Autowired + private AADAppRoleStatelessAuthenticationFilter aadAuthFilter; + + @Override + protected void configure(HttpSecurity http) throws Exception { + http.csrf().disable(); + + http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.NEVER); + + http.authorizeRequests() + .antMatchers("/adminRole").hasRole("Admin") + .antMatchers("/", "/index.html", "/public").permitAll() + .anyRequest().authenticated(); + + http.addFilterBefore(aadAuthFilter, UsernamePasswordAuthenticationFilter.class); + } + + @GetMapping("/public") + public String publicMethod() { + return "public"; + } + + @GetMapping("/userRole") + @PreAuthorize("hasRole('ROLE_User')") + public String onlyAuthorizedUsers() { + return "userRole"; + } + + @GetMapping("/adminRole") + public String onlyForAdmins() { + return "adminRole"; + } + } + +} diff --git a/sdk/spring/azure-spring-boot-test-aad-resource-server/CHANGELOG.md b/sdk/spring/azure-spring-boot-test-aad-resource-server/CHANGELOG.md new file mode 100644 index 0000000000000..3bae488de73c9 --- /dev/null +++ b/sdk/spring/azure-spring-boot-test-aad-resource-server/CHANGELOG.md @@ -0,0 +1,3 @@ +# Release History + +## 1.0.0 (Unreleased) diff --git a/sdk/spring/azure-spring-boot-test-aad-resource-server/README.md b/sdk/spring/azure-spring-boot-test-aad-resource-server/README.md new file mode 100644 index 0000000000000..c4e48df945621 --- /dev/null +++ b/sdk/spring/azure-spring-boot-test-aad-resource-server/README.md @@ -0,0 +1,8 @@ +# Azure Spring Boot AAD Resource Server Integration tests client library for Java + +## Key concepts +## Getting started +## Examples +## Troubleshooting +## Next steps +## Contributing diff --git a/sdk/spring/azure-spring-boot-test-aad-resource-server/pom.xml b/sdk/spring/azure-spring-boot-test-aad-resource-server/pom.xml new file mode 100644 index 0000000000000..f6383c959a5a6 --- /dev/null +++ b/sdk/spring/azure-spring-boot-test-aad-resource-server/pom.xml @@ -0,0 +1,64 @@ + + + + org.springframework.boot + spring-boot-starter-parent + 2.3.7.RELEASE + + + 4.0.0 + + com.azure.spring + azure-spring-boot-test-aad-resource-server + 1.0.0 + + + + com.azure.spring + azure-spring-boot-starter-active-directory + 3.2.0-beta.1 + + + + + org.springframework.boot + spring-boot-starter-oauth2-resource-server + + + org.springframework.boot + spring-boot-starter-web + + + + + com.azure.spring + azure-spring-boot-test-core + 1.0.0 + test + + + org.springframework.boot + spring-boot-starter-test + test + + + + + true + + + + + + org.apache.maven.plugins + maven-failsafe-plugin + 2.22.0 + + ${skipSpringITs} + + + + + diff --git a/sdk/spring/azure-spring-boot-test-aad-resource-server/src/test/java/com/azure/test/aad/resource/server/AADWeiResourceServerIT.java b/sdk/spring/azure-spring-boot-test-aad-resource-server/src/test/java/com/azure/test/aad/resource/server/AADWeiResourceServerIT.java new file mode 100644 index 0000000000000..b1cb35412473e --- /dev/null +++ b/sdk/spring/azure-spring-boot-test-aad-resource-server/src/test/java/com/azure/test/aad/resource/server/AADWeiResourceServerIT.java @@ -0,0 +1,83 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.test.aad.resource.server; + +import com.azure.spring.test.aad.AADWebApiITHelper; +import org.junit.Before; +import org.junit.Test; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; +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; +import org.springframework.security.config.annotation.web.configurers.oauth2.server.resource.OAuth2ResourceServerConfigurer; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.client.HttpClientErrorException; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +import static com.azure.spring.test.aad.EnvironmentVariables.AAD_MULTI_TENANT_CLIENT_ID; +import static com.azure.spring.test.aad.EnvironmentVariables.AAD_MULTI_TENANT_CLIENT_SECRET; +import static com.azure.spring.test.aad.EnvironmentVariables.MULTI_TENANT_SCOPE_GRAPH_READ; +import static org.junit.Assert.assertEquals; + +public class AADWeiResourceServerIT { + + private AADWebApiITHelper aadWebApiITHelper; + + @Before + public void init() { + Map properties = new HashMap<>(); + properties.put("azure.activedirectory.client-id", AAD_MULTI_TENANT_CLIENT_ID); + properties.put("azure.activedirectory.client-secret", AAD_MULTI_TENANT_CLIENT_SECRET); + properties.put("azure.activedirectory.app-id-uri", "api://" + AAD_MULTI_TENANT_CLIENT_ID); + aadWebApiITHelper = new AADWebApiITHelper( + DumbApp.class, + properties, + AAD_MULTI_TENANT_CLIENT_ID, + AAD_MULTI_TENANT_CLIENT_SECRET, + Collections.singletonList(MULTI_TENANT_SCOPE_GRAPH_READ)); + } + + @Test + public void testHasScope() { + assertEquals(aadWebApiITHelper.httpGetStringByAccessToken("graph"), "graph"); + } + + @Test(expected = HttpClientErrorException.class) + public void testHasNoScope() { + aadWebApiITHelper.httpGetStringByAccessToken("notExist"); + } + + @EnableWebSecurity + @EnableGlobalMethodSecurity(securedEnabled = true, prePostEnabled = true) + @SpringBootApplication + @RestController + public static class DumbApp extends WebSecurityConfigurerAdapter { + + @Override + protected void configure(HttpSecurity http) throws Exception { + http.authorizeRequests() + .anyRequest().authenticated() + .and() + .oauth2ResourceServer(OAuth2ResourceServerConfigurer::jwt); + } + + @GetMapping("graph") + @PreAuthorize("hasAuthority('SCOPE_ResourceAccessGraph.Read')") + public String graph() { + return "graph"; + } + + @GetMapping("notExist") + @PreAuthorize("hasAuthority('SCOPE_NotExist')") + public String notExist() { + return "notExist"; + } + } +} diff --git a/sdk/spring/azure-spring-boot-test-aad/pom.xml b/sdk/spring/azure-spring-boot-test-aad/pom.xml index a874122e93d1a..1c5bc342a3e9c 100644 --- a/sdk/spring/azure-spring-boot-test-aad/pom.xml +++ b/sdk/spring/azure-spring-boot-test-aad/pom.xml @@ -15,22 +15,13 @@ 1.0.0 - - com.azure.spring - azure-spring-boot-test-core - 1.0.0 - com.azure.spring azure-spring-boot-starter-active-directory 3.2.0-beta.1 - - org.springframework.boot - spring-boot-starter-test - test - + org.springframework.boot spring-boot-starter-web @@ -40,9 +31,22 @@ spring-boot-starter-oauth2-client + + + com.azure.spring + azure-spring-boot-test-core + 1.0.0 + test + + + org.springframework.boot + spring-boot-starter-test + test + org.seleniumhq.selenium selenium-java + test diff --git a/sdk/spring/azure-spring-boot-test-aad/src/test/java/com/azure/test/aad/AADTestUtils.java b/sdk/spring/azure-spring-boot-test-aad/src/test/java/com/azure/test/aad/AADTestUtils.java deleted file mode 100644 index 305e1ab582057..0000000000000 --- a/sdk/spring/azure-spring-boot-test-aad/src/test/java/com/azure/test/aad/AADTestUtils.java +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -package com.azure.test.aad; - -import com.azure.test.aad.filter.OAuthResponse; -import org.springframework.http.HttpEntity; -import org.springframework.http.HttpHeaders; -import org.springframework.util.LinkedMultiValueMap; -import org.springframework.util.MultiValueMap; -import org.springframework.web.client.RestTemplate; - -import static org.springframework.http.MediaType.APPLICATION_FORM_URLENCODED; - -public class AADTestUtils { - - public static final String AAD_MULTI_TENANT_CLIENT_ID = "AAD_MULTI_TENANT_CLIENT_ID"; - public static final String AAD_MULTI_TENANT_CLIENT_SECRET = "AAD_MULTI_TENANT_CLIENT_SECRET"; - public static final String AAD_SINGLE_TENANT_CLIENT_ID_WITH_ROLE = "AAD_SINGLE_TENANT_CLIENT_ID_WITH_ROLE"; - public static final String AAD_SINGLE_TENANT_CLIENT_SECRET_WITH_ROLE = "AAD_SINGLE_TENANT_CLIENT_SECRET_WITH_ROLE"; - public static final String AAD_SINGLE_TENANT_CLIENT_ID = "AAD_SINGLE_TENANT_CLIENT_ID"; - public static final String AAD_SINGLE_TENANT_CLIENT_SECRET = "AAD_SINGLE_TENANT_CLIENT_SECRET"; - public static final String AAD_TENANT_ID_1 = "AAD_TENANT_ID_1"; - public static final String AAD_USER_NAME_1 = "AAD_USER_NAME_1"; - public static final String AAD_USER_PASSWORD_1 = "AAD_USER_PASSWORD_1"; - - private static final RestTemplate CLIENT = new RestTemplate(); - - public static OAuthResponse executeOAuth2ROPCFlow(String aadClientId, String aadClientSecret) { - final String tenantId = System.getenv().get(AAD_TENANT_ID_1); - final String aadUsername = System.getenv(AAD_USER_NAME_1); - final String aadUserPassword = System.getenv(AAD_USER_PASSWORD_1); - - assertNotEmpty(aadClientId, "client id"); - assertNotEmpty(aadClientSecret, "client secret"); - assertNotEmpty(aadUsername, AAD_USER_NAME_1); - assertNotEmpty(aadUserPassword, AAD_USER_PASSWORD_1); - - String url = String.format("https://login.microsoftonline.com/%s/oauth2/v2.0/token", tenantId); - - HttpHeaders headers = new HttpHeaders(); - headers.setContentType(APPLICATION_FORM_URLENCODED); - - MultiValueMap requestBody = new LinkedMultiValueMap<>(); - requestBody.add("scope", "user.read openid profile offline_access"); - requestBody.add("grant_type", "password"); - requestBody.add("client_id", aadClientId); - requestBody.add("client_secret", aadClientSecret); - requestBody.add("username", aadUsername); - requestBody.add("password", aadUserPassword); - - HttpEntity> requestEntity = new HttpEntity<>(requestBody, headers); - - return CLIENT.postForObject(url, requestEntity, OAuthResponse.class); - } - - private static void assertNotEmpty(String text, String key) { - if (text == null || text.isEmpty()) { - throw new IllegalArgumentException(String.format("%s is not set!", key)); - } - } - -} diff --git a/sdk/spring/azure-spring-boot-test-aad/src/test/java/com/azure/test/aad/filter/OAuthResponse.java b/sdk/spring/azure-spring-boot-test-aad/src/test/java/com/azure/test/aad/filter/OAuthResponse.java deleted file mode 100644 index 0dbeb910eb78c..0000000000000 --- a/sdk/spring/azure-spring-boot-test-aad/src/test/java/com/azure/test/aad/filter/OAuthResponse.java +++ /dev/null @@ -1,75 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -package com.azure.test.aad.filter; - -import com.fasterxml.jackson.databind.PropertyNamingStrategy; -import com.fasterxml.jackson.databind.annotation.JsonNaming; - -@JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class) -public class OAuthResponse { - - private String tokenType; - private String scope; - private long expiresIn; - private long extExpiresIn; - private String accessToken; - private String refreshToken; - private String idToken; - - public String getTokenType() { - return tokenType; - } - - public void setTokenType(String tokenType) { - this.tokenType = tokenType; - } - - public String getScope() { - return scope; - } - - public void setScope(String scope) { - this.scope = scope; - } - - public long getExpiresIn() { - return expiresIn; - } - - public void setExpiresIn(long expiresIn) { - this.expiresIn = expiresIn; - } - - public long getExtExpiresIn() { - return extExpiresIn; - } - - public void setExtExpiresIn(long extExpiresIn) { - this.extExpiresIn = extExpiresIn; - } - - public String getAccessToken() { - return accessToken; - } - - public void setAccessToken(String accessToken) { - this.accessToken = accessToken; - } - - public String getRefreshToken() { - return refreshToken; - } - - public void setRefreshToken(String refreshToken) { - this.refreshToken = refreshToken; - } - - public String getIdToken() { - return idToken; - } - - public void setIdToken(String idToken) { - this.idToken = idToken; - } -} diff --git a/sdk/spring/azure-spring-boot-test-aad/src/test/java/com/azure/test/aad/filter/stateful/AADAuthenticationFilterIT.java b/sdk/spring/azure-spring-boot-test-aad/src/test/java/com/azure/test/aad/filter/stateful/AADAuthenticationFilterIT.java deleted file mode 100644 index 1c60242d45a39..0000000000000 --- a/sdk/spring/azure-spring-boot-test-aad/src/test/java/com/azure/test/aad/filter/stateful/AADAuthenticationFilterIT.java +++ /dev/null @@ -1,168 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -package com.azure.test.aad.filter.stateful; - -import com.azure.spring.autoconfigure.aad.AADAuthenticationFilter; -import com.azure.test.aad.AADTestUtils; -import com.azure.test.aad.filter.OAuthResponse; -import com.azure.test.utils.AppRunner; -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.http.HttpEntity; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpMethod; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; -import org.springframework.security.config.annotation.web.builders.HttpSecurity; -import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; -import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; -import org.springframework.security.web.csrf.CookieCsrfTokenRepository; -import org.springframework.security.web.util.matcher.AntPathRequestMatcher; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RestController; -import org.springframework.web.client.HttpClientErrorException; -import org.springframework.web.client.RestTemplate; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Optional; - -import static com.azure.test.aad.AADTestUtils.AAD_MULTI_TENANT_CLIENT_ID; -import static com.azure.test.aad.AADTestUtils.AAD_MULTI_TENANT_CLIENT_SECRET; -import static com.azure.test.aad.AADTestUtils.AAD_SINGLE_TENANT_CLIENT_ID; -import static com.azure.test.aad.AADTestUtils.AAD_SINGLE_TENANT_CLIENT_SECRET; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.springframework.http.HttpHeaders.COOKIE; -import static org.springframework.http.HttpHeaders.SET_COOKIE; - -public class AADAuthenticationFilterIT { - - private static final Logger LOGGER = LoggerFactory.getLogger(AADAuthenticationFilterIT.class); - private final RestTemplate restTemplate = new RestTemplate(); - - @Test - public void testAADAuthenticationFilterWithSingleTenantApp() { - final String clientId = System.getenv(AAD_SINGLE_TENANT_CLIENT_ID); - final String clientSecret = System.getenv(AAD_SINGLE_TENANT_CLIENT_SECRET); - - final OAuthResponse authResponse = AADTestUtils.executeOAuth2ROPCFlow(clientId, clientSecret); - assertNotNull(authResponse); - - testAADAuthenticationFilter(clientId, clientSecret, authResponse.getIdToken()); - } - - @Test - public void testAADAuthenticationFilterWithMultiTenantApp() { - final String clientId = System.getenv(AAD_MULTI_TENANT_CLIENT_ID); - final String clientSecret = System.getenv(AAD_MULTI_TENANT_CLIENT_SECRET); - - final OAuthResponse authResponse = AADTestUtils.executeOAuth2ROPCFlow(clientId, clientSecret); - assertNotNull(authResponse); - - testAADAuthenticationFilter(clientId, clientSecret, authResponse.getIdToken()); - } - - - private void testAADAuthenticationFilter(String clientId, String clientSecret, String idToken) { - try (AppRunner app = new AppRunner(DumbApp.class)) { - - app.property("azure.activedirectory.client-id", clientId); - app.property("azure.activedirectory.client-secret", clientSecret); - app.property("azure.activedirectory.user-group.allowed-groups", "group1,group2"); - - app.start(); - - final ResponseEntity response = restTemplate.exchange(app.root() + "home", - HttpMethod.GET, new HttpEntity<>(new HttpHeaders()), String.class, new HashMap<>()); - assertEquals(HttpStatus.OK, response.getStatusCode()); - assertEquals("home", response.getBody()); - - final HttpHeaders headers = new HttpHeaders(); - headers.set("Authorization", String.format("Bearer %s", idToken)); - HttpEntity entity = new HttpEntity<>(headers); - - final ResponseEntity response2 = restTemplate.exchange(app.root() + "api/all", - HttpMethod.GET, entity, String.class, new HashMap<>()); - assertEquals(HttpStatus.OK, response2.getStatusCode()); - assertEquals("all", response2.getBody()); - - final List cookies = response2.getHeaders().getOrDefault(SET_COOKIE, new ArrayList<>()); - final Optional sessionCookie = cookies.stream().filter(s -> s.startsWith("JSESSIONID=")).findAny(); - - if (sessionCookie.isPresent()) { - headers.add(COOKIE, sessionCookie.get()); - entity = new HttpEntity<>(headers); - } - - final ResponseEntity response3 = restTemplate.exchange(app.root() + "api/group1", - HttpMethod.GET, entity, String.class, new HashMap<>()); - assertEquals(HttpStatus.OK, response3.getStatusCode()); - assertEquals("group1", response3.getBody()); - - try { - restTemplate.exchange(app.root() + "api/group2", - HttpMethod.GET, entity, String.class, new HashMap<>()); - } catch (Exception e) { - assertEquals(HttpClientErrorException.Forbidden.class, e.getClass()); - } - - LOGGER.info("--------------------->test over"); - } - } - - @EnableGlobalMethodSecurity(securedEnabled = true, prePostEnabled = true) - @SpringBootApplication - @RestController - public static class DumbApp extends WebSecurityConfigurerAdapter { - - @Autowired - private AADAuthenticationFilter aadAuthFilter; - - @Override - protected void configure(HttpSecurity http) throws Exception { - - http.authorizeRequests().antMatchers("/home").permitAll(); - http.authorizeRequests().antMatchers("/api/**").authenticated(); - - http.logout().logoutRequestMatcher(new AntPathRequestMatcher("/logout")) - .logoutSuccessUrl("/").deleteCookies("JSESSIONID").invalidateHttpSession(true); - - http.authorizeRequests().anyRequest().permitAll(); - - http.csrf().csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse()); - - http.addFilterBefore(aadAuthFilter, UsernamePasswordAuthenticationFilter.class); - } - - @GetMapping(value = "/api/all") - public ResponseEntity getAll() { - return new ResponseEntity<>("all", HttpStatus.OK); - } - - @PreAuthorize("hasRole('ROLE_group1')") - @GetMapping(value = "/api/group1") - public ResponseEntity getRoleGroup1() { - return new ResponseEntity<>("group1", HttpStatus.OK); - } - - @PreAuthorize("hasRole('ROLE_group2')") - @GetMapping(value = "/api/group2") - public ResponseEntity getRoleGroup2() { - return new ResponseEntity<>("group2", HttpStatus.OK); - } - - @GetMapping(value = "/home") - public ResponseEntity getHome() { - return new ResponseEntity<>("home", HttpStatus.OK); - } - } - -} diff --git a/sdk/spring/azure-spring-boot-test-aad/src/test/java/com/azure/test/aad/filter/stateless/AADAppRoleStatelessAuthenticationFilterIT.java b/sdk/spring/azure-spring-boot-test-aad/src/test/java/com/azure/test/aad/filter/stateless/AADAppRoleStatelessAuthenticationFilterIT.java deleted file mode 100644 index 1a841a5a83357..0000000000000 --- a/sdk/spring/azure-spring-boot-test-aad/src/test/java/com/azure/test/aad/filter/stateless/AADAppRoleStatelessAuthenticationFilterIT.java +++ /dev/null @@ -1,128 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -package com.azure.test.aad.filter.stateless; - -import com.azure.spring.autoconfigure.aad.AADAppRoleStatelessAuthenticationFilter; -import com.azure.test.aad.AADTestUtils; -import com.azure.test.aad.filter.OAuthResponse; -import com.azure.test.utils.AppRunner; -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.http.HttpEntity; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpMethod; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; -import org.springframework.security.config.annotation.web.builders.HttpSecurity; -import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; -import org.springframework.security.config.http.SessionCreationPolicy; -import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RestController; -import org.springframework.web.client.HttpClientErrorException; -import org.springframework.web.client.RestTemplate; - -import java.util.HashMap; - -import static com.azure.test.aad.AADTestUtils.AAD_SINGLE_TENANT_CLIENT_ID_WITH_ROLE; -import static com.azure.test.aad.AADTestUtils.AAD_SINGLE_TENANT_CLIENT_SECRET_WITH_ROLE; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -public class AADAppRoleStatelessAuthenticationFilterIT { - - private static final Logger LOGGER = LoggerFactory.getLogger(AADAppRoleStatelessAuthenticationFilterIT.class); - private final RestTemplate restTemplate = new RestTemplate(); - - @Test - public void testAADAppRoleStatelessAuthenticationFilter() { - final OAuthResponse authResponse = - AADTestUtils.executeOAuth2ROPCFlow(System.getenv(AAD_SINGLE_TENANT_CLIENT_ID_WITH_ROLE), - System.getenv(AAD_SINGLE_TENANT_CLIENT_SECRET_WITH_ROLE)); - assertNotNull(authResponse); - - try (AppRunner app = new AppRunner(DumbApp.class)) { - - app.property("azure.activedirectory.client-id", System.getenv(AAD_SINGLE_TENANT_CLIENT_ID_WITH_ROLE)); - app.property("azure.activedirectory.session-stateless", "true"); - - app.start(); - - final ResponseEntity response = restTemplate.exchange(app.root() + "public", - HttpMethod.GET, new HttpEntity<>(new HttpHeaders()), String.class, new HashMap<>()); - assertEquals(HttpStatus.OK, response.getStatusCode()); - assertEquals("public endpoint response", response.getBody()); - - try { - restTemplate.exchange(app.root() + "authorized", - HttpMethod.GET, new HttpEntity<>(new HttpHeaders()), String.class, new HashMap<>()); - } catch (Exception e) { - assertEquals(HttpClientErrorException.Forbidden.class, e.getClass()); - } - - final HttpHeaders headers = new HttpHeaders(); - headers.set("Authorization", String.format("Bearer %s", authResponse.getIdToken())); - final HttpEntity entity = new HttpEntity<>(headers); - - final ResponseEntity response2 = restTemplate.exchange(app.root() + "authorized", - HttpMethod.GET, entity, String.class, new HashMap<>()); - assertEquals(HttpStatus.OK, response2.getStatusCode()); - assertEquals("authorized endpoint response", response2.getBody()); - - try { - restTemplate.exchange(app.root() + "admin/demo", - HttpMethod.GET, entity, String.class, new HashMap<>()); - } catch (Exception e) { - assertEquals(HttpClientErrorException.Forbidden.class, e.getClass()); - } - - LOGGER.info("--------------------->test over"); - } - } - - @EnableGlobalMethodSecurity(prePostEnabled = true) - @SpringBootApplication - @RestController - public static class DumbApp extends WebSecurityConfigurerAdapter { - - @Autowired - private AADAppRoleStatelessAuthenticationFilter aadAuthFilter; - - @Override - protected void configure(HttpSecurity http) throws Exception { - http.csrf().disable(); - - http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.NEVER); - - http.authorizeRequests() - .antMatchers("/admin/**").hasRole("Admin") - .antMatchers("/", "/index.html", "/public").permitAll() - .anyRequest().authenticated(); - - http.addFilterBefore(aadAuthFilter, UsernamePasswordAuthenticationFilter.class); - } - - @GetMapping("/public") - public String publicMethod() { - return "public endpoint response"; - } - - @GetMapping("/authorized") - @PreAuthorize("hasRole('ROLE_User')") - public String onlyAuthorizedUsers() { - return "authorized endpoint response"; - } - - @GetMapping("/admin/demo") - public String onlyForAdmins() { - return "admin endpoint response"; - } - } - -} diff --git a/sdk/spring/azure-spring-boot-test-aad/src/test/java/com/azure/test/aad/selenium/AADSeleniumITHelper.java b/sdk/spring/azure-spring-boot-test-aad/src/test/java/com/azure/test/aad/selenium/AADSeleniumITHelper.java index 5cbc6fa12c345..977266bfeeb0f 100644 --- a/sdk/spring/azure-spring-boot-test-aad/src/test/java/com/azure/test/aad/selenium/AADSeleniumITHelper.java +++ b/sdk/spring/azure-spring-boot-test-aad/src/test/java/com/azure/test/aad/selenium/AADSeleniumITHelper.java @@ -1,6 +1,6 @@ package com.azure.test.aad.selenium; -import com.azure.test.utils.AppRunner; +import com.azure.spring.test.AppRunner; import org.junit.Assert; import org.openqa.selenium.By; import org.openqa.selenium.Keys; @@ -16,11 +16,11 @@ import java.util.Map; import java.util.regex.Pattern; -import static com.azure.test.aad.AADTestUtils.AAD_MULTI_TENANT_CLIENT_ID; -import static com.azure.test.aad.AADTestUtils.AAD_MULTI_TENANT_CLIENT_SECRET; -import static com.azure.test.aad.AADTestUtils.AAD_TENANT_ID_1; -import static com.azure.test.aad.AADTestUtils.AAD_USER_NAME_1; -import static com.azure.test.aad.AADTestUtils.AAD_USER_PASSWORD_1; +import static com.azure.spring.test.aad.EnvironmentVariables.AAD_MULTI_TENANT_CLIENT_ID; +import static com.azure.spring.test.aad.EnvironmentVariables.AAD_MULTI_TENANT_CLIENT_SECRET; +import static com.azure.spring.test.aad.EnvironmentVariables.AAD_TENANT_ID_1; +import static com.azure.spring.test.aad.EnvironmentVariables.AAD_USER_NAME_1; +import static com.azure.spring.test.aad.EnvironmentVariables.AAD_USER_PASSWORD_1; import static org.openqa.selenium.support.ui.ExpectedConditions.presenceOfElementLocated; public class AADSeleniumITHelper { @@ -32,9 +32,9 @@ public class AADSeleniumITHelper { private static final Map DEFAULT_PROPERTIES = new HashMap<>(); static { - DEFAULT_PROPERTIES.put("azure.activedirectory.tenant-id", System.getenv(AAD_TENANT_ID_1)); - DEFAULT_PROPERTIES.put("azure.activedirectory.client-id", System.getenv(AAD_MULTI_TENANT_CLIENT_ID)); - DEFAULT_PROPERTIES.put("azure.activedirectory.client-secret", System.getenv(AAD_MULTI_TENANT_CLIENT_SECRET)); + DEFAULT_PROPERTIES.put("azure.activedirectory.tenant-id", AAD_TENANT_ID_1); + DEFAULT_PROPERTIES.put("azure.activedirectory.client-id", AAD_MULTI_TENANT_CLIENT_ID); + DEFAULT_PROPERTIES.put("azure.activedirectory.client-secret", AAD_MULTI_TENANT_CLIENT_SECRET); DEFAULT_PROPERTIES.put("azure.activedirectory.user-group.allowed-groups", "group1"); DEFAULT_PROPERTIES.put("azure.activedirectory.post-logout-redirect-uri", "http://localhost:${server.port}"); @@ -69,8 +69,8 @@ public class AADSeleniumITHelper { } public AADSeleniumITHelper(Class appClass, Map properties) throws InterruptedException { - username = System.getenv(AAD_USER_NAME_1); - password = System.getenv(AAD_USER_PASSWORD_1); + username = AAD_USER_NAME_1; + password = AAD_USER_PASSWORD_1; app = new AppRunner(appClass); DEFAULT_PROPERTIES.forEach(app::property); properties.forEach(app::property); diff --git a/sdk/spring/azure-spring-boot-test-aad/src/test/java/com/azure/test/aad/selenium/access/token/scopes/AADAccessTokenScopesIT.java b/sdk/spring/azure-spring-boot-test-aad/src/test/java/com/azure/test/aad/selenium/access/token/scopes/AADAccessTokenScopesIT.java index c2afc98a9a018..f25d0fc6994b4 100644 --- a/sdk/spring/azure-spring-boot-test-aad/src/test/java/com/azure/test/aad/selenium/access/token/scopes/AADAccessTokenScopesIT.java +++ b/sdk/spring/azure-spring-boot-test-aad/src/test/java/com/azure/test/aad/selenium/access/token/scopes/AADAccessTokenScopesIT.java @@ -49,8 +49,8 @@ public void testAccessTokenScopes() throws InterruptedException { Assert.assertTrue(httpResponse.contains("https://manage.office.com/ActivityFeed.ReadDlp")); Assert.assertTrue(httpResponse.contains("https://manage.office.com/ServiceHealth.Read")); - httpResponse = aadSeleniumITHelper.httpGet("arm"); - Assert.assertNotEquals(httpResponse, "arm"); + httpResponse = aadSeleniumITHelper.httpGet("notExist"); + Assert.assertNotEquals(httpResponse, "notExist"); } @EnableGlobalMethodSecurity(securedEnabled = true, prePostEnabled = true) @@ -85,10 +85,10 @@ public Set office( .orElse(null); } - @GetMapping(value = "arm") - public String arm( - @RegisteredOAuth2AuthorizedClient("arm") OAuth2AuthorizedClient authorizedClient) { - return "arm"; + @GetMapping(value = "notExist") + public String notExist( + @RegisteredOAuth2AuthorizedClient("notExist") OAuth2AuthorizedClient authorizedClient) { + return "notExist"; } } diff --git a/sdk/spring/azure-spring-boot-test-core/pom.xml b/sdk/spring/azure-spring-boot-test-core/pom.xml index fc786f5315817..3380b36b5a572 100644 --- a/sdk/spring/azure-spring-boot-test-core/pom.xml +++ b/sdk/spring/azure-spring-boot-test-core/pom.xml @@ -81,5 +81,12 @@ azure-spring-boot-starter 3.2.0-beta.1 + + + + org.springframework.boot + spring-boot-starter-test + test + diff --git a/sdk/spring/azure-spring-boot-test-core/src/main/java/com/azure/test/utils/AppRunner.java b/sdk/spring/azure-spring-boot-test-core/src/main/java/com/azure/spring/test/AppRunner.java similarity index 99% rename from sdk/spring/azure-spring-boot-test-core/src/main/java/com/azure/test/utils/AppRunner.java rename to sdk/spring/azure-spring-boot-test-core/src/main/java/com/azure/spring/test/AppRunner.java index 57a3c6a463943..db6d7020da0e4 100644 --- a/sdk/spring/azure-spring-boot-test-core/src/main/java/com/azure/test/utils/AppRunner.java +++ b/sdk/spring/azure-spring-boot-test-core/src/main/java/com/azure/spring/test/AppRunner.java @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -package com.azure.test.utils; +package com.azure.spring.test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/sdk/spring/azure-spring-boot-test-core/src/main/java/com/azure/test/utils/MavenBasedProject.java b/sdk/spring/azure-spring-boot-test-core/src/main/java/com/azure/spring/test/MavenBasedProject.java similarity index 98% rename from sdk/spring/azure-spring-boot-test-core/src/main/java/com/azure/test/utils/MavenBasedProject.java rename to sdk/spring/azure-spring-boot-test-core/src/main/java/com/azure/spring/test/MavenBasedProject.java index 279c0dcb218ff..0657a7ed53c05 100644 --- a/sdk/spring/azure-spring-boot-test-core/src/main/java/com/azure/test/utils/MavenBasedProject.java +++ b/sdk/spring/azure-spring-boot-test-core/src/main/java/com/azure/spring/test/MavenBasedProject.java @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -package com.azure.test.utils; +package com.azure.spring.test; import org.apache.maven.cli.MavenCli; import org.apache.maven.model.io.xpp3.MavenXpp3Reader; diff --git a/sdk/spring/azure-spring-boot-test-core/src/main/java/com/azure/test/utils/SSHShell.java b/sdk/spring/azure-spring-boot-test-core/src/main/java/com/azure/spring/test/SSHShell.java similarity index 99% rename from sdk/spring/azure-spring-boot-test-core/src/main/java/com/azure/test/utils/SSHShell.java rename to sdk/spring/azure-spring-boot-test-core/src/main/java/com/azure/spring/test/SSHShell.java index bda073d85b9aa..f59346717e9e5 100644 --- a/sdk/spring/azure-spring-boot-test-core/src/main/java/com/azure/test/utils/SSHShell.java +++ b/sdk/spring/azure-spring-boot-test-core/src/main/java/com/azure/spring/test/SSHShell.java @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -package com.azure.test.utils; +package com.azure.spring.test; import com.jcraft.jsch.ChannelSftp; import com.jcraft.jsch.ChannelShell; diff --git a/sdk/spring/azure-spring-boot-test-core/src/main/java/com/azure/spring/test/aad/AADWebApiITHelper.java b/sdk/spring/azure-spring-boot-test-core/src/main/java/com/azure/spring/test/aad/AADWebApiITHelper.java new file mode 100644 index 0000000000000..561ecb6590c85 --- /dev/null +++ b/sdk/spring/azure-spring-boot-test-core/src/main/java/com/azure/spring/test/aad/AADWebApiITHelper.java @@ -0,0 +1,100 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.spring.test.aad; + +import com.azure.spring.test.AppRunner; +import com.azure.spring.test.aad.ropc.AADOauth2ROPCGrantClient; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.ResponseEntity; +import org.springframework.util.Assert; +import org.springframework.web.client.RestTemplate; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import static com.azure.spring.test.aad.EnvironmentVariables.AAD_TENANT_ID_1; +import static com.azure.spring.test.aad.EnvironmentVariables.AAD_USER_NAME_1; +import static com.azure.spring.test.aad.EnvironmentVariables.AAD_USER_PASSWORD_1; +import static org.springframework.http.HttpHeaders.COOKIE; +import static org.springframework.http.HttpHeaders.SET_COOKIE; + +public class AADWebApiITHelper { + private static final RestTemplate REST_TEMPLATE = new RestTemplate(); + + private final AppRunner app; + private final AADOauth2ROPCGrantClient.OAuth2ROPCResponse oAuth2ROPCResponse; + + public AADWebApiITHelper(Class appClass, + Map appProperties, + String clientId, + String clientSecret, + List accessTokenScopes) { + app = new AppRunner(appClass); + appProperties.forEach(app::property); + app.start(); + + oAuth2ROPCResponse = AADOauth2ROPCGrantClient.getOAuth2ROPCResponseByROPCGrant( + AAD_TENANT_ID_1, + clientId, + clientSecret, + AAD_USER_NAME_1, + AAD_USER_PASSWORD_1, + String.join(" ", accessTokenScopes)); + } + + public String httpGetCookieByAccessTokenThenGetStringByCookie(String accessTokenEndpoint, String cookieEndpoint) { + ResponseEntity responseEntity = + httpGetResponseByToken(accessTokenEndpoint, oAuth2ROPCResponse.getAccessToken()); + String jSessionIdCookie = responseEntity + .getHeaders() + .getOrDefault(SET_COOKIE, new ArrayList<>()) + .stream() + .filter(s -> s.startsWith("JSESSIONID=")) + .findAny() + .orElse(null); + Assert.notNull(jSessionIdCookie, "jSessionIdCookie can not be null."); + HttpHeaders headers = new HttpHeaders(); + headers.add(COOKIE, jSessionIdCookie); + HttpEntity entity = new HttpEntity<>(headers); + return httpGetResponseByEntity(cookieEndpoint, entity).getBody(); + } + + public String httpGetStringByAccessToken(String endpoint) { + return httpGetStringByToken(endpoint, oAuth2ROPCResponse.getAccessToken()); + } + + public String httpGetStringByIdToken(String endpoint) { + return httpGetStringByToken(endpoint, oAuth2ROPCResponse.getIdToken()); + } + + public String httpGetStringByToken(String endpoint, String token) { + return httpGetResponseByToken(endpoint, token).getBody(); + } + + public ResponseEntity httpGetResponseByToken(String endpoint, String token) { + HttpHeaders headers = new HttpHeaders(); + headers.set("Authorization", String.format("Bearer %s", token)); + HttpEntity entity = new HttpEntity<>(headers); + return httpGetResponseByEntity(endpoint, entity); + } + + public ResponseEntity httpGetResponseByEntity(String endpoint, HttpEntity entity) { + endpoint = addSlash(endpoint); + return REST_TEMPLATE + .exchange( + app.root() + endpoint, + HttpMethod.GET, + entity, + String.class, + new HashMap<>()); + } + + private String addSlash(String endpoint) { + return endpoint.startsWith("/") ? endpoint : "/" + endpoint; + } +} diff --git a/sdk/spring/azure-spring-boot-test-core/src/main/java/com/azure/spring/test/aad/EnvironmentVariables.java b/sdk/spring/azure-spring-boot-test-core/src/main/java/com/azure/spring/test/aad/EnvironmentVariables.java new file mode 100644 index 0000000000000..20a40a2fe5d48 --- /dev/null +++ b/sdk/spring/azure-spring-boot-test-core/src/main/java/com/azure/spring/test/aad/EnvironmentVariables.java @@ -0,0 +1,28 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.spring.test.aad; + +public class EnvironmentVariables { + // Test accounts + public static final String AAD_TENANT_ID_1 = System.getenv("AAD_TENANT_ID_1"); + public static final String AAD_USER_NAME_1 = System.getenv("AAD_USER_NAME_1"); + public static final String AAD_USER_PASSWORD_1 = System.getenv("AAD_USER_PASSWORD_1"); + public static final String AAD_SINGLE_TENANT_CLIENT_ID = System.getenv("AAD_SINGLE_TENANT_CLIENT_ID"); + public static final String AAD_SINGLE_TENANT_CLIENT_SECRET = System.getenv("AAD_SINGLE_TENANT_CLIENT_SECRET"); + public static final String AAD_MULTI_TENANT_CLIENT_ID = System.getenv("AAD_MULTI_TENANT_CLIENT_ID"); + public static final String AAD_MULTI_TENANT_CLIENT_SECRET = System.getenv("AAD_MULTI_TENANT_CLIENT_SECRET"); + public static final String AAD_SINGLE_TENANT_CLIENT_ID_WITH_ROLE = + System.getenv("AAD_SINGLE_TENANT_CLIENT_ID_WITH_ROLE"); + public static final String AAD_SINGLE_TENANT_CLIENT_SECRET_WITH_ROLE = + System.getenv("AAD_SINGLE_TENANT_CLIENT_SECRET_WITH_ROLE"); + + // scopes + public static final String SCOPE_GRAPH_READ = "ResourceAccessGraph.Read"; + public static final String MULTI_TENANT_SCOPE_GRAPH_READ = + toFullNameScope(AAD_MULTI_TENANT_CLIENT_ID, "ResourceAccessGraph.Read"); + + public static String toFullNameScope(String clientId, String scope) { + return "api://" + clientId + "/" + scope; + } +} diff --git a/sdk/spring/azure-spring-boot-test-core/src/main/java/com/azure/spring/test/aad/ropc/AADOauth2ROPCGrantClient.java b/sdk/spring/azure-spring-boot-test-core/src/main/java/com/azure/spring/test/aad/ropc/AADOauth2ROPCGrantClient.java new file mode 100644 index 0000000000000..18245d1e459f8 --- /dev/null +++ b/sdk/spring/azure-spring-boot-test-core/src/main/java/com/azure/spring/test/aad/ropc/AADOauth2ROPCGrantClient.java @@ -0,0 +1,120 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.spring.test.aad.ropc; + +import com.fasterxml.jackson.databind.PropertyNamingStrategy; +import com.fasterxml.jackson.databind.annotation.JsonNaming; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.util.Assert; +import org.springframework.util.LinkedMultiValueMap; +import org.springframework.util.MultiValueMap; +import org.springframework.web.client.RestTemplate; + +import static org.springframework.http.MediaType.APPLICATION_FORM_URLENCODED; + +public class AADOauth2ROPCGrantClient { + + private static final RestTemplate REST_TEMPLATE = new RestTemplate(); + private static final HttpHeaders HEADERS = new HttpHeaders(); + + static { + HEADERS.setContentType(APPLICATION_FORM_URLENCODED); + } + + // Refs: https://docs.microsoft.com/en-us/azure/active-directory/develop/v2-oauth-ropc + public static OAuth2ROPCResponse getOAuth2ROPCResponseByROPCGrant(String tenantId, + String clientId, + String clientSecret, + String username, + String password, + String scope) { + Assert.hasText(tenantId, "tenantId can not be empty."); + Assert.hasText(clientId, "clientId can not be empty."); + Assert.hasText(clientSecret, "clientSecret can not be empty."); + Assert.hasText(username, "username can not be empty."); + Assert.hasText(password, "password can not be empty."); + + MultiValueMap body = new LinkedMultiValueMap<>(); + body.add("grant_type", "password"); + body.add("client_id", clientId); + body.add("client_secret", clientSecret); + body.add("username", username); + body.add("password", password); + body.add("scope", scope); + + HttpEntity> httpEntity = new HttpEntity<>(body, HEADERS); + String url = String.format("https://login.microsoftonline.com/%s/oauth2/v2.0/token", tenantId); + return REST_TEMPLATE.postForObject(url, httpEntity, OAuth2ROPCResponse.class); + } + + @JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class) + public static final class OAuth2ROPCResponse { + + private String tokenType; + private String scope; + private long expiresIn; + private long extExpiresIn; + private String accessToken; + private String refreshToken; + private String idToken; + + public String getTokenType() { + return tokenType; + } + + public void setTokenType(String tokenType) { + this.tokenType = tokenType; + } + + public String getScope() { + return scope; + } + + public void setScope(String scope) { + this.scope = scope; + } + + public long getExpiresIn() { + return expiresIn; + } + + public void setExpiresIn(long expiresIn) { + this.expiresIn = expiresIn; + } + + public long getExtExpiresIn() { + return extExpiresIn; + } + + public void setExtExpiresIn(long extExpiresIn) { + this.extExpiresIn = extExpiresIn; + } + + public String getAccessToken() { + return accessToken; + } + + public void setAccessToken(String accessToken) { + this.accessToken = accessToken; + } + + public String getRefreshToken() { + return refreshToken; + } + + public void setRefreshToken(String refreshToken) { + this.refreshToken = refreshToken; + } + + public String getIdToken() { + return idToken; + } + + public void setIdToken(String idToken) { + this.idToken = idToken; + } + } + +} diff --git a/sdk/spring/azure-spring-boot-test-core/src/main/java/com/azure/test/management/Access.java b/sdk/spring/azure-spring-boot-test-core/src/main/java/com/azure/spring/test/management/Access.java similarity index 87% rename from sdk/spring/azure-spring-boot-test-core/src/main/java/com/azure/test/management/Access.java rename to sdk/spring/azure-spring-boot-test-core/src/main/java/com/azure/spring/test/management/Access.java index 16ec8f41e7dfc..10b16d24d6205 100644 --- a/sdk/spring/azure-spring-boot-test-core/src/main/java/com/azure/test/management/Access.java +++ b/sdk/spring/azure-spring-boot-test-core/src/main/java/com/azure/spring/test/management/Access.java @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -package com.azure.test.management; +package com.azure.spring.test.management; import com.microsoft.azure.credentials.AzureTokenCredentials; diff --git a/sdk/spring/azure-spring-boot-test-core/src/main/java/com/azure/test/management/ClientSecretAccess.java b/sdk/spring/azure-spring-boot-test-core/src/main/java/com/azure/spring/test/management/ClientSecretAccess.java similarity index 98% rename from sdk/spring/azure-spring-boot-test-core/src/main/java/com/azure/test/management/ClientSecretAccess.java rename to sdk/spring/azure-spring-boot-test-core/src/main/java/com/azure/spring/test/management/ClientSecretAccess.java index 78e981f0a97b2..fa53b14ebc255 100644 --- a/sdk/spring/azure-spring-boot-test-core/src/main/java/com/azure/test/management/ClientSecretAccess.java +++ b/sdk/spring/azure-spring-boot-test-core/src/main/java/com/azure/spring/test/management/ClientSecretAccess.java @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -package com.azure.test.management; +package com.azure.spring.test.management; import com.microsoft.azure.AzureEnvironment; import com.microsoft.azure.credentials.ApplicationTokenCredentials; diff --git a/sdk/spring/azure-spring-boot-test-core/src/test/java/com/azure/spring/test/aad/ropc/AADOauth2ROPCGrantClientIT.java b/sdk/spring/azure-spring-boot-test-core/src/test/java/com/azure/spring/test/aad/ropc/AADOauth2ROPCGrantClientIT.java new file mode 100644 index 0000000000000..524be2aafef0e --- /dev/null +++ b/sdk/spring/azure-spring-boot-test-core/src/test/java/com/azure/spring/test/aad/ropc/AADOauth2ROPCGrantClientIT.java @@ -0,0 +1,30 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.spring.test.aad.ropc; + +import org.junit.Test; + +import static com.azure.spring.test.aad.EnvironmentVariables.AAD_MULTI_TENANT_CLIENT_ID; +import static com.azure.spring.test.aad.EnvironmentVariables.AAD_MULTI_TENANT_CLIENT_SECRET; +import static com.azure.spring.test.aad.EnvironmentVariables.AAD_TENANT_ID_1; +import static com.azure.spring.test.aad.EnvironmentVariables.AAD_USER_NAME_1; +import static com.azure.spring.test.aad.EnvironmentVariables.AAD_USER_PASSWORD_1; +import static com.azure.spring.test.aad.EnvironmentVariables.MULTI_TENANT_SCOPE_GRAPH_READ; +import static org.junit.Assert.assertNotNull; + +public class AADOauth2ROPCGrantClientIT { + + @Test + public void getOAuth2ROPCResponseByROPCGrantTest() { + AADOauth2ROPCGrantClient.OAuth2ROPCResponse oAuth2ROPCResponse = + AADOauth2ROPCGrantClient.getOAuth2ROPCResponseByROPCGrant( + AAD_TENANT_ID_1, + AAD_MULTI_TENANT_CLIENT_ID, + AAD_MULTI_TENANT_CLIENT_SECRET, + AAD_USER_NAME_1, + AAD_USER_PASSWORD_1, + MULTI_TENANT_SCOPE_GRAPH_READ); + assertNotNull(oAuth2ROPCResponse); + } +} diff --git a/sdk/spring/azure-spring-boot-test-cosmos/src/test/java/com/azure/test/cosmos/CosmosActuatorIT.java b/sdk/spring/azure-spring-boot-test-cosmos/src/test/java/com/azure/test/cosmos/CosmosActuatorIT.java index 98ad470f719e3..ed5b5eec7415d 100644 --- a/sdk/spring/azure-spring-boot-test-cosmos/src/test/java/com/azure/test/cosmos/CosmosActuatorIT.java +++ b/sdk/spring/azure-spring-boot-test-cosmos/src/test/java/com/azure/test/cosmos/CosmosActuatorIT.java @@ -3,7 +3,7 @@ package com.azure.test.cosmos; -import com.azure.test.utils.AppRunner; +import com.azure.spring.test.AppRunner; import org.junit.Assert; import org.junit.Test; import org.springframework.web.client.RestTemplate; diff --git a/sdk/spring/azure-spring-boot-test-cosmos/src/test/java/com/azure/test/cosmos/CosmosIT.java b/sdk/spring/azure-spring-boot-test-cosmos/src/test/java/com/azure/test/cosmos/CosmosIT.java index 970d5b4cdf91d..6a7292aeae1e7 100644 --- a/sdk/spring/azure-spring-boot-test-cosmos/src/test/java/com/azure/test/cosmos/CosmosIT.java +++ b/sdk/spring/azure-spring-boot-test-cosmos/src/test/java/com/azure/test/cosmos/CosmosIT.java @@ -4,7 +4,7 @@ package com.azure.test.cosmos; import com.azure.spring.autoconfigure.aad.AADAuthenticationFilterAutoConfiguration; -import com.azure.test.utils.AppRunner; +import com.azure.spring.test.AppRunner; import org.junit.Assert; import org.junit.Ignore; import org.junit.Test; diff --git a/sdk/spring/azure-spring-boot-test-keyvault/src/test/java/com/azure/test/keyvault/ActuatorIT.java b/sdk/spring/azure-spring-boot-test-keyvault/src/test/java/com/azure/test/keyvault/ActuatorIT.java index 9f27487299193..582b1508a63f8 100644 --- a/sdk/spring/azure-spring-boot-test-keyvault/src/test/java/com/azure/test/keyvault/ActuatorIT.java +++ b/sdk/spring/azure-spring-boot-test-keyvault/src/test/java/com/azure/test/keyvault/ActuatorIT.java @@ -2,8 +2,8 @@ // Licensed under the MIT License. package com.azure.test.keyvault; -import com.azure.test.management.ClientSecretAccess; -import com.azure.test.utils.AppRunner; +import com.azure.spring.test.management.ClientSecretAccess; +import com.azure.spring.test.AppRunner; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/sdk/spring/azure-spring-boot-test-keyvault/src/test/java/com/azure/test/keyvault/KeyVaultIT.java b/sdk/spring/azure-spring-boot-test-keyvault/src/test/java/com/azure/test/keyvault/KeyVaultIT.java index 580d9a9c738f8..c0d5d3ea67498 100644 --- a/sdk/spring/azure-spring-boot-test-keyvault/src/test/java/com/azure/test/keyvault/KeyVaultIT.java +++ b/sdk/spring/azure-spring-boot-test-keyvault/src/test/java/com/azure/test/keyvault/KeyVaultIT.java @@ -10,9 +10,9 @@ import com.microsoft.azure.management.compute.RunCommandInput; import com.microsoft.azure.management.compute.VirtualMachine; import com.microsoft.azure.management.resources.fluentcore.utils.SdkContext; -import com.azure.test.management.ClientSecretAccess; -import com.azure.test.utils.AppRunner; -import com.azure.test.utils.MavenBasedProject; +import com.azure.spring.test.management.ClientSecretAccess; +import com.azure.spring.test.AppRunner; +import com.azure.spring.test.MavenBasedProject; import java.io.File; import java.util.ArrayList; import java.util.List; diff --git a/sdk/spring/azure-spring-boot-test-keyvault/src/test/java/com/azure/test/keyvault/MultipleKeyVaultsIT.java b/sdk/spring/azure-spring-boot-test-keyvault/src/test/java/com/azure/test/keyvault/MultipleKeyVaultsIT.java index 0a16a353c6ce2..56a9359cbc646 100644 --- a/sdk/spring/azure-spring-boot-test-keyvault/src/test/java/com/azure/test/keyvault/MultipleKeyVaultsIT.java +++ b/sdk/spring/azure-spring-boot-test-keyvault/src/test/java/com/azure/test/keyvault/MultipleKeyVaultsIT.java @@ -5,8 +5,8 @@ import static org.junit.Assert.assertEquals; -import com.azure.test.management.ClientSecretAccess; -import com.azure.test.utils.AppRunner; +import com.azure.spring.test.management.ClientSecretAccess; +import com.azure.spring.test.AppRunner; import org.junit.Test; import org.springframework.boot.autoconfigure.SpringBootApplication; diff --git a/sdk/spring/azure-spring-boot-test-storage/src/test/java/com/microsoft/azure/test/storage/ActuatorIT.java b/sdk/spring/azure-spring-boot-test-storage/src/test/java/com/microsoft/azure/test/storage/ActuatorIT.java index 32793e3292aed..fe8096f467553 100644 --- a/sdk/spring/azure-spring-boot-test-storage/src/test/java/com/microsoft/azure/test/storage/ActuatorIT.java +++ b/sdk/spring/azure-spring-boot-test-storage/src/test/java/com/microsoft/azure/test/storage/ActuatorIT.java @@ -3,7 +3,7 @@ package com.microsoft.azure.test.storage; -import com.azure.test.utils.AppRunner; +import com.azure.spring.test.AppRunner; import org.junit.jupiter.api.Test; import org.springframework.web.client.RestTemplate; diff --git a/sdk/spring/azure-spring-boot/README.md b/sdk/spring/azure-spring-boot/README.md index cbbcd63eaf6a3..ed6a239f7363a 100644 --- a/sdk/spring/azure-spring-boot/README.md +++ b/sdk/spring/azure-spring-boot/README.md @@ -61,7 +61,7 @@ The following section provides sample projects illustrating how to use the Azure - [Azure Active Directory for Web Application](https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-webapp) - [Azure Active Directory for Resource Server](https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server) - [Azure Active Directory for Resource Server with Obo Clients](https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-obo) -- [Azure Active Directory for Resource Server with Filter(Deprecated)](https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-with-filter) +- [Azure Active Directory for Resource Server by Filter(Deprecated)](https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-by-filter) - [Azure Active Directory B2C](https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-b2c-oidc) - [Cosmos DB SQL API](https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-cosmos) - [Gremlin SQL API](https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-data-gremlin) @@ -93,7 +93,7 @@ The following section provides sample projects illustrating how to use the Azure - [Azure Active Directory for Web Application](https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-webapp) - [Azure Active Directory for Resource Server](https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server) - [Azure Active Directory for Resource Server with Obo Clients](https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-obo) -- [Azure Active Directory for Resource Server with Filter(Deprecated)](https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-with-filter) +- [Azure Active Directory for Resource Server by Filter(Deprecated)](https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-by-filter) - [Azure Active Directory B2C](https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-active-directory-b2c-oidc) - [Cosmos DB SQL API](https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-cosmos) - [Gremlin SQL API](https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/azure-spring-boot-sample-data-gremlin) diff --git a/sdk/spring/ci.yml b/sdk/spring/ci.yml index b3e1f11f4e75f..388ec9814fe3f 100644 --- a/sdk/spring/ci.yml +++ b/sdk/spring/ci.yml @@ -140,7 +140,7 @@ extends: AdditionalModules: - name: azure-spring-boot-sample-active-directory-resource-server groupId: com.azure.spring - - name: azure-spring-boot-sample-active-directory-resource-server-with-filter + - name: azure-spring-boot-sample-active-directory-resource-server-by-filter groupId: com.azure.spring - name: azure-spring-boot-sample-active-directory-b2c-oidc groupId: com.azure.spring @@ -148,7 +148,7 @@ extends: groupId: com.azure.spring - name: azure-spring-boot-sample-active-directory-resource-server-obo groupId: com.azure.spring - - name: azure-spring-boot-sample-active-directory-resource-server-stateless + - name: azure-spring-boot-sample-active-directory-resource-server-by-filter-stateless groupId: com.azure.spring - name: azure-spring-boot-sample-cosmos groupId: com.azure.spring diff --git a/sdk/spring/azure-spring-boot-test-aad/images/add-api-permission.png b/sdk/spring/images/add-api-permission.png similarity index 100% rename from sdk/spring/azure-spring-boot-test-aad/images/add-api-permission.png rename to sdk/spring/images/add-api-permission.png diff --git a/sdk/spring/azure-spring-boot-test-aad/images/allow-implicit-flow.png b/sdk/spring/images/allow-implicit-flow.png similarity index 100% rename from sdk/spring/azure-spring-boot-test-aad/images/allow-implicit-flow.png rename to sdk/spring/images/allow-implicit-flow.png diff --git a/sdk/spring/azure-spring-boot-test-aad/images/change-password.png b/sdk/spring/images/change-password.png similarity index 100% rename from sdk/spring/azure-spring-boot-test-aad/images/change-password.png rename to sdk/spring/images/change-password.png diff --git a/sdk/spring/azure-spring-boot-test-aad/images/copy-tenant-id.png b/sdk/spring/images/copy-tenant-id.png similarity index 100% rename from sdk/spring/azure-spring-boot-test-aad/images/copy-tenant-id.png rename to sdk/spring/images/copy-tenant-id.png diff --git a/sdk/spring/azure-spring-boot-test-aad/images/create-aad-multitenant-client.png b/sdk/spring/images/create-aad-multitenant-client.png similarity index 100% rename from sdk/spring/azure-spring-boot-test-aad/images/create-aad-multitenant-client.png rename to sdk/spring/images/create-aad-multitenant-client.png diff --git a/sdk/spring/azure-spring-boot-test-aad/images/create-user1.png b/sdk/spring/images/create-user1.png similarity index 100% rename from sdk/spring/azure-spring-boot-test-aad/images/create-user1.png rename to sdk/spring/images/create-user1.png diff --git a/sdk/spring/azure-spring-boot-test-aad/images/created-a-new-tenant.png b/sdk/spring/images/created-a-new-tenant.png similarity index 100% rename from sdk/spring/azure-spring-boot-test-aad/images/created-a-new-tenant.png rename to sdk/spring/images/created-a-new-tenant.png diff --git a/sdk/spring/images/expose-api.png b/sdk/spring/images/expose-api.png new file mode 100644 index 0000000000000..356cfb0da46f3 Binary files /dev/null and b/sdk/spring/images/expose-api.png differ diff --git a/sdk/spring/azure-spring-boot-test-aad/images/open-inPrivate-window.png b/sdk/spring/images/open-inPrivate-window.png similarity index 100% rename from sdk/spring/azure-spring-boot-test-aad/images/open-inPrivate-window.png rename to sdk/spring/images/open-inPrivate-window.png diff --git a/sdk/spring/azure-spring-boot-test-aad/images/role-user.png b/sdk/spring/images/role-user.png similarity index 100% rename from sdk/spring/azure-spring-boot-test-aad/images/role-user.png rename to sdk/spring/images/role-user.png diff --git a/sdk/spring/pom.xml b/sdk/spring/pom.xml index 53220c0970eed..d20591cac837f 100644 --- a/sdk/spring/pom.xml +++ b/sdk/spring/pom.xml @@ -136,83 +136,85 @@ azure-identity-spring - azure-spring-boot - azure-spring-boot-starter - azure-spring-boot-starter-active-directory - azure-spring-boot-starter-active-directory-b2c - azure-spring-boot-starter-cosmos - azure-spring-boot-starter-data-gremlin - azure-spring-boot-starter-keyvault-certificates - azure-spring-boot-starter-keyvault-secrets - azure-spring-boot-starter-servicebus-jms - azure-spring-boot-starter-storage - azure-spring-boot-test-application - azure-spring-boot-test-core - azure-spring-boot-test-aad - azure-spring-boot-test-aad-obo - azure-spring-boot-test-cosmos - azure-spring-boot-test-keyvault - azure-spring-boot-test-servicebus-jms - azure-spring-boot-test-storage - azure-spring-cloud-test-eventhubs - azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-with-filter - azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server - azure-spring-boot-samples/azure-spring-boot-sample-active-directory-webapp + azure-spring-boot-samples/azure-cloud-foundry-service-sample azure-spring-boot-samples/azure-spring-boot-sample-active-directory-b2c-oidc + azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-by-filter-stateless + azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-by-filter azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-obo - azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server-stateless + azure-spring-boot-samples/azure-spring-boot-sample-active-directory-resource-server + azure-spring-boot-samples/azure-spring-boot-sample-active-directory-webapp azure-spring-boot-samples/azure-spring-boot-sample-cosmos azure-spring-boot-samples/azure-spring-boot-sample-data-gremlin azure-spring-boot-samples/azure-spring-boot-sample-keyvault-certificates azure-spring-boot-samples/azure-spring-boot-sample-keyvault-secrets azure-spring-boot-samples/azure-spring-boot-sample-mediaservices - azure-spring-boot-samples/azure-spring-boot-sample-servicebus azure-spring-boot-samples/azure-spring-boot-sample-servicebus-jms-queue azure-spring-boot-samples/azure-spring-boot-sample-servicebus-jms-topic + azure-spring-boot-samples/azure-spring-boot-sample-servicebus azure-spring-boot-samples/azure-spring-boot-sample-storage-resource - azure-spring-boot-samples/azure-spring-data-sample-gremlin - azure-spring-boot-samples/azure-spring-data-sample-gremlin-web-service - azure-spring-boot-samples/azure-cloud-foundry-service-sample - azure-spring-boot-samples/azure-spring-cloud-sample-appconfiguration azure-spring-boot-samples/azure-spring-cloud-sample-appconfiguration-conversion-complete azure-spring-boot-samples/azure-spring-cloud-sample-appconfiguration-conversion-initial + azure-spring-boot-samples/azure-spring-cloud-sample-appconfiguration azure-spring-boot-samples/azure-spring-cloud-sample-cache azure-spring-boot-samples/azure-spring-cloud-sample-eventhubs-binder azure-spring-boot-samples/azure-spring-cloud-sample-eventhubs-kafka azure-spring-boot-samples/azure-spring-cloud-sample-eventhubs-multibinders azure-spring-boot-samples/azure-spring-cloud-sample-eventhubs-operation - azure-spring-boot-samples/azure-spring-cloud-sample-feature-management azure-spring-boot-samples/azure-spring-cloud-sample-feature-management-web + azure-spring-boot-samples/azure-spring-cloud-sample-feature-management azure-spring-boot-samples/azure-spring-cloud-sample-messaging azure-spring-boot-samples/azure-spring-cloud-sample-servicebus-operation azure-spring-boot-samples/azure-spring-cloud-sample-servicebus-queue-binder azure-spring-boot-samples/azure-spring-cloud-sample-servicebus-queue-multibinders azure-spring-boot-samples/azure-spring-cloud-sample-servicebus-topic-binder azure-spring-boot-samples/azure-spring-cloud-sample-storage-queue-operation + azure-spring-boot-samples/azure-spring-data-sample-gremlin-web-service + azure-spring-boot-samples/azure-spring-data-sample-gremlin azure-spring-boot-samples/azure-spring-integration-sample-eventhubs azure-spring-boot-samples/azure-spring-integration-sample-servicebus azure-spring-boot-samples/azure-spring-integration-sample-storage-queue + azure-spring-boot-starter-active-directory-b2c + azure-spring-boot-starter-active-directory + azure-spring-boot-starter-cosmos + azure-spring-boot-starter-data-gremlin + azure-spring-boot-starter-keyvault-certificates + azure-spring-boot-starter-keyvault-secrets + azure-spring-boot-starter-servicebus-jms + azure-spring-boot-starter-storage + azure-spring-boot-starter + azure-spring-boot-test-aad-obo + azure-spring-boot-test-aad-resource-server-by-filter + azure-spring-boot-test-aad-resource-server + azure-spring-boot-test-aad + azure-spring-boot-test-application + azure-spring-boot-test-core + azure-spring-boot-test-cosmos + azure-spring-boot-test-keyvault + azure-spring-boot-test-servicebus-jms + azure-spring-boot-test-storage + azure-spring-boot azure-spring-cloud-autoconfigure azure-spring-cloud-context - azure-spring-cloud-storage - azure-spring-cloud-telemetry - azure-spring-data-gremlin - azure-spring-integration-core - azure-spring-integration-eventhubs - azure-spring-integration-servicebus - azure-spring-integration-storage-queue - azure-spring-integration-test azure-spring-cloud-messaging azure-spring-cloud-starter-cache - azure-spring-cloud-starter-eventhubs azure-spring-cloud-starter-eventhubs-kafka + azure-spring-cloud-starter-eventhubs azure-spring-cloud-starter-servicebus azure-spring-cloud-starter-storage-queue + azure-spring-cloud-storage azure-spring-cloud-stream-binder-eventhubs azure-spring-cloud-stream-binder-servicebus-core azure-spring-cloud-stream-binder-servicebus-queue azure-spring-cloud-stream-binder-servicebus-topic azure-spring-cloud-stream-binder-test + azure-spring-cloud-telemetry + azure-spring-cloud-test-eventhubs + azure-spring-data-gremlin + azure-spring-integration-core + azure-spring-integration-eventhubs + azure-spring-integration-servicebus + azure-spring-integration-storage-queue + azure-spring-integration-test diff --git a/sdk/spring/tests.yml b/sdk/spring/tests.yml index 8c3068a462b1d..9691f64bf1215 100644 --- a/sdk/spring/tests.yml +++ b/sdk/spring/tests.yml @@ -25,6 +25,12 @@ jobs: - name: azure-spring-boot-test-aad-obo groupId: com.azure.spring safeName: azurespringboottestaadobo + - name: azure-spring-boot-test-aad-resource-server + groupId: com.azure.spring + safeName: azurespringboottestaadresourceserver + - name: azure-spring-boot-test-aad-resource-server-by-filter + groupId: com.azure.spring + safeName: azurespringboottestaadresourceserverbyfilter - name: azure-spring-boot-test-keyvault groupId: com.azure.spring safeName: azurespringboottestkeyvault