Search in sources :

Example 1 with JwsDetachedSignature

use of org.apache.cxf.rs.security.jose.jws.JwsDetachedSignature in project cxf by apache.

the class AbstractJwsMultipartSignatureFilter method getAttachmentParts.

protected List<Object> getAttachmentParts(Object rootEntity) {
    List<Object> parts = null;
    if (rootEntity instanceof MultipartBody) {
        parts = CastUtils.cast(((MultipartBody) rootEntity).getAllAttachments());
    } else {
        parts = new ArrayList<Object>();
        if (rootEntity instanceof List) {
            List<Object> entityList = CastUtils.cast((List<?>) rootEntity);
            parts.addAll(entityList);
        } else {
            parts.add(rootEntity);
        }
    }
    JwsHeaders headers = new JwsHeaders();
    headers.setPayloadEncodingStatus(false);
    JwsSignatureProvider theSigProvider = sigProvider != null ? sigProvider : JwsUtils.loadSignatureProvider(headers, true);
    JwsSignature jwsSignature = theSigProvider.createJwsSignature(headers);
    String base64UrlEncodedHeaders = Base64UrlUtility.encode(writer.toJson(headers));
    byte[] headerBytesWithDot = StringUtils.toBytesASCII(base64UrlEncodedHeaders + ".");
    jwsSignature.update(headerBytesWithDot, 0, headerBytesWithDot.length);
    AttachmentUtils.addMultipartOutFilter(new JwsMultipartSignatureOutFilter(jwsSignature));
    JwsDetachedSignature jws = new JwsDetachedSignature(headers, base64UrlEncodedHeaders, jwsSignature, useJwsJsonSignatureFormat);
    Attachment jwsPart = new Attachment("signature", JoseConstants.MEDIA_TYPE_JOSE, jws);
    parts.add(jwsPart);
    return parts;
}
Also used : JwsSignature(org.apache.cxf.rs.security.jose.jws.JwsSignature) Attachment(org.apache.cxf.jaxrs.ext.multipart.Attachment) JwsHeaders(org.apache.cxf.rs.security.jose.jws.JwsHeaders) MultipartBody(org.apache.cxf.jaxrs.ext.multipart.MultipartBody) JwsDetachedSignature(org.apache.cxf.rs.security.jose.jws.JwsDetachedSignature) ArrayList(java.util.ArrayList) List(java.util.List) JwsSignatureProvider(org.apache.cxf.rs.security.jose.jws.JwsSignatureProvider)

Aggregations

ArrayList (java.util.ArrayList)1 List (java.util.List)1 Attachment (org.apache.cxf.jaxrs.ext.multipart.Attachment)1 MultipartBody (org.apache.cxf.jaxrs.ext.multipart.MultipartBody)1 JwsDetachedSignature (org.apache.cxf.rs.security.jose.jws.JwsDetachedSignature)1 JwsHeaders (org.apache.cxf.rs.security.jose.jws.JwsHeaders)1 JwsSignature (org.apache.cxf.rs.security.jose.jws.JwsSignature)1 JwsSignatureProvider (org.apache.cxf.rs.security.jose.jws.JwsSignatureProvider)1