1
0
mirror of synced 2026-08-04 09:17:02 +00:00

Remove internal Optional usage in favor of null checks

Issue gh-7155
This commit is contained in:
watsta
2019-08-26 15:27:40 +02:00
committed by Eleftheria Stein-Kousathana
parent 2c2d3b5d85
commit 2c2e8e5f24
9 changed files with 101 additions and 75 deletions
@@ -71,13 +71,19 @@ final class OAuth2ClientConfiguration {
@Override
public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
if (this.clientRegistrationRepository != null && this.authorizedClientRepository != null) {
OAuth2AuthorizedClientProvider authorizedClientProvider =
OAuth2AuthorizedClientProviderBuilder authorizedClientProviderBuilder =
OAuth2AuthorizedClientProviderBuilder.builder()
.authorizationCode()
.refreshToken()
.clientCredentials(configurer ->
Optional.ofNullable(this.accessTokenResponseClient).ifPresent(configurer::accessTokenResponseClient))
.build();
.refreshToken();
if (this.accessTokenResponseClient != null) {
authorizedClientProviderBuilder.clientCredentials(configurer ->
configurer.accessTokenResponseClient(this.accessTokenResponseClient));
} else {
authorizedClientProviderBuilder.clientCredentials();
}
OAuth2AuthorizedClientProvider authorizedClientProvider = authorizedClientProviderBuilder.build();
DefaultOAuth2AuthorizedClientManager authorizedClientManager = new DefaultOAuth2AuthorizedClientManager(
this.clientRegistrationRepository, this.authorizedClientRepository);
authorizedClientManager.setAuthorizedClientProvider(authorizedClientProvider);
@@ -27,7 +27,6 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.UUID;
import java.util.function.Function;
import java.util.function.Supplier;
@@ -2665,10 +2664,10 @@ public class ServerHttpSecurity {
}
protected void configure(ServerHttpSecurity http) {
Optional.ofNullable(this.csrfTokenRepository).ifPresent(serverCsrfTokenRepository -> {
this.filter.setCsrfTokenRepository(serverCsrfTokenRepository);
http.logout().addLogoutHandler(new CsrfServerLogoutHandler(serverCsrfTokenRepository));
});
if (this.csrfTokenRepository != null) {
this.filter.setCsrfTokenRepository(this.csrfTokenRepository);
http.logout().addLogoutHandler(new CsrfServerLogoutHandler(this.csrfTokenRepository));
}
http.addFilterAt(this.filter, SecurityWebFiltersOrder.CSRF);
}
@@ -3607,19 +3606,21 @@ public class ServerHttpSecurity {
return and();
}
private Optional<ServerLogoutHandler> createLogoutHandler() {
private ServerLogoutHandler createLogoutHandler() {
if (this.logoutHandlers.isEmpty()) {
return Optional.empty();
return null;
} else if (this.logoutHandlers.size() == 1) {
return this.logoutHandlers.get(0);
} else {
return new DelegatingServerLogoutHandler(this.logoutHandlers);
}
else if (this.logoutHandlers.size() == 1) {
return Optional.of(this.logoutHandlers.get(0));
}
return Optional.of(new DelegatingServerLogoutHandler(this.logoutHandlers));
}
protected void configure(ServerHttpSecurity http) {
createLogoutHandler().ifPresent(this.logoutWebFilter::setLogoutHandler);
ServerLogoutHandler logoutHandler = createLogoutHandler();
if (logoutHandler != null) {
this.logoutWebFilter.setLogoutHandler(logoutHandler);
}
http.addFilterAt(this.logoutWebFilter, SecurityWebFiltersOrder.LOGOUT);
}