Search in sources :

Example 1 with KeyProvider

use of org.apache.cxf.rs.security.httpsignature.provider.KeyProvider in project cxf by apache.

the class AbstractSignatureOutFilter method createMessageSigner.

private MessageSigner createMessageSigner() {
    Properties props = KeyManagementUtils.loadSignatureOutProperties();
    if (props == null) {
        throw new SignatureException("Signature properties are not configured correctly");
    }
    Message m = PhaseInterceptorChain.getCurrentMessage();
    KeyProvider keyProvider = keyId -> KeyManagementUtils.loadPrivateKey(m, props);
    String signatureAlgorithm = (String) m.getContextualProperty(HTTPSignatureConstants.RSSEC_SIGNATURE_ALGORITHM);
    if (signatureAlgorithm == null) {
        signatureAlgorithm = DefaultSignatureConstants.SIGNING_ALGORITHM;
    }
    String keyId = (String) m.getContextualProperty(HTTPSignatureConstants.RSSEC_HTTP_SIGNATURE_KEY_ID);
    if (keyId == null) {
        keyId = props.getProperty(HTTPSignatureConstants.RSSEC_HTTP_SIGNATURE_KEY_ID);
        if (keyId == null) {
            throw new SignatureException("The signature key id is a required configuration property");
        }
    }
    List<String> signedHeaders = CastUtils.cast((List<?>) m.getContextualProperty(HTTPSignatureConstants.RSSEC_HTTP_SIGNATURE_OUT_HEADERS));
    if (signedHeaders == null) {
        signedHeaders = Collections.emptyList();
    }
    return new MessageSigner(signatureAlgorithm, keyProvider, keyId, signedHeaders);
}
Also used : KeyProvider(org.apache.cxf.rs.security.httpsignature.provider.KeyProvider) Properties(java.util.Properties) CastUtils(org.apache.cxf.helpers.CastUtils) Message(org.apache.cxf.message.Message) IOException(java.io.IOException) HashMap(java.util.HashMap) KeyProvider(org.apache.cxf.rs.security.httpsignature.provider.KeyProvider) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) MultivaluedMap(javax.ws.rs.core.MultivaluedMap) MessageSigner(org.apache.cxf.rs.security.httpsignature.MessageSigner) DefaultSignatureConstants(org.apache.cxf.rs.security.httpsignature.utils.DefaultSignatureConstants) List(java.util.List) LogUtils(org.apache.cxf.common.logging.LogUtils) Map(java.util.Map) PhaseInterceptorChain(org.apache.cxf.phase.PhaseInterceptorChain) HTTPSignatureConstants(org.apache.cxf.rs.security.httpsignature.HTTPSignatureConstants) KeyManagementUtils(org.apache.cxf.rs.security.httpsignature.utils.KeyManagementUtils) Collections(java.util.Collections) SignatureException(org.apache.cxf.rs.security.httpsignature.exception.SignatureException) MessageSigner(org.apache.cxf.rs.security.httpsignature.MessageSigner) Message(org.apache.cxf.message.Message) SignatureException(org.apache.cxf.rs.security.httpsignature.exception.SignatureException) Properties(java.util.Properties)

Aggregations

IOException (java.io.IOException)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Properties (java.util.Properties)1 Logger (java.util.logging.Logger)1 Collectors (java.util.stream.Collectors)1 MultivaluedMap (javax.ws.rs.core.MultivaluedMap)1 LogUtils (org.apache.cxf.common.logging.LogUtils)1 CastUtils (org.apache.cxf.helpers.CastUtils)1 Message (org.apache.cxf.message.Message)1 PhaseInterceptorChain (org.apache.cxf.phase.PhaseInterceptorChain)1 HTTPSignatureConstants (org.apache.cxf.rs.security.httpsignature.HTTPSignatureConstants)1 MessageSigner (org.apache.cxf.rs.security.httpsignature.MessageSigner)1 SignatureException (org.apache.cxf.rs.security.httpsignature.exception.SignatureException)1 KeyProvider (org.apache.cxf.rs.security.httpsignature.provider.KeyProvider)1 DefaultSignatureConstants (org.apache.cxf.rs.security.httpsignature.utils.DefaultSignatureConstants)1 KeyManagementUtils (org.apache.cxf.rs.security.httpsignature.utils.KeyManagementUtils)1