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