forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enhance OidcClientFilter to select named OIDC clients
closes: quarkusio#16397
- Loading branch information
1 parent
e151807
commit eedbda0
Showing
43 changed files
with
952 additions
and
166 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
17 changes: 17 additions & 0 deletions
17
...rc/main/java/io/quarkus/oidc/client/filter/deployment/NamedOidcClientFilterBuildItem.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,17 @@ | ||
package io.quarkus.oidc.client.filter.deployment; | ||
|
||
import java.util.Set; | ||
|
||
import io.quarkus.builder.item.SimpleBuildItem; | ||
|
||
/** | ||
* Contains a list of all Rest clients annotated with @OidcClientFilter("someClientName"). | ||
*/ | ||
public final class NamedOidcClientFilterBuildItem extends SimpleBuildItem { | ||
|
||
final Set<String> namedFilterClientClasses; | ||
|
||
NamedOidcClientFilterBuildItem(Set<String> namedFilterClientClasses) { | ||
this.namedFilterClientClasses = Set.copyOf(namedFilterClientClasses); | ||
} | ||
} |
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
...loyment/src/test/java/io/quarkus/oidc/client/filter/ConfigPropertyOidcClientResource.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.filter; | ||
|
||
import javax.inject.Inject; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
|
||
import org.eclipse.microprofile.rest.client.inject.RestClient; | ||
|
||
@Path("/config-property-oidc-client") | ||
public class ConfigPropertyOidcClientResource { | ||
|
||
@Inject | ||
@RestClient | ||
ProtectedResourceServiceConfigPropertyOidcClient protectedResourceServiceConfigPropertyOidcClient; | ||
|
||
@GET | ||
@Path("user-name") | ||
public String userName() { | ||
return protectedResourceServiceConfigPropertyOidcClient.getUserName(); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
...loyment/src/test/java/io/quarkus/oidc/client/filter/NamedOidcClientFilterDevModeTest.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,45 @@ | ||
package io.quarkus.oidc.client.filter; | ||
|
||
import static org.hamcrest.Matchers.equalTo; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.QuarkusDevModeTest; | ||
import io.quarkus.test.common.QuarkusTestResource; | ||
import io.quarkus.test.keycloak.server.KeycloakTestResourceLifecycleManager; | ||
import io.restassured.RestAssured; | ||
|
||
@QuarkusTestResource(KeycloakTestResourceLifecycleManager.class) | ||
public class NamedOidcClientFilterDevModeTest { | ||
|
||
private static final Class<?>[] testClasses = { | ||
ProtectedResource.class, | ||
ProtectedResourceServiceNamedOidcClient.class, | ||
ProtectedResourceServiceConfigPropertyOidcClient.class, | ||
NamedOidcClientResource.class, | ||
ConfigPropertyOidcClientResource.class | ||
}; | ||
|
||
@RegisterExtension | ||
static final QuarkusDevModeTest test = new QuarkusDevModeTest() | ||
.withApplicationRoot((jar) -> jar | ||
.addClasses(testClasses) | ||
.addAsResource("application-named-oidc-client-filter.properties", "application.properties")); | ||
|
||
@Test | ||
public void testGerUserConfigPropertyAndAnnotation() { | ||
// OidcClient selected via @OidcClient("clientName") | ||
RestAssured.when().get("/named-oidc-client/user-name") | ||
.then() | ||
.statusCode(200) | ||
.body(equalTo("jdoe")); | ||
|
||
// OidcClient selected via `quarkus.oidc-client-filter.client-name=config-property` | ||
RestAssured.when().get("/config-property-oidc-client/user-name") | ||
.then() | ||
.statusCode(200) | ||
.body(equalTo("alice")); | ||
} | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
...ilter/deployment/src/test/java/io/quarkus/oidc/client/filter/NamedOidcClientResource.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.filter; | ||
|
||
import javax.inject.Inject; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
|
||
import org.eclipse.microprofile.rest.client.inject.RestClient; | ||
|
||
@Path("/named-oidc-client") | ||
public class NamedOidcClientResource { | ||
|
||
@Inject | ||
@RestClient | ||
ProtectedResourceServiceNamedOidcClient protectedResourceServiceNamedOidcClient; | ||
|
||
@GET | ||
@Path("user-name") | ||
public String userName() { | ||
return protectedResourceServiceNamedOidcClient.getUserName(); | ||
} | ||
} |
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
15 changes: 15 additions & 0 deletions
15
.../java/io/quarkus/oidc/client/filter/ProtectedResourceServiceConfigPropertyOidcClient.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,15 @@ | ||
package io.quarkus.oidc.client.filter; | ||
|
||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
|
||
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient; | ||
|
||
@OidcClientFilter | ||
@RegisterRestClient | ||
@Path("/") | ||
public interface ProtectedResourceServiceConfigPropertyOidcClient { | ||
|
||
@GET | ||
String getUserName(); | ||
} |
15 changes: 15 additions & 0 deletions
15
.../src/test/java/io/quarkus/oidc/client/filter/ProtectedResourceServiceNamedOidcClient.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,15 @@ | ||
package io.quarkus.oidc.client.filter; | ||
|
||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
|
||
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient; | ||
|
||
@OidcClientFilter("named") | ||
@RegisterRestClient | ||
@Path("/") | ||
public interface ProtectedResourceServiceNamedOidcClient { | ||
|
||
@GET | ||
String getUserName(); | ||
} |
23 changes: 23 additions & 0 deletions
23
...ient-filter/deployment/src/test/resources/application-named-oidc-client-filter.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,23 @@ | ||
quarkus.oidc.auth-server-url=${keycloak.url}/realms/quarkus/ | ||
quarkus.oidc.client-id=quarkus-service-app | ||
quarkus.oidc.credentials.secret=secret | ||
|
||
quarkus.oidc-client-filter.client-name=config-property | ||
quarkus.oidc-client.config-property.auth-server-url=${quarkus.oidc.auth-server-url} | ||
quarkus.oidc-client.config-property.client-id=${quarkus.oidc.client-id} | ||
quarkus.oidc-client.config-property.credentials.client-secret.value=${quarkus.oidc.credentials.secret} | ||
quarkus.oidc-client.config-property.credentials.client-secret.method=POST | ||
quarkus.oidc-client.config-property.grant.type=password | ||
quarkus.oidc-client.config-property.grant-options.password.username=alice | ||
quarkus.oidc-client.config-property.grant-options.password.password=alice | ||
|
||
quarkus.oidc-client.named.auth-server-url=${quarkus.oidc.auth-server-url} | ||
quarkus.oidc-client.named.client-id=${quarkus.oidc.client-id} | ||
quarkus.oidc-client.named.credentials.client-secret.value=${quarkus.oidc.credentials.secret} | ||
quarkus.oidc-client.named.credentials.client-secret.method=POST | ||
quarkus.oidc-client.named.grant.type=password | ||
quarkus.oidc-client.named.grant-options.password.username=jdoe | ||
quarkus.oidc-client.named.grant-options.password.password=jdoe | ||
|
||
io.quarkus.oidc.client.filter.ProtectedResourceServiceNamedOidcClient/mp-rest/url=http://localhost:8080/protected | ||
io.quarkus.oidc.client.filter.ProtectedResourceServiceConfigPropertyOidcClient/mp-rest/url=http://localhost:8080/protected |
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
Oops, something went wrong.