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     */
017    package org.apache.camel.model.dataformat;
018    
019    import javax.xml.bind.annotation.XmlAccessType;
020    import javax.xml.bind.annotation.XmlAccessorType;
021    import javax.xml.bind.annotation.XmlAttribute;
022    import javax.xml.bind.annotation.XmlRootElement;
023    
024    import org.apache.camel.model.DataFormatDefinition;
025    import org.apache.camel.spi.DataFormat;
026    
027    /**
028     * Represents as XML Security Encrypter/Decrypter {@link DataFormat}
029     */
030    @XmlRootElement(name = "secureXML")
031    @XmlAccessorType(XmlAccessType.FIELD)
032    public class XMLSecurityDataFormat extends DataFormatDefinition {
033    
034        private static final transient String TRIPLEDES = "http://www.w3.org/2001/04/xmlenc#tripledes-cbc";
035    
036        @XmlAttribute(required = false)
037        private String xmlCipherAlgorithm;
038        @XmlAttribute(required = false)
039        private String passPhrase;
040        @XmlAttribute(required = false)
041        private String secureTag;
042        @XmlAttribute(required = false)
043        private boolean secureTagContents;
044    
045        public XMLSecurityDataFormat() {
046            super("secureXML");
047        }
048    
049        public XMLSecurityDataFormat(String secureTag, boolean secureTagContents) {
050            this();
051            this.setSecureTag(secureTag);
052            this.setSecureTagContents(secureTagContents);
053        }
054    
055        public XMLSecurityDataFormat(String secureTag, boolean secureTagContents, String passPhrase) {
056            this();
057            this.setSecureTag(secureTag);
058            this.setSecureTagContents(secureTagContents);
059            this.setPassPhrase(passPhrase);
060        }
061    
062        public XMLSecurityDataFormat(String secureTag, boolean secureTagContents, String passPhrase,
063                                     String xmlCipherAlgorithm) {
064            this();
065            this.setSecureTag(secureTag);
066            this.setSecureTagContents(secureTagContents);
067            this.setPassPhrase(passPhrase);
068            this.setXmlCipherAlgorithm(xmlCipherAlgorithm);
069        }
070    
071        @Override
072        protected void configureDataFormat(DataFormat dataFormat) {
073            if (getSecureTag() != null) {
074                setProperty(dataFormat, "secureTag", getSecureTag());
075            } else {
076                setProperty(dataFormat, "secureTag", "");
077            }
078    
079            setProperty(dataFormat, "secureTagContents", isSecureTagContents());
080    
081            if (passPhrase != null) {
082                setProperty(dataFormat, "passPhrase", getPassPhrase());
083            } else {
084                setProperty(dataFormat, "passPhrase", "Just another 24 Byte key".getBytes());
085            }
086            if (getXmlCipherAlgorithm() != null) {
087                setProperty(dataFormat, "xmlCipherAlgorithm", getXmlCipherAlgorithm());
088            } else {
089                setProperty(dataFormat, "xmlCipherAlgorithm", TRIPLEDES);
090            }
091        }
092    
093    
094        public String getXmlCipherAlgorithm() {
095            return xmlCipherAlgorithm;
096        }
097    
098        public void setXmlCipherAlgorithm(String xmlCipherAlgorithm) {
099            this.xmlCipherAlgorithm = xmlCipherAlgorithm;
100        }
101    
102        public String getPassPhrase() {
103            return passPhrase;
104        }
105    
106        public void setPassPhrase(String passPhrase) {
107            this.passPhrase = passPhrase;
108        }
109    
110        public String getSecureTag() {
111            return secureTag;
112        }
113    
114        public void setSecureTag(String secureTag) {
115            this.secureTag = secureTag;
116        }
117    
118        public boolean isSecureTagContents() {
119            return secureTagContents;
120        }
121    
122        public void setSecureTagContents(boolean secureTagContents) {
123            this.secureTagContents = secureTagContents;
124        }
125    }