1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.common.aws.status;
17
18 import static com.google.common.collect.Lists.newArrayList;
19 import static org.kuali.common.util.encrypt.Encryption.getDefaultEncryptor;
20
21 import java.util.List;
22
23 import org.kuali.common.aws.EncryptedAwsCredentials;
24 import org.kuali.common.aws.EncryptedKeyPair;
25 import org.kuali.common.core.ssh.KeyPair;
26 import org.kuali.common.util.encrypt.Encryptor;
27
28 import com.amazonaws.auth.AWSCredentials;
29 import com.amazonaws.auth.BasicAWSCredentials;
30
31 public class Auth {
32
33 public static KeyPair getKeyPair(EncryptedKeyPair encrypted) {
34 Encryptor encryptor = getDefaultEncryptor();
35 KeyPair keyPair = encrypted.getKeyPair();
36 String publicKey = encryptor.decrypt(keyPair.getPublicKey());
37 String privateKey = encryptor.decrypt(keyPair.getPrivateKey());
38 return KeyPair.builder(keyPair.getName()).withPublicKey(publicKey).withPrivateKey(privateKey).build();
39 }
40
41 public static AWSCredentials getCredentials(EncryptedAwsCredentials encrypted) {
42 Encryptor encryptor = getDefaultEncryptor();
43 String accessKey = encryptor.decrypt(encrypted.getAWSAccessKeyId());
44 String secretKey = encryptor.decrypt(encrypted.getAWSSecretKey());
45 return new BasicAWSCredentials(accessKey, secretKey);
46 }
47
48 public static List<AWSCredentials> getCredentials() {
49 List<AWSCredentials> list = newArrayList();
50 for (EncryptedAwsCredentials credentials : EncryptedAwsCredentials.values()) {
51 AWSCredentials decrypted = getCredentials(credentials);
52 list.add(decrypted);
53 }
54 return list;
55
56 }
57
58 }