|
| 1 | +// Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | +// Licensed under the MIT License. |
| 3 | + |
| 4 | +package com.azure.test.aad.selenium.multitenant; |
| 5 | + |
| 6 | +import com.azure.test.aad.selenium.AADSeleniumITHelper; |
| 7 | +import org.junit.After; |
| 8 | +import org.junit.Assert; |
| 9 | +import org.junit.Test; |
| 10 | +import org.slf4j.Logger; |
| 11 | +import org.slf4j.LoggerFactory; |
| 12 | +import org.springframework.boot.autoconfigure.SpringBootApplication; |
| 13 | +import org.springframework.http.ResponseEntity; |
| 14 | +import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; |
| 15 | +import org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken; |
| 16 | +import org.springframework.web.bind.annotation.GetMapping; |
| 17 | +import org.springframework.web.bind.annotation.RestController; |
| 18 | + |
| 19 | +import java.security.Principal; |
| 20 | +import java.util.HashMap; |
| 21 | +import java.util.Map; |
| 22 | + |
| 23 | +import static com.azure.spring.test.EnvironmentVariable.AAD_MULTI_TENANT_CLIENT_ID; |
| 24 | +import static com.azure.spring.test.EnvironmentVariable.AAD_MULTI_TENANT_CLIENT_SECRET; |
| 25 | +import static com.azure.spring.test.EnvironmentVariable.AAD_USER_NAME_2; |
| 26 | +import static com.azure.spring.test.EnvironmentVariable.AAD_USER_PASSWORD_2; |
| 27 | + |
| 28 | +public class AADMultipleTenantIT { |
| 29 | + private static final Logger LOGGER = LoggerFactory.getLogger(AADMultipleTenantIT.class); |
| 30 | + private AADSeleniumITHelper aadSeleniumITHelper; |
| 31 | + |
| 32 | + @Test |
| 33 | + public void multipleTenantTest() { |
| 34 | + Map<String, String> properties = new HashMap<>(); |
| 35 | + properties.put("azure.activedirectory.client-id", AAD_MULTI_TENANT_CLIENT_ID); |
| 36 | + properties.put("azure.activedirectory.client-secret", AAD_MULTI_TENANT_CLIENT_SECRET); |
| 37 | + aadSeleniumITHelper = new AADSeleniumITHelper(DumbApp.class, properties, |
| 38 | + AAD_USER_NAME_2, AAD_USER_PASSWORD_2); |
| 39 | + aadSeleniumITHelper.logIn(); |
| 40 | + |
| 41 | + String httpResponse = aadSeleniumITHelper.httpGet("api/home"); |
| 42 | + Assert.assertTrue(httpResponse.contains("home")); |
| 43 | + } |
| 44 | + |
| 45 | + @After |
| 46 | + public void destroy() { |
| 47 | + aadSeleniumITHelper.destroy(); |
| 48 | + } |
| 49 | + |
| 50 | + @EnableGlobalMethodSecurity(securedEnabled = true, prePostEnabled = true) |
| 51 | + @SpringBootApplication |
| 52 | + @RestController |
| 53 | + public static class DumbApp { |
| 54 | + |
| 55 | + @GetMapping(value = "/api/home") |
| 56 | + public ResponseEntity<String> home(Principal principal) { |
| 57 | + LOGGER.info(((OAuth2AuthenticationToken) principal).getAuthorities().toString()); |
| 58 | + return ResponseEntity.ok("home"); |
| 59 | + } |
| 60 | + } |
| 61 | +} |
0 commit comments