-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16060 from sberyozkin/oidc_request_retry
Update OIDC client code to retry in case of the connection errors and have OIDC starting without the complete config
- Loading branch information
Showing
12 changed files
with
183 additions
and
12 deletions.
There are no files selected for viewing
This file contains 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 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 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
20 changes: 20 additions & 0 deletions
20
...ent/runtime/src/main/java/io/quarkus/oidc/client/runtime/DisabledOidcClientException.java
This file contains 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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package io.quarkus.oidc.client.runtime; | ||
|
||
@SuppressWarnings("serial") | ||
public class DisabledOidcClientException extends RuntimeException { | ||
public DisabledOidcClientException() { | ||
|
||
} | ||
|
||
public DisabledOidcClientException(String errorMessage) { | ||
this(errorMessage, null); | ||
} | ||
|
||
public DisabledOidcClientException(Throwable cause) { | ||
this(null, cause); | ||
} | ||
|
||
public DisabledOidcClientException(String errorMessage, Throwable cause) { | ||
super(errorMessage, cause); | ||
} | ||
} |
This file contains 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 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
74 changes: 74 additions & 0 deletions
74
...c/deployment/src/test/java/io/quarkus/oidc/test/CodeFlowDevModeDefaultTenantTestCase.java
This file contains 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 |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package io.quarkus.oidc.test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.fail; | ||
|
||
import java.io.IOException; | ||
|
||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException; | ||
import com.gargoylesoftware.htmlunit.SilentCssErrorHandler; | ||
import com.gargoylesoftware.htmlunit.WebClient; | ||
import com.gargoylesoftware.htmlunit.html.HtmlForm; | ||
import com.gargoylesoftware.htmlunit.html.HtmlPage; | ||
|
||
import io.quarkus.test.QuarkusDevModeTest; | ||
import io.quarkus.test.common.QuarkusTestResource; | ||
|
||
@QuarkusTestResource(KeycloakDevModeRealmResourceManager.class) | ||
public class CodeFlowDevModeDefaultTenantTestCase { | ||
|
||
private static Class<?>[] testClasses = { | ||
ProtectedResource.class, | ||
UnprotectedResource.class | ||
}; | ||
|
||
@RegisterExtension | ||
static final QuarkusDevModeTest test = new QuarkusDevModeTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(testClasses) | ||
.addAsResource("application-dev-mode-default-tenant.properties", "application.properties")); | ||
|
||
@Test | ||
public void testAccessAndRefreshTokenInjectionDevMode() throws IOException, InterruptedException { | ||
try (final WebClient webClient = createWebClient()) { | ||
|
||
try { | ||
webClient.getPage("http://localhost:8080/protected"); | ||
fail("Exception is expected because auth-server-url is not available and the authentication can not be completed"); | ||
} catch (FailingHttpStatusCodeException ex) { | ||
// Reported by Quarkus | ||
assertEquals(500, ex.getStatusCode()); | ||
} | ||
|
||
// Enable auth-server-url | ||
test.modifyResourceFile("application.properties", | ||
s -> s.replace("#quarkus.oidc.auth-server-url", "quarkus.oidc.auth-server-url")); | ||
|
||
HtmlPage page = webClient.getPage("http://localhost:8080/protected"); | ||
|
||
assertEquals("Sign in to devmode", page.getTitleText()); | ||
|
||
HtmlForm loginForm = page.getForms().get(0); | ||
|
||
loginForm.getInputByName("username").setValueAttribute("alice-dev-mode"); | ||
loginForm.getInputByName("password").setValueAttribute("alice-dev-mode"); | ||
|
||
page = loginForm.getInputByName("login").click(); | ||
|
||
assertEquals("alice-dev-mode", page.getBody().asText()); | ||
|
||
webClient.getCookieManager().clearCookies(); | ||
} | ||
} | ||
|
||
private WebClient createWebClient() { | ||
WebClient webClient = new WebClient(); | ||
webClient.setCssErrorHandler(new SilentCssErrorHandler()); | ||
return webClient; | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
extensions/oidc/deployment/src/test/resources/application-dev-mode-default-tenant.properties
This file contains 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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#quarkus.oidc.auth-server-url=${keycloak.url}/realms/devmode | ||
quarkus.oidc.client-id=client-dev-mode | ||
quarkus.oidc.application-type=web-app | ||
|
||
quarkus.log.category."com.gargoylesoftware.htmlunit.javascript.host.css.CSSStyleSheet".level=FATAL | ||
|
This file contains 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 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 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 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