Search in sources :

Example 11 with JwtException

use of io.helidon.security.jwt.JwtException in project helidon by oracle.

the class JwtAuthProvider method impersonate.

private OutboundSecurityResponse impersonate(JwtOutboundTarget ot, String username) {
    Map<String, List<String>> headers = new HashMap<>();
    Jwk jwk = signKeys.forKeyId(ot.jwkKid).orElseThrow(() -> new JwtException("Signing JWK with kid: " + ot.jwkKid + " is not defined."));
    Jwt.Builder builder = Jwt.builder();
    builder.addPayloadClaim("name", username);
    builder.subject(username).preferredUsername(username).issuer(issuer).algorithm(jwk.algorithm());
    ot.update(builder);
    Jwt jwt = builder.build();
    SignedJwt signed = SignedJwt.sign(jwt, jwk);
    ot.outboundHandler.header(headers, signed.tokenContent());
    return OutboundSecurityResponse.withHeaders(headers);
}
Also used : IdentityHashMap(java.util.IdentityHashMap) HashMap(java.util.HashMap) EncryptedJwt(io.helidon.security.jwt.EncryptedJwt) SignedJwt(io.helidon.security.jwt.SignedJwt) Jwt(io.helidon.security.jwt.Jwt) List(java.util.List) LinkedList(java.util.LinkedList) JwtException(io.helidon.security.jwt.JwtException) SignedJwt(io.helidon.security.jwt.SignedJwt) Jwk(io.helidon.security.jwt.jwk.Jwk)

Aggregations

JwtException (io.helidon.security.jwt.JwtException)11 Principal (io.helidon.security.Principal)4 Jwt (io.helidon.security.jwt.Jwt)4 SignedJwt (io.helidon.security.jwt.SignedJwt)4 Jwk (io.helidon.security.jwt.jwk.Jwk)4 HashMap (java.util.HashMap)4 IdentityHashMap (java.util.IdentityHashMap)4 List (java.util.List)4 EncryptedJwt (io.helidon.security.jwt.EncryptedJwt)2 JwtUtil.asString (io.helidon.security.jwt.JwtUtil.asString)2 Signature (java.security.Signature)2 CertificateException (java.security.cert.CertificateException)2 LinkedList (java.util.LinkedList)2 JwtUtil.asBigInteger (io.helidon.security.jwt.JwtUtil.asBigInteger)1 JwtUtil.getBigInteger (io.helidon.security.jwt.JwtUtil.getBigInteger)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 BigInteger (java.math.BigInteger)1 InvalidKeyException (java.security.InvalidKeyException)1 PrivateKey (java.security.PrivateKey)1