diff --git a/security/providers/oidc-common/src/main/java/io/helidon/security/providers/oidc/common/OidcConfig.java b/security/providers/oidc-common/src/main/java/io/helidon/security/providers/oidc/common/OidcConfig.java index ba3dc2f34a7..1cc2d076fd7 100644 --- a/security/providers/oidc-common/src/main/java/io/helidon/security/providers/oidc/common/OidcConfig.java +++ b/security/providers/oidc-common/src/main/java/io/helidon/security/providers/oidc/common/OidcConfig.java @@ -22,7 +22,6 @@ import java.util.HashMap; import java.util.Locale; import java.util.Map; -import java.util.Optional; import java.util.function.Supplier; import io.helidon.common.Errors; diff --git a/security/providers/oidc/src/main/java/io/helidon/security/providers/oidc/TenantAuthenticationHandler.java b/security/providers/oidc/src/main/java/io/helidon/security/providers/oidc/TenantAuthenticationHandler.java index 430d58b5425..41a662caa38 100644 --- a/security/providers/oidc/src/main/java/io/helidon/security/providers/oidc/TenantAuthenticationHandler.java +++ b/security/providers/oidc/src/main/java/io/helidon/security/providers/oidc/TenantAuthenticationHandler.java @@ -331,7 +331,7 @@ private AuthenticationResponse errorResponse(ProviderRequest providerRequest, StringBuilder scopes = new StringBuilder(tenantConfig.baseScopes()); for (String expectedScope : expectedScopes) { - if (scopes.length() > 0) { + if (!scopes.isEmpty()) { // space after base scopes scopes.append(' '); } @@ -355,14 +355,12 @@ private AuthenticationResponse errorResponse(ProviderRequest providerRequest, + encode(oidcConfig.tenantParamName()) + "=" + encode(tenantId)); } - - StringBuilder queryString = new StringBuilder("?"); - queryString.append("client_id=").append(tenantConfig.clientId()).append("&"); - queryString.append("response_type=code&"); - queryString.append("redirect_uri=").append(redirectUri).append("&"); - queryString.append("scope=").append(scopeString).append("&"); - queryString.append("nonce=").append(nonce).append("&"); - queryString.append("state=").append(encode(state)); + String queryString = "?" + "client_id=" + tenantConfig.clientId() + "&" + + "response_type=code&" + + "redirect_uri=" + redirectUri + "&" + + "scope=" + scopeString + "&" + + "nonce=" + nonce + "&" + + "state=" + encode(state); // must redirect return AuthenticationResponse @@ -380,7 +378,7 @@ private AuthenticationResponse errorResponse(ProviderRequest providerRequest, private String redirectUri(SecurityEnvironment env) { for (Map.Entry> entry : env.headers().entrySet()) { if (entry.getKey().equalsIgnoreCase("host") && !entry.getValue().isEmpty()) { - String firstHost = entry.getValue().get(0); + String firstHost = entry.getValue().getFirst(); return oidcConfig.redirectUriWithHost(oidcConfig.forceHttpsRedirects() ? "https" : env.transport() + "://" + firstHost); } @@ -452,7 +450,7 @@ private String origUri(ProviderRequest providerRequest) { origUri = List.of(providerRequest.env().targetUri().getPath()); } - return origUri.get(0); + return origUri.getFirst(); } private String encode(String state) {