-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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 #16388 from fwippe/oidc_client_names
Oidc-Client: Allow named injections of OidcClients and Tokens
- Loading branch information
Showing
13 changed files
with
410 additions
and
18 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
21 changes: 21 additions & 0 deletions
21
.../deployment/src/main/java/io/quarkus/oidc/client/deployment/OidcClientNamesBuildItem.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,21 @@ | ||
package io.quarkus.oidc.client.deployment; | ||
|
||
import java.util.Collections; | ||
import java.util.Set; | ||
|
||
import io.quarkus.builder.item.SimpleBuildItem; | ||
|
||
/** | ||
* Contains non-default names of OIDC Clients. | ||
*/ | ||
public final class OidcClientNamesBuildItem extends SimpleBuildItem { | ||
private final Set<String> oidcClientNames; | ||
|
||
OidcClientNamesBuildItem(Set<String> oidcClientNames) { | ||
this.oidcClientNames = Collections.unmodifiableSet(oidcClientNames); | ||
} | ||
|
||
Set<String> oidcClientNames() { | ||
return oidcClientNames; | ||
} | ||
} |
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
67 changes: 67 additions & 0 deletions
67
...ent/deployment/src/test/java/io/quarkus/oidc/client/NamedOidcClientInjectionTestCase.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,67 @@ | ||
package io.quarkus.oidc.client; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.equalTo; | ||
import static org.hamcrest.Matchers.is; | ||
import static org.hamcrest.Matchers.not; | ||
import static org.hamcrest.Matchers.notNullValue; | ||
|
||
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 io.quarkus.oidc.runtime.OidcUtils; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.quarkus.test.common.QuarkusTestResource; | ||
import io.restassured.RestAssured; | ||
|
||
@QuarkusTestResource(KeycloakRealmUserPasswordManager.class) | ||
public class NamedOidcClientInjectionTestCase { | ||
|
||
private static Class<?>[] testClasses = { | ||
NamedOidcClientResource.class | ||
}; | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest test = new QuarkusUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(testClasses) | ||
.addAsResource("application-named-oidc-client-credentials.properties", "application.properties")); | ||
|
||
@Test | ||
public void testInjectedNamedOidcClients() { | ||
String token1 = doTestGetTokenByNamedClient("client1"); | ||
String token2 = doTestGetTokenByNamedClient("client2"); | ||
validateTokens(token1, token2); | ||
} | ||
|
||
@Test | ||
public void testInjectedNamedTokens() { | ||
String token1 = doTestGetTokenByNamedTokensProvider("client1"); | ||
String token2 = doTestGetTokenByNamedTokensProvider("client2"); | ||
validateTokens(token1, token2); | ||
} | ||
|
||
private void validateTokens(String token1, String token2) { | ||
assertThat(token1, is(not(equalTo(token2)))); | ||
assertThat(preferredUserOf(token1), is("alice")); | ||
assertThat(preferredUserOf(token2), is("bob")); | ||
} | ||
|
||
private String preferredUserOf(String token) { | ||
return OidcUtils.decodeJwtContent(token).getString("preferred_username"); | ||
} | ||
|
||
private String doTestGetTokenByNamedClient(String clientId) { | ||
String token = RestAssured.when().get("/" + clientId + "/token").body().asString(); | ||
assertThat(token, is(notNullValue())); | ||
return token; | ||
} | ||
|
||
private String doTestGetTokenByNamedTokensProvider(String clientId) { | ||
String token = RestAssured.when().get("/" + clientId + "/token/singleton").body().asString(); | ||
assertThat(token, is(notNullValue())); | ||
return token; | ||
} | ||
} |
Oops, something went wrong.