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