Search in sources :

Example 1 with JweJwtCompactProducer

use of org.apache.cxf.rs.security.jose.jwe.JweJwtCompactProducer in project cxf by apache.

the class JoseJwtProducer method processJwt.

public String processJwt(JwtToken jwt, JweEncryptionProvider theEncProvider, JwsSignatureProvider theSigProvider) {
    super.checkProcessRequirements();
    String data = null;
    if (isJweRequired() && theEncProvider == null) {
        theEncProvider = getInitializedEncryptionProvider(jwt.getJweHeaders());
        if (theEncProvider == null) {
            throw new JwtException("Unable to encrypt JWT");
        }
    }
    if (isJwsRequired()) {
        JwsJwtCompactProducer jws = new JwsJwtCompactProducer(jwt);
        if (jws.isPlainText()) {
            data = jws.getSignedEncodedJws();
        } else {
            if (theSigProvider == null) {
                theSigProvider = getInitializedSignatureProvider(jws.getJwsHeaders());
            }
            if (theSigProvider == null) {
                throw new JwtException("Unable to sign JWT");
            }
            data = jws.signWith(theSigProvider);
        }
        if (theEncProvider != null) {
            data = theEncProvider.encrypt(StringUtils.toBytesUTF8(data), jwt.getJweHeaders());
        }
    } else {
        JweJwtCompactProducer jwe = new JweJwtCompactProducer(jwt.getJweHeaders(), jwt.getClaims());
        data = jwe.encryptWith(theEncProvider);
    }
    return data;
}
Also used : JwsJwtCompactProducer(org.apache.cxf.rs.security.jose.jws.JwsJwtCompactProducer) JweJwtCompactProducer(org.apache.cxf.rs.security.jose.jwe.JweJwtCompactProducer)

Aggregations

JweJwtCompactProducer (org.apache.cxf.rs.security.jose.jwe.JweJwtCompactProducer)1 JwsJwtCompactProducer (org.apache.cxf.rs.security.jose.jws.JwsJwtCompactProducer)1