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.
Add one more OIDC tenant-paths resolution test
- Loading branch information
1 parent
ecdf3ea
commit 9ae780f
Showing
4 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
integration-tests/oidc-wiremock/src/main/java/io/quarkus/it/keycloak/UploadResource.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,24 @@ | ||
package io.quarkus.it.keycloak; | ||
|
||
import jakarta.annotation.security.RolesAllowed; | ||
import jakarta.inject.Inject; | ||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.Path; | ||
import jakarta.ws.rs.Produces; | ||
import jakarta.ws.rs.core.MediaType; | ||
|
||
import io.quarkus.security.identity.SecurityIdentity; | ||
|
||
@Path("/upload") | ||
public class UploadResource { | ||
|
||
@Inject | ||
SecurityIdentity identity; | ||
|
||
@GET | ||
@RolesAllowed("admin") | ||
@Produces(MediaType.APPLICATION_JSON) | ||
public String bearerCertificateCustomValidator() { | ||
return "granted:" + identity.getRoles(); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
...-tests/oidc-wiremock/src/main/java/io/quarkus/it/keycloak/UploadsTokenChainValidator.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,34 @@ | ||
package io.quarkus.it.keycloak; | ||
|
||
import java.security.cert.CertificateException; | ||
import java.security.cert.X509Certificate; | ||
import java.util.List; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
|
||
import io.quarkus.arc.Unremovable; | ||
import io.quarkus.oidc.OidcTenantConfig; | ||
import io.quarkus.oidc.TenantFeature; | ||
import io.quarkus.oidc.TokenCertificateValidator; | ||
import io.quarkus.oidc.runtime.TrustStoreUtils; | ||
import io.vertx.core.json.JsonObject; | ||
|
||
@ApplicationScoped | ||
@Unremovable | ||
@TenantFeature("uploads") | ||
public class UploadsTokenChainValidator implements TokenCertificateValidator { | ||
|
||
@Override | ||
public void validate(OidcTenantConfig oidcConfig, List<X509Certificate> chain, String tokenClaims) | ||
throws CertificateException { | ||
if (!"uploads".equals(oidcConfig.tenantId.get())) { | ||
throw new RuntimeException("Unexpected tenant id"); | ||
} | ||
String leafCertificateThumbprint = TrustStoreUtils.calculateThumprint(chain.get(0)); | ||
JsonObject claims = new JsonObject(tokenClaims); | ||
if (!leafCertificateThumbprint.equals(claims.getString("leaf-certificate-thumbprint"))) { | ||
throw new CertificateException("Invalid leaf certificate"); | ||
} | ||
} | ||
|
||
} |
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