Search in sources :

Example 6 with JWEException

use of org.keycloak.jose.jwe.JWEException in project keycloak by keycloak.

the class CIBAAuthenticationRequest method serialize.

/**
 * Serializes this instance to a JWE.
 *
 * @param session the session
 * @return the JWE
 */
public String serialize(KeycloakSession session) {
    try {
        SignatureProvider signatureProvider = session.getProvider(SignatureProvider.class, Algorithm.HS256);
        SignatureSignerContext signer = signatureProvider.signer();
        String encodedJwt = new JWSBuilder().type("JWT").jsonContent(this).sign(signer);
        SecretKey aesKey = session.keys().getActiveKey(session.getContext().getRealm(), KeyUse.ENC, Algorithm.AES).getSecretKey();
        SecretKey hmacKey = session.keys().getActiveKey(session.getContext().getRealm(), KeyUse.SIG, Algorithm.HS256).getSecretKey();
        return TokenUtil.jweDirectEncode(aesKey, hmacKey, encodedJwt.getBytes("UTF-8"));
    } catch (JWEException | UnsupportedEncodingException e) {
        throw new RuntimeException("Error encoding auth_req_id.", e);
    }
}
Also used : SignatureProvider(org.keycloak.crypto.SignatureProvider) SecretKey(javax.crypto.SecretKey) SignatureSignerContext(org.keycloak.crypto.SignatureSignerContext) JWEException(org.keycloak.jose.jwe.JWEException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) JWSBuilder(org.keycloak.jose.jws.JWSBuilder)

Aggregations

UnsupportedEncodingException (java.io.UnsupportedEncodingException)6 JWEException (org.keycloak.jose.jwe.JWEException)6 PrivateKey (java.security.PrivateKey)4 JWEAlgorithmProvider (org.keycloak.jose.jwe.alg.JWEAlgorithmProvider)4 JWEEncryptionProvider (org.keycloak.jose.jwe.enc.JWEEncryptionProvider)4 Key (java.security.Key)2 SecretKey (javax.crypto.SecretKey)2 ClientResource (org.keycloak.admin.client.resource.ClientResource)2 CekManagementProvider (org.keycloak.crypto.CekManagementProvider)2 ContentEncryptionProvider (org.keycloak.crypto.ContentEncryptionProvider)2 KeyWrapper (org.keycloak.crypto.KeyWrapper)2 SignatureProvider (org.keycloak.crypto.SignatureProvider)2 SignatureSignerContext (org.keycloak.crypto.SignatureSignerContext)2 JWEHeader (org.keycloak.jose.jwe.JWEHeader)2 ClientModel (org.keycloak.models.ClientModel)2 ClientRepresentation (org.keycloak.representations.idm.ClientRepresentation)2 TestOIDCEndpointsApplicationResource (org.keycloak.testsuite.client.resources.TestOIDCEndpointsApplicationResource)2 OAuthClient (org.keycloak.testsuite.util.OAuthClient)2 IOException (java.io.IOException)1 Comparator (java.util.Comparator)1