-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Remove internal Optional usage in favor of null checks #7295
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
Merged
eleftherias
merged 5 commits into
spring-projects:master
from
krisztian-toth:gh-7155-remove-optional-usage
Aug 26, 2019
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e78616e
Remove internal Optional usage in favor of null checks
krisztian-toth bf486fc
Merge branches 'gh-7155-remove-optional-usage' and 'master' of https:…
krisztian-toth 6a4425c
Fix possible NPE in OidcClientInitiatedLogoutSuccessHandler#endSessio…
krisztian-toth f6f4378
Revert changes in test file
krisztian-toth 3fef167
Add missing else branch in OAuth2ClientWebMvcSecurityConfiguration#ad…
krisztian-toth File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -18,7 +18,6 @@ | |
|
||
import java.net.URI; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.Optional; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
|
||
|
@@ -52,25 +51,34 @@ public OidcClientInitiatedLogoutSuccessHandler(ClientRegistrationRepository clie | |
@Override | ||
protected String determineTargetUrl(HttpServletRequest request, | ||
HttpServletResponse response, Authentication authentication) { | ||
String targetUrl = null; | ||
URI endSessionEndpoint; | ||
if (authentication instanceof OAuth2AuthenticationToken && authentication.getPrincipal() instanceof OidcUser) { | ||
endSessionEndpoint = this.endSessionEndpoint((OAuth2AuthenticationToken) authentication); | ||
if (endSessionEndpoint != null) { | ||
targetUrl = endpointUri(endSessionEndpoint, authentication); | ||
} | ||
} | ||
if (targetUrl == null) { | ||
targetUrl = super.determineTargetUrl(request, response); | ||
} | ||
|
||
return Optional.of(authentication) | ||
.filter(OAuth2AuthenticationToken.class::isInstance) | ||
.filter(token -> authentication.getPrincipal() instanceof OidcUser) | ||
.map(OAuth2AuthenticationToken.class::cast) | ||
.flatMap(this::endSessionEndpoint) | ||
.map(endSessionEndpoint -> endpointUri(endSessionEndpoint, authentication)) | ||
.orElseGet(() -> super.determineTargetUrl(request, response)); | ||
return targetUrl; | ||
} | ||
|
||
private Optional<URI> endSessionEndpoint(OAuth2AuthenticationToken token) { | ||
private URI endSessionEndpoint(OAuth2AuthenticationToken token) { | ||
String registrationId = token.getAuthorizedClientRegistrationId(); | ||
return Optional.of( | ||
this.clientRegistrationRepository.findByRegistrationId(registrationId)) | ||
.map(ClientRegistration::getProviderDetails) | ||
.map(ClientRegistration.ProviderDetails::getConfigurationMetadata) | ||
.map(configurationMetadata -> configurationMetadata.get("end_session_endpoint")) | ||
.map(Object::toString) | ||
.map(URI::create); | ||
ClientRegistration clientRegistration = this.clientRegistrationRepository.findByRegistrationId(registrationId); | ||
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.
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. Fixed in 6a4425c |
||
|
||
URI result = null; | ||
if (clientRegistration != null) { | ||
Object endSessionEndpoint = clientRegistration.getProviderDetails().getConfigurationMetadata().get("end_session_endpoint"); | ||
if (endSessionEndpoint != null) { | ||
result = URI.create(endSessionEndpoint.toString()); | ||
} | ||
} | ||
|
||
return result; | ||
} | ||
|
||
private String endpointUri(URI endSessionEndpoint, Authentication authentication) { | ||
|
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This code changes the existing functionality. If
accessTokenResponseClient
is null,clientCredentials
should still be enabled. Please add anelse
statement containingauthorizedClientProviderBuilder.clientCredentials()
to ensureclientCredentials
is enabled by default.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.
Updated in 3fef167