-
Notifications
You must be signed in to change notification settings - Fork 149
Expand file tree
/
Copy pathCredentialsProvider.java
More file actions
61 lines (53 loc) · 2.17 KB
/
CredentialsProvider.java
File metadata and controls
61 lines (53 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package com.amazon.sqs.javamessaging.jndi;
import com.amazonaws.auth.AWSStaticCredentialsProvider;
import com.amazonaws.auth.BasicAWSCredentials;
/**
* Simple implementation of {@link AWSStaticCredentialsProvider} with {@link BasicAWSCredentials}
* that use {@link javax.naming.Context#SECURITY_PRINCIPAL identity} as an AWS <b>access key</b>
* and {@link javax.naming.Context#SECURITY_CREDENTIALS credentials} as an AWS <b>secret access key</b>.
*
* @author krloss
* @since 1.1.0
*/
public class CredentialsProvider extends AWSStaticCredentialsProvider {
// Prevents incorrect startup.
private CredentialsProvider(String accessKey, String secretKey) {
super(new BasicAWSCredentials(accessKey.trim(),secretKey.trim()));
getCredentials(); // Initialize
}
private static boolean assertNotEmpty(String accessKey, String secretKey) {
try { if(accessKey.trim().isEmpty() || secretKey.trim().isEmpty()) return false; }
catch(NullPointerException npe) { return false; }
return true;
}
/**
* Public method that create a {@link CredentialsProvider} instance.
*
* @param securityPrincipal - {@link javax.naming.Context#SECURITY_PRINCIPAL identity}
* as an AWS <i>access key</i>
*
* @param securityCredentials - {@link javax.naming.Context#SECURITY_CREDENTIALS credentials}
* as an AWS <i>secret access key</i>
*
* @return {@link CredentialsProvider}
*/
public static CredentialsProvider create(String securityPrincipal, String securityCredentials) {
if(assertNotEmpty(securityPrincipal,securityCredentials))
return new CredentialsProvider(securityPrincipal,securityCredentials);
return null;
}
/**
* Public method that create a {@link CredentialsProvider} instance.
*
* @param securityPrincipal - {@link javax.naming.Context#SECURITY_PRINCIPAL identity}
* as an AWS <i>access key</i>
*
* @param securityCredentials - {@link javax.naming.Context#SECURITY_CREDENTIALS credentials}
* as an AWS <i>secret access key</i>
*
* @return {@link CredentialsProvider}
*/
public static CredentialsProvider create(Object securityPrincipal, Object securityCredentials) {
return create((String)securityPrincipal,(String)securityCredentials);
}
}