-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add scopes for graph and office client in test and sample (#18332)
- Loading branch information
1 parent
93194df
commit 45f182f
Showing
5 changed files
with
105 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 0 additions & 91 deletions
91
...-spring-boot-test-aad/src/test/java/com/azure/test/aad/selenium/RefreshTokenScopesIT.java
This file was deleted.
Oops, something went wrong.
92 changes: 92 additions & 0 deletions
92
...-aad/src/test/java/com/azure/test/aad/selenium/accessTokenScopes/AccessTokenScopesIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
|
||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
package com.azure.test.aad.selenium.accessTokenScopes; | ||
|
||
import com.azure.test.aad.selenium.SeleniumTestUtils; | ||
import com.azure.test.utils.AppRunner; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; | ||
import org.springframework.security.oauth2.client.OAuth2AuthorizedClient; | ||
import org.springframework.security.oauth2.client.annotation.RegisteredOAuth2AuthorizedClient; | ||
import org.springframework.security.oauth2.core.OAuth2AccessToken; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.util.*; | ||
|
||
public class AccessTokenScopesIT { | ||
|
||
@Test | ||
public void testAccessTokenScopes() { | ||
try (AppRunner app = new AppRunner(DumbApp.class)) { | ||
SeleniumTestUtils.addProperty(app); | ||
app.property("azure.activedirectory.authorization.office.scopes", "https://manage.office.com/ActivityFeed.Read , https://manage.office.com/ActivityFeed.ReadDlp , https://manage.office.com/ServiceHealth.Read"); | ||
app.property("azure.activedirectory.authorization.graph.scopes", "https://graph.microsoft.com/User.Read , https://graph.microsoft.com/Directory.AccessAsUser.All"); | ||
List<String> endPoints = new ArrayList<>(); | ||
endPoints.add("accessTokenScopes/azure"); | ||
endPoints.add("accessTokenScopes/office"); | ||
endPoints.add("accessTokenScopes/graph"); | ||
endPoints.add("accessTokenScopes/arm"); | ||
Map<String, String> result = SeleniumTestUtils.get(app, endPoints); | ||
|
||
Assert.assertFalse(result.get("accessTokenScopes/office").contains("profile")); | ||
Assert.assertTrue(result.get("accessTokenScopes/office").contains("https://manage.office.com/ActivityFeed.Read")); | ||
Assert.assertTrue(result.get("accessTokenScopes/office").contains("https://manage.office.com/ActivityFeed.ReadDlp")); | ||
Assert.assertTrue(result.get("accessTokenScopes/office").contains("https://manage.office.com/ServiceHealth.Read")); | ||
|
||
Assert.assertTrue(result.get("accessTokenScopes/azure").contains("profile")); | ||
Assert.assertTrue(result.get("accessTokenScopes/azure").contains("https://graph.microsoft.com/Directory.AccessAsUser.All")); | ||
Assert.assertTrue(result.get("accessTokenScopes/azure").contains("https://graph.microsoft.com/User.Read")); | ||
|
||
Assert.assertTrue(result.get("accessTokenScopes/graph").contains("profile")); | ||
Assert.assertTrue(result.get("accessTokenScopes/graph").contains("https://graph.microsoft.com/Directory.AccessAsUser.All")); | ||
Assert.assertTrue(result.get("accessTokenScopes/graph").contains("https://graph.microsoft.com/User.Read")); | ||
|
||
Assert.assertNotEquals("error", result.get("api/arm")); | ||
} | ||
} | ||
|
||
@EnableGlobalMethodSecurity(securedEnabled = true, prePostEnabled = true) | ||
@SpringBootApplication | ||
@RestController | ||
public static class DumbApp { | ||
|
||
@GetMapping(value = "accessTokenScopes/office") | ||
public Set<String> office( | ||
@RegisteredOAuth2AuthorizedClient("office") OAuth2AuthorizedClient authorizedClient) { | ||
return Optional.of(authorizedClient) | ||
.map(OAuth2AuthorizedClient::getAccessToken) | ||
.map(OAuth2AccessToken::getScopes) | ||
.orElse(null); | ||
} | ||
|
||
@GetMapping(value = "accessTokenScopes/azure") | ||
public Set<String> azure( | ||
@RegisteredOAuth2AuthorizedClient("azure") OAuth2AuthorizedClient authorizedClient) { | ||
return Optional.of(authorizedClient) | ||
.map(OAuth2AuthorizedClient::getAccessToken) | ||
.map(OAuth2AccessToken::getScopes) | ||
.orElse(null); | ||
} | ||
|
||
@GetMapping(value = "accessTokenScopes/graph") | ||
public Set<String> graph( | ||
@RegisteredOAuth2AuthorizedClient("graph") OAuth2AuthorizedClient authorizedClient) { | ||
return Optional.of(authorizedClient) | ||
.map(OAuth2AuthorizedClient::getAccessToken) | ||
.map(OAuth2AccessToken::getScopes) | ||
.orElse(null); | ||
} | ||
|
||
@GetMapping(value = "accessTokenScopes/arm") | ||
public String arm( | ||
@RegisteredOAuth2AuthorizedClient("arm") OAuth2AuthorizedClient authorizedClient) { | ||
return "error"; | ||
} | ||
} | ||
|
||
} |
3 changes: 2 additions & 1 deletion
3
...m/azure/test/aad/selenium/AADLoginIT.java → ...e/test/aad/selenium/login/AADLoginIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters