-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Fix bugs about connect to Azure AD by proxy #31213
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
5470386
8836ab2
88b1e04
5af9bed
a647731
057d4ab
d76c78a
9f7fbf9
0f5851f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,11 +4,10 @@ | |
| package com.azure.spring.cloud.autoconfigure.aad.implementation.oauth2; | ||
|
|
||
| import com.azure.spring.cloud.core.implementation.util.AzureSpringIdentifier; | ||
| import org.springframework.core.convert.converter.Converter; | ||
| import org.springframework.http.HttpHeaders; | ||
| import org.springframework.http.RequestEntity; | ||
| import org.springframework.security.oauth2.client.endpoint.OAuth2AuthorizationCodeGrantRequest; | ||
| import org.springframework.security.oauth2.client.endpoint.OAuth2AuthorizationCodeGrantRequestEntityConverter; | ||
| import org.springframework.util.LinkedMultiValueMap; | ||
| import org.springframework.util.MultiValueMap; | ||
|
|
||
| import java.util.Collections; | ||
|
|
@@ -20,25 +19,17 @@ | |
| public abstract class AbstractOAuth2AuthorizationCodeGrantRequestEntityConverter | ||
| extends OAuth2AuthorizationCodeGrantRequestEntityConverter { | ||
|
|
||
| protected AbstractOAuth2AuthorizationCodeGrantRequestEntityConverter() { | ||
| addHeadersConverter((request) -> getHttpHeaders()); | ||
| addParametersConverter(this::getHttpBody); | ||
| } | ||
|
|
||
| /** | ||
| * Gets the application ID. | ||
| * | ||
| * @return the application ID | ||
| */ | ||
| protected abstract String getApplicationId(); | ||
|
|
||
| @Override | ||
| @SuppressWarnings("unchecked") | ||
| public RequestEntity<?> convert(OAuth2AuthorizationCodeGrantRequest request) { | ||
| addHeadersConverter(headersConverter); | ||
| addParametersConverter(parametersConverter); | ||
| return super.convert(request); | ||
| } | ||
|
|
||
| private final Converter<OAuth2AuthorizationCodeGrantRequest, HttpHeaders> headersConverter = (request) -> getHttpHeaders(); | ||
|
|
||
| private final Converter<OAuth2AuthorizationCodeGrantRequest, MultiValueMap<String, String>> parametersConverter = this::getHttpBody; | ||
|
|
||
| /** | ||
| * Additional default headers information. | ||
| * @return HttpHeaders | ||
|
|
@@ -57,6 +48,6 @@ public HttpHeaders getHttpHeaders() { | |
| * @return MultiValueMap | ||
| */ | ||
| public MultiValueMap<String, String> getHttpBody(OAuth2AuthorizationCodeGrantRequest request) { | ||
| return null; | ||
| return new LinkedMultiValueMap<>(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My personal preference would be to return an immutable collection here, if possible. Hence my suggestion of Maybe even have a static field to return, so there is no repeated allocation.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point. Will accept this suggestion. |
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,6 +13,7 @@ | |
| import javax.servlet.http.HttpServletResponse; | ||
| import javax.servlet.http.HttpSession; | ||
| import java.util.Collections; | ||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
| import java.util.Optional; | ||
|
|
||
|
|
@@ -48,10 +49,10 @@ public void saveAuthorizedClient(OAuth2AuthorizedClient authorizedClient, Authen | |
| Assert.notNull(authorizedClient, "authorizedClient cannot be null"); | ||
| Assert.notNull(request, MSG_REQUEST_CANNOT_BE_NULL); | ||
| Assert.notNull(response, "response cannot be null"); | ||
| Map<String, OAuth2AuthorizedClient> authorizedClients = this.getAuthorizedClients(request); | ||
| Map<String, OAuth2AuthorizedClient> authorizedClients = new HashMap<>(this.getAuthorizedClients(request)); | ||
| authorizedClients.put(authorizedClient.getClientRegistration().getRegistrationId(), authorizedClient); | ||
| request.getSession().setAttribute(AUTHORIZED_CLIENTS_ATTR_NAME, | ||
| serializeOAuth2AuthorizedClientMap(authorizedClients)); | ||
| serializeOAuth2AuthorizedClientMap(Collections.unmodifiableMap(authorizedClients))); | ||
| } | ||
|
|
||
| @Override | ||
|
|
@@ -77,6 +78,6 @@ private Map<String, OAuth2AuthorizedClient> getAuthorizedClients(HttpServletRequ | |
| .map(s -> s.getAttribute(AUTHORIZED_CLIENTS_ATTR_NAME)) | ||
| .map(Object::toString) | ||
| .map(SerializerUtils::deserializeOAuth2AuthorizedClientMap) | ||
| .orElse(Collections.emptyMap()); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wouldn't do this, as it means the execution of an additional lambda, whereas the
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @0x006EA1E5 But I have different understanding:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, yes, you are right, it is a method reference so the lambda doesn't need to be created. When I mentioned cost saving, I meant different scenario which doesn't apply here: vs Where the second is obviously preferable, even with the extra lambda. In any case, I suspect that the performance of Thanks for the response, please ignore my change suggestion :)
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got it. Thank you for your detailed explanation. |
||
| .orElseGet(Collections::emptyMap); | ||
| } | ||
| } | ||

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about making this
public HttpHeaders getHttpHeaders(OAuth2AuthorizationCodeGrantRequest request) {?This is an abstract class, it seems like it seems like it might be nice to give implementors access to the request parameter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do.