-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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
Changes from 2 commits
e78616e
bf486fc
6a4425c
f6f4378
3fef167
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 |
|---|---|---|
|
|
@@ -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,32 @@ 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 |
||
| Object endSessionEndpoint = clientRegistration.getProviderDetails().getConfigurationMetadata().get("end_session_endpoint"); | ||
|
|
||
| URI result = null; | ||
| if (endSessionEndpoint != null) { | ||
| result = URI.create(endSessionEndpoint.toString()); | ||
| } | ||
|
|
||
| return result; | ||
| } | ||
|
|
||
| private String endpointUri(URI endSessionEndpoint, Authentication authentication) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -67,7 +67,6 @@ | |
| import java.util.HashSet; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.Optional; | ||
|
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 is no need to change this file since it is a test. Please revert this change. 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. Reverted in f6f4378 |
||
| import java.util.Set; | ||
| import java.util.stream.Collectors; | ||
|
|
||
|
|
@@ -331,10 +330,14 @@ private void assertIndexPage(HtmlPage page) throws Exception { | |
| } | ||
|
|
||
| private HtmlAnchor getClientAnchorElement(HtmlPage page, ClientRegistration clientRegistration) { | ||
| Optional<HtmlAnchor> clientAnchorElement = page.getAnchors().stream() | ||
| .filter(e -> e.asText().equals(clientRegistration.getClientName())).findFirst(); | ||
|
|
||
| return (clientAnchorElement.orElse(null)); | ||
| HtmlAnchor result = null; | ||
| for (HtmlAnchor anchor: page.getAnchors()) { | ||
| if (anchor.asText().equals(clientRegistration.getClientName())) { | ||
| result = anchor; | ||
| break; | ||
| } | ||
| } | ||
| return result; | ||
| } | ||
|
|
||
| private WebResponse followLinkDisableRedirects(HtmlAnchor anchorElement) throws Exception { | ||
|
|
||
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
accessTokenResponseClientis null,clientCredentialsshould still be enabled. Please add anelsestatement containingauthorizedClientProviderBuilder.clientCredentials()to ensureclientCredentialsis 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