forked from Azure/azure-sdk-for-java
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support conditional access policy in obo flow. (Azure#18354)
- Loading branch information
Showing
17 changed files
with
237 additions
and
329 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
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
27 changes: 27 additions & 0 deletions
27
...ve-directory-webapp/src/main/java/com/azure/spring/sample/aad/config/WebClientConfig.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,27 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
package com.azure.spring.sample.aad.config; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.security.oauth2.client.registration.ClientRegistrationRepository; | ||
import org.springframework.security.oauth2.client.web.OAuth2AuthorizedClientRepository; | ||
import org.springframework.security.oauth2.client.web.reactive.function.client.ServletOAuth2AuthorizedClientExchangeFilterFunction; | ||
import org.springframework.web.reactive.function.client.WebClient; | ||
|
||
|
||
@Configuration | ||
public class WebClientConfig { | ||
|
||
@Bean | ||
public static WebClient webClient(ClientRegistrationRepository clientRegistrationRepository, | ||
OAuth2AuthorizedClientRepository authorizedClientRepository) { | ||
ServletOAuth2AuthorizedClientExchangeFilterFunction function = | ||
new ServletOAuth2AuthorizedClientExchangeFilterFunction(clientRegistrationRepository, | ||
authorizedClientRepository); | ||
return WebClient.builder() | ||
.apply(function.oauth2Configuration()) | ||
.build(); | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
...-webapp/src/main/java/com/azure/spring/sample/aad/controller/CallOboServerController.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,60 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
package com.azure.spring.sample.aad.controller; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.security.oauth2.client.OAuth2AuthorizedClient; | ||
import org.springframework.security.oauth2.client.annotation.RegisteredOAuth2AuthorizedClient; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.ResponseBody; | ||
import org.springframework.web.reactive.function.client.WebClient; | ||
|
||
|
||
import static org.springframework.security.oauth2.client.web.reactive.function.client.ServletOAuth2AuthorizedClientExchangeFilterFunction.oauth2AuthorizedClient; | ||
|
||
@Controller | ||
public class CallOboServerController { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(CallOboServerController.class); | ||
|
||
private static final String CUSTOM_LOCAL_FILE_ENDPOINT = "http://localhost:8081/call-custom"; | ||
|
||
@Autowired | ||
private WebClient webClient; | ||
|
||
/** | ||
* Call obo server, combine all the response and return. | ||
* @param obo authorized client for Custom | ||
* @return Response Graph and Custom data. | ||
*/ | ||
@GetMapping("/obo") | ||
@ResponseBody | ||
public String callOboServer(@RegisteredOAuth2AuthorizedClient("obo") OAuth2AuthorizedClient obo) { | ||
return callOboEndpoint(obo); | ||
} | ||
|
||
/** | ||
* Call obo local file endpoint | ||
* @param obo Authorized Client | ||
* @return Response string data. | ||
*/ | ||
private String callOboEndpoint(OAuth2AuthorizedClient obo) { | ||
if (null != obo) { | ||
String body = webClient | ||
.get() | ||
.uri(CUSTOM_LOCAL_FILE_ENDPOINT) | ||
.attributes(oauth2AuthorizedClient(obo)) | ||
.retrieve() | ||
.bodyToMono(String.class) | ||
.block(); | ||
LOGGER.info("Response from obo server: {}", body); | ||
return "Obo server response " + (null != body ? "success." : "failed."); | ||
} else { | ||
return "Obo server response failed."; | ||
} | ||
} | ||
} |
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
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
59 changes: 0 additions & 59 deletions
59
...pring-boot/src/main/java/com/azure/spring/aad/webapp/AADAuthenticationFailureHandler.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.