View Javadoc
1   /**
2    * Copyright 2004-2014 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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  }