View Javadoc

1   package org.kuali.common.deploy.channel.spring;
2   
3   import java.util.List;
4   
5   import org.kuali.common.deploy.env.spring.DefaultDeployEnvironmentConfig;
6   import org.kuali.common.deploy.env.spring.DeployEnvironmentConfig;
7   import org.kuali.common.util.secure.channel.DefaultSecureChannel;
8   import org.kuali.common.util.secure.channel.SecureChannel;
9   import org.kuali.common.util.secure.channel.spring.SecureChannelConfig;
10  import org.kuali.common.util.spring.SpringUtils;
11  import org.kuali.common.util.spring.env.EnvironmentService;
12  import org.kuali.common.util.spring.service.SpringServiceConfig;
13  import org.springframework.beans.factory.annotation.Autowired;
14  import org.springframework.context.annotation.Bean;
15  import org.springframework.context.annotation.Configuration;
16  import org.springframework.context.annotation.Import;
17  import org.springframework.util.Assert;
18  
19  @Configuration
20  @Import({ DefaultDeployEnvironmentConfig.class, SpringServiceConfig.class })
21  public class DefaultSecureChannelConfig implements SecureChannelConfig {
22  
23  	private static final String USERNAME_KEY = "channel.username";
24  	private static final String HOSTNAME_KEY = "channel.hostname";
25  
26  	private static final String ROOT = "root";
27  
28  	@Autowired
29  	DeployEnvironmentConfig envConfig;
30  
31  	@Autowired
32  	EnvironmentService env;
33  
34  	@Override
35  	@Bean
36  	public SecureChannel secureChannel() {
37  
38  		// User to connect as
39  		String username = env.getString(USERNAME_KEY, ROOT);
40  
41  		// Hostname to connect to
42  		String hostname = env.getString(HOSTNAME_KEY, envConfig.deployEnvironment().getDns().getHostname());
43  
44  		// Turn off strict host key checking by default
45  		boolean strictHostKeyChecking = env.getBoolean("channel.strictHostKeyChecking", false);
46  
47  		// Turn off use of ~/.ssh/config
48  		boolean useConfigFile = env.getBoolean("channel.useConfigFile", false);
49  
50  		// Don't check file system locations for private keys
51  		boolean includeDefaultPrivateKeyLocations = env.getBoolean("channel.includeDefaultPrivateKeyLocations", false);
52  
53  		// Require at least one private key string
54  		List<String> privateKeyStrings = SpringUtils.getNoneSensitiveListFromCSV(env, "channel.privateKeyStrings");
55  
56  		Assert.isTrue(privateKeyStrings.size() > 0, "no private key strings");
57  
58  		// Setup the channel
59  		return new DefaultSecureChannel.Builder(username, hostname).strictHostKeyChecking(strictHostKeyChecking).useConfigFile(useConfigFile)
60  				.includeDefaultPrivateKeyLocations(includeDefaultPrivateKeyLocations).privateKeyStrings(privateKeyStrings).build();
61  
62  	}
63  
64  }