Skip to content

Commit

Permalink
Merge pull request #20151 from sberyozkin/oidc_test_identity_augmento…
Browse files Browse the repository at this point in the history
…r_rsa

Update OidcTestSecurityIdentityAugmentorProducer to generate a single RSA key
  • Loading branch information
stuartwdouglas authored Sep 14, 2021
2 parents 1261ed0 + 91c4edb commit c1cbb7b
Showing 1 changed file with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package io.quarkus.test.security.oidc;

import java.lang.annotation.Annotation;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.util.Optional;
import java.util.UUID;
import java.util.stream.Collectors;

import javax.annotation.PostConstruct;
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.inject.Produces;
import javax.inject.Inject;
Expand Down Expand Up @@ -37,6 +40,17 @@ public class OidcTestSecurityIdentityAugmentorProducer {
@ConfigProperty(name = "quarkus.oidc.token.issuer")
Optional<String> issuer;

PrivateKey privateKey;

@PostConstruct
public void init() {
try {
privateKey = KeyUtils.generateKeyPair(2048).getPrivate();
} catch (NoSuchAlgorithmException ex) {
throw new RuntimeException(ex);
}
}

@Produces
@Unremovable
public TestSecurityIdentityAugmentor produce() {
Expand Down Expand Up @@ -115,7 +129,7 @@ public SecurityIdentity augment(final SecurityIdentity identity, final Annotatio

private String generateToken(JwtClaims claims) {
try {
return Jwt.claims(claims.getClaimsMap()).sign(KeyUtils.generateKeyPair(2048).getPrivate());
return Jwt.claims(claims.getClaimsMap()).sign(privateKey);
} catch (Exception ex) {
throw new RuntimeException(ex);
}
Expand Down

0 comments on commit c1cbb7b

Please sign in to comment.