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.component.crypto;
018    
019    import java.security.KeyStore;
020    import java.security.PrivateKey;
021    import java.security.PublicKey;
022    import java.security.SecureRandom;
023    import java.security.cert.Certificate;
024    
025    import org.apache.camel.Consumer;
026    import org.apache.camel.Processor;
027    import org.apache.camel.Producer;
028    import org.apache.camel.component.crypto.processor.SigningProcessor;
029    import org.apache.camel.component.crypto.processor.VerifyingProcessor;
030    import org.apache.camel.impl.DefaultEndpoint;
031    
032    /**
033     * <code>DigitalSignatureEndpoint</code>
034     */
035    public class DigitalSignatureEndpoint extends DefaultEndpoint {
036        private DigitalSignatureConfiguration configuration;
037    
038        public DigitalSignatureEndpoint(String uri, DigitalSignatureComponent component, DigitalSignatureConfiguration configuration) {
039            super(uri, component);
040            this.configuration = configuration;
041        }
042    
043        public Producer createProducer() throws Exception {
044            return "sign".equals(configuration.getCryptoOperation())
045                ? new DigitalSignatureProducer(this, new SigningProcessor(configuration)) : new DigitalSignatureProducer(this, new VerifyingProcessor(configuration));
046        }
047    
048        public Consumer createConsumer(Processor processor) throws Exception {
049            throw new UnsupportedOperationException("Digital Signatures endpoints are not meant to be consumed from. They are meant be used as an intermediate endpoints");
050        }
051    
052        public boolean isSingleton() {
053            return true;
054        }
055    
056        public Object getManagedObject(DigitalSignatureEndpoint endpoint) {
057            return this;
058        }
059    
060        public void setConfiguration(DigitalSignatureConfiguration configuration) {
061            this.configuration = configuration;
062        }
063    
064        public DigitalSignatureConfiguration getConfiguration() {
065            return configuration;
066        }
067    
068        public PublicKey getPublicKey() throws Exception {
069            return getConfiguration().getPublicKey();
070        }
071    
072        public void setPublicKey(PublicKey publicKey) {
073            getConfiguration().setPublicKey(publicKey);
074        }
075    
076        public void setPublicKey(String publicKeyName) {
077            getConfiguration().setPublicKey(publicKeyName);
078        }
079    
080        public Certificate getCertificate() throws Exception {
081            return getConfiguration().getCertificate();
082        }
083    
084        public PrivateKey getPrivateKey() throws Exception {
085            return getConfiguration().getPrivateKey();
086        }
087    
088        public void setPrivateKey(PrivateKey privateKey) {
089            getConfiguration().setPrivateKey(privateKey);
090        }
091    
092        public KeyStore getKeystore() {
093            return getConfiguration().getKeystore();
094        }
095    
096        public void setKeystore(KeyStore keystore) {
097            getConfiguration().setKeystore(keystore);
098        }
099    
100        public char[] getPassword() {
101            return getConfiguration().getPassword();
102        }
103    
104        public void setKeyPassword(char[] keyPassword) {
105            getConfiguration().setPassword(keyPassword);
106        }
107    
108        public SecureRandom getSecureRandom() {
109            return getConfiguration().getSecureRandom();
110        }
111    
112        public void setSecureRandom(SecureRandom secureRandom) {
113            getConfiguration().setSecureRandom(secureRandom);
114        }
115    
116        public String getAlgorithm() {
117            return getConfiguration().getAlgorithm();
118        }
119    
120        public void setAlgorithm(String algorithm) {
121            getConfiguration().setAlgorithm(algorithm);
122        }
123    
124        public Integer getBuffersize() {
125            return getConfiguration().getBufferSize();
126        }
127    
128        public void setBuffersize(Integer buffersize) {
129            getConfiguration().setBufferSize(buffersize);
130        }
131    
132        public String getProvider() {
133            return getConfiguration().getProvider();
134        }
135    
136        public void setProvider(String provider) {
137            getConfiguration().setProvider(provider);
138        }
139    
140        public String getSignatureHeader() {
141            return getConfiguration().getSignatureHeader();
142        }
143    
144        public void setSignatureHeader(String signatureHeaderName) {
145            getConfiguration().setSignatureHeader(signatureHeaderName);
146        }
147    
148        public String getAlias() {
149            return getConfiguration().getAlias();
150        }
151    
152        public void setAlias(String alias) {
153            getConfiguration().setAlias(alias);
154        }
155    
156        public boolean getClearHeaders() {
157            return getConfiguration().getClearHeaders();
158        }
159    
160        public void setClearHeaders(boolean clearHeaders) {
161            getConfiguration().setClearHeaders(clearHeaders);
162        }
163    }