1 package com.meltmedia.jgroups.aws;
2
3 import com.amazonaws.auth.AWSCredentialsProvider;
4 import org.jgroups.logging.Log;
5 import org.jgroups.logging.LogFactory;
6 import org.jgroups.util.Util;
7
8 public class CredentialsProviderFactory {
9 private final Log log;
10
11 public CredentialsProviderFactory() {
12 this(LogFactory.getLog(AWS_PING.class));
13 }
14
15 public CredentialsProviderFactory(final Log log) {
16 this.log = log;
17 }
18
19
20
21
22
23
24
25
26
27 public AWSCredentialsProvider createCredentialsProvider(final String credentialProviderClass) throws Exception {
28 try {
29 final Class<?> credsProviderClazz = Util.loadClass(credentialProviderClass, getClass());
30 return (AWSCredentialsProvider) credsProviderClazz.newInstance();
31 } catch (ClassNotFoundException e) {
32 throw new Exception("unable to load credentials provider class " + credentialProviderClass);
33 } catch (InstantiationException e) {
34 log.error("an instance of " + credentialProviderClass + " could not be created. Please check that it implements" +
35 " interface AWSCredentialsProvider and that is has a public empty constructor !");
36 throw e;
37 }
38 }
39 }