001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.camel.reifier.dataformat; 018 019import org.apache.camel.CamelContext; 020import org.apache.camel.model.DataFormatDefinition; 021import org.apache.camel.model.dataformat.XMLSecurityDataFormat; 022import org.apache.camel.spi.DataFormat; 023 024public class XMLSecurityDataFormatReifier extends DataFormatReifier<XMLSecurityDataFormat> { 025 026 private static final String TRIPLEDES = "http://www.w3.org/2001/04/xmlenc#tripledes-cbc"; 027 028 public XMLSecurityDataFormatReifier(DataFormatDefinition definition) { 029 super((XMLSecurityDataFormat)definition); 030 } 031 032 @Override 033 protected void configureDataFormat(DataFormat dataFormat, CamelContext camelContext) { 034 if (definition.getSecureTag() != null) { 035 setProperty(camelContext, dataFormat, "secureTag", definition.getSecureTag()); 036 } else { 037 setProperty(camelContext, dataFormat, "secureTag", ""); 038 } 039 040 boolean isSecureTagContents = definition.getSecureTagContents() != null && definition.getSecureTagContents(); 041 setProperty(camelContext, dataFormat, "secureTagContents", isSecureTagContents); 042 043 if (definition.getPassPhrase() != null || definition.getPassPhraseByte() != null) { 044 if (definition.getPassPhraseByte() != null) { 045 setProperty(camelContext, dataFormat, "passPhrase", definition.getPassPhraseByte()); 046 } else { 047 setProperty(camelContext, dataFormat, "passPhrase", definition.getPassPhrase().getBytes()); 048 } 049 } else { 050 setProperty(camelContext, dataFormat, "passPhrase", "Just another 24 Byte key".getBytes()); 051 } 052 if (definition.getXmlCipherAlgorithm() != null) { 053 setProperty(camelContext, dataFormat, "xmlCipherAlgorithm", definition.getXmlCipherAlgorithm()); 054 } else { 055 setProperty(camelContext, dataFormat, "xmlCipherAlgorithm", TRIPLEDES); 056 } 057 if (definition.getKeyCipherAlgorithm() != null) { 058 setProperty(camelContext, dataFormat, "keyCipherAlgorithm", definition.getKeyCipherAlgorithm()); 059 } 060 if (definition.getRecipientKeyAlias() != null) { 061 setProperty(camelContext, dataFormat, "recipientKeyAlias", definition.getRecipientKeyAlias()); 062 } 063 if (definition.getKeyOrTrustStoreParametersRef() != null) { 064 setProperty(camelContext, dataFormat, "keyOrTrustStoreParametersRef", definition.getKeyOrTrustStoreParametersRef()); 065 } 066 if (definition.getKeyOrTrustStoreParameters() != null) { 067 setProperty(camelContext, dataFormat, "keyOrTrustStoreParameters", definition.getKeyOrTrustStoreParameters()); 068 } 069 if (definition.getNamespaces() != null) { 070 setProperty(camelContext, dataFormat, "namespaces", definition.getNamespaces()); 071 } 072 if (definition.getKeyPassword() != null) { 073 setProperty(camelContext, dataFormat, "keyPassword", definition.getKeyPassword()); 074 } 075 if (definition.getDigestAlgorithm() != null) { 076 setProperty(camelContext, dataFormat, "digestAlgorithm", definition.getDigestAlgorithm()); 077 } 078 if (definition.getMgfAlgorithm() != null) { 079 setProperty(camelContext, dataFormat, "mgfAlgorithm", definition.getMgfAlgorithm()); 080 } 081 // should be true by default 082 boolean isAddKeyValueForEncryptedKey = definition.getAddKeyValueForEncryptedKey() == null || definition.getAddKeyValueForEncryptedKey(); 083 setProperty(camelContext, dataFormat, "addKeyValueForEncryptedKey", isAddKeyValueForEncryptedKey); 084 } 085 086}