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.file.remote;
018    
019    import java.net.URI;
020    import java.util.Map;
021    
022    import org.apache.camel.CamelContext;
023    import org.apache.camel.component.file.GenericFileEndpoint;
024    import org.apache.camel.util.IntrospectionSupport;
025    import org.apache.commons.net.ftp.FTPFile;
026    
027    /**
028     * FTP Secure (FTP over SSL/TLS) Component.
029     * <p/>
030     * If desired, the JVM property <tt>-Djavax.net.debug=all</tt> can be used to see wire-level SSL details.
031     * 
032     * @version $Revision: 951412 $
033     */
034    public class FtpsComponent extends FtpComponent {
035    
036        public FtpsComponent() {
037        }
038    
039        public FtpsComponent(CamelContext context) {
040            super(context);
041        }
042    
043        @Override
044        protected GenericFileEndpoint<FTPFile> buildFileEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
045            String baseUri = getBaseUri(uri);
046    
047            // lets make sure we create a new configuration as each endpoint can customize its own version
048            // must pass on baseUri to the configuration (see above)
049            FtpsConfiguration config = new FtpsConfiguration(new URI(baseUri));
050    
051            FtpsEndpoint endpoint = new FtpsEndpoint(uri, this, config);
052            extractAndSetFtpClientKeyStoreParameters(parameters, endpoint);
053            extractAndSetFtpClientTrustStoreParameters(parameters, endpoint);
054            extractAndSetFtpClientConfigParameters(parameters, endpoint);
055            extractAndSetFtpClientParameters(parameters, endpoint);
056            
057            return endpoint;
058        }
059    
060        /**
061         * Extract additional ftp client key store options from the parameters map (parameters starting with 
062         * 'ftpClient.keyStore.'). To remember these parameters, we set them in the endpoint and we can use 
063         * them when creating a client.
064         */
065        protected void extractAndSetFtpClientKeyStoreParameters(Map<String, Object> parameters, FtpsEndpoint endpoint) {
066            if (IntrospectionSupport.hasProperties(parameters, "ftpClient.keyStore.")) {
067                Map<String, Object> param = IntrospectionSupport.extractProperties(parameters, "ftpClient.keyStore.");
068                endpoint.setFtpClientKeyStoreParameters(param);
069            }
070        }
071    
072        /**
073         * Extract additional ftp client trust store options from the parameters map (parameters starting with 
074         * 'ftpClient.trustStore.'). To remember these parameters, we set them in the endpoint and we can use 
075         * them when creating a client.
076         */
077        protected void extractAndSetFtpClientTrustStoreParameters(Map<String, Object> parameters, FtpsEndpoint endpoint) {
078            if (IntrospectionSupport.hasProperties(parameters, "ftpClient.trustStore.")) {
079                Map<String, Object> param = IntrospectionSupport.extractProperties(parameters, "ftpClient.trustStore.");
080                endpoint.setFtpClientTrustStoreParameters(param);
081            }
082        }
083    
084    }