Example usage for com.amazonaws.auth AWSCredentials AWSCredentials

List of usage examples for com.amazonaws.auth AWSCredentials AWSCredentials

Introduction

In this page you can find the example usage for com.amazonaws.auth AWSCredentials AWSCredentials.

Prototype

AWSCredentials

Source Link

Usage

From source file:me.footlights.server.AmazonUploader.java

License:Apache License

@Inject
public AmazonUploader(Preferences preferences) {
    this.prefs = preferences;
    this.authSecret = getMandatoryPreference("cas.secret");

    final String keyId = getMandatoryPreference("amazon.keyId");
    final String secret = getMandatoryPreference("amazon.secretKey");

    if (keyId.isEmpty())
        throw new ConfigurationError("Amazon key ID not set");
    if (secret.isEmpty())
        throw new ConfigurationError("Amazon secret key not set");

    AWSCredentials cred = new AWSCredentials() {
        @Override//from w w w .ja v a  2  s  .  c  o m
        public String getAWSAccessKeyId() {
            return keyId;
        }

        @Override
        public String getAWSSecretKey() {
            return secret;
        }
    };

    s3 = new AmazonS3Client(cred);
}

From source file:org.apache.druid.common.aws.ConfigDrivenAwsCredentialsConfigProvider.java

License:Apache License

@Override
public AWSCredentials getCredentials() {
    final String key = config.getAccessKey().getPassword();
    final String secret = config.getSecretKey().getPassword();
    if (!Strings.isNullOrEmpty(key) && !Strings.isNullOrEmpty(secret)) {
        return new AWSCredentials() {
            @Override//from   w  w  w. ja  v a2 s .  com
            public String getAWSAccessKeyId() {
                return key;
            }

            @Override
            public String getAWSSecretKey() {
                return secret;
            }
        };
    }
    throw new AmazonClientException("Unable to load AWS credentials from druid AWSCredentialsConfig");
}

From source file:org.apache.pulsar.io.kinesis.KinesisSink.java

License:Apache License

private AWSCredentialsProvider defaultCredentialProvider(String accessKey, String secretKey) {
    return new AWSCredentialsProvider() {
        @Override//w  w  w.  j  a  v a2  s.c  om
        public AWSCredentials getCredentials() {
            return new AWSCredentials() {
                @Override
                public String getAWSAccessKeyId() {
                    return accessKey;
                }

                @Override
                public String getAWSSecretKey() {
                    return secretKey;
                }
            };
        }

        @Override
        public void refresh() {
            // no-op
        }
    };
}

From source file:org.apache.samza.system.kinesis.KinesisAWSCredentialsProvider.java

License:Apache License

public KinesisAWSCredentialsProvider(String accessKey, String secretKey) {
    if (StringUtils.isEmpty(accessKey) || StringUtils.isEmpty(secretKey)) {
        creds = new AWSCredentials() {
            @Override//from w  w  w . j  a va2  s .co m
            public String getAWSAccessKeyId() {
                return null;
            }

            @Override
            public String getAWSSecretKey() {
                return null;
            }
        };
        LOG.info("Could not load credentials from KinesisAWSCredentialsProvider");
    } else {
        creds = new BasicAWSCredentials(accessKey, secretKey);
        LOG.info("Loaded credentials from KinesisAWSCredentialsProvider");
    }
}

From source file:org.broadleafcommerce.vendor.amazon.s3.S3FileServiceProvider.java

License:Apache License

protected AWSCredentials getAWSCredentials(final S3Configuration s3configParam) {
    return new AWSCredentials() {

        private final S3Configuration s3ConfigVar = s3configParam;

        @Override//from   w w w.  ja va 2  s  .co  m
        public String getAWSSecretKey() {
            return s3ConfigVar.getAwsSecretKey();
        }

        @Override
        public String getAWSAccessKeyId() {
            return s3ConfigVar.getGetAWSAccessKeyId();
        }
    };
}

From source file:org.cm.podd.urban.report.helper.Util.java

License:Open Source License

/**
 * Gets an instance of a S3 client which is constructed using the given
 * Context./*from  www  . j  a va 2s . c o m*/
 *
 * @param context An Context instance.
 * @return A default S3 client.
 */
public static AmazonS3Client getS3Client(Context context) {
    if (sS3Client == null) {
        AWSCredentials cr = new AWSCredentials() {
            @Override
            public String getAWSAccessKeyId() {
                return BuildConfig.S3_ACCESS_KEY;
            }

            @Override
            public String getAWSSecretKey() {
                return BuildConfig.S3_SECRET_KEY;
            }
        };

        sS3Client = new AmazonS3Client(cr);
    }
    return sS3Client;
}

From source file:org.pentaho.amazon.s3.S3VfsFileChooserDialog.java

License:Apache License

private void createConnectionPanel() {

    // The Connection group
    Group connectionGroup = new Group(this, SWT.SHADOW_ETCHED_IN);
    connectionGroup.setText(BaseMessages.getString(PKG, "S3VfsFileChooserDialog.ConnectionGroup.Label")); //$NON-NLS-1$;
    GridLayout connectionGroupLayout = new GridLayout();
    connectionGroupLayout.marginWidth = 5;
    connectionGroupLayout.marginHeight = 5;
    connectionGroupLayout.verticalSpacing = 5;
    connectionGroupLayout.horizontalSpacing = 5;
    GridData gData = new GridData(SWT.FILL, SWT.FILL, true, false);
    connectionGroup.setLayoutData(gData);
    connectionGroup.setLayout(connectionGroupLayout);

    // The composite we need in the group
    Composite textFieldPanel = new Composite(connectionGroup, SWT.NONE);
    GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, false);
    textFieldPanel.setLayoutData(gridData);
    textFieldPanel.setLayout(new GridLayout(3, false));

    // URL label and text field
    wlAccessKey = new Label(textFieldPanel, SWT.RIGHT);
    wlAccessKey.setText(BaseMessages.getString(PKG, "S3VfsFileChooserDialog.AccessKey.Label")); //$NON-NLS-1$
    fdlAccessKey = new GridData();
    fdlAccessKey.widthHint = 75;/*from  w ww  .  j a va 2  s . co m*/
    wlAccessKey.setLayoutData(fdlAccessKey);
    wAccessKey = new TextVar(getVariableSpace(), textFieldPanel,
            SWT.PASSWORD | SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    fdAccessKey = new GridData();
    fdAccessKey.widthHint = 150;
    wAccessKey.setLayoutData(fdAccessKey);
    wAccessKey.setText(Encr.decryptPasswordOptionallyEncrypted(
            Props.getInstance().getCustomParameter("S3VfsFileChooserDialog.AccessKey", "")));

    wAccessKey.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent arg0) {
            handleConnectionButton();
        }
    });

    // // Place holder
    wPlaceHolderLabel = new Label(textFieldPanel, SWT.RIGHT);
    wPlaceHolderLabel.setText("");
    fdlPlaceHolderLabel = new GridData();
    fdlPlaceHolderLabel.widthHint = 75;
    wPlaceHolderLabel.setLayoutData(fdlPlaceHolderLabel);

    // UserID label and field
    wlSecretKey = new Label(textFieldPanel, SWT.RIGHT);
    wlSecretKey.setText(BaseMessages.getString(PKG, "S3VfsFileChooserDialog.SecretKey.Label"));
    fdlSecretKey = new GridData();
    fdlSecretKey.widthHint = 75;
    wlSecretKey.setLayoutData(fdlSecretKey);

    wSecretKey = new TextVar(getVariableSpace(), textFieldPanel,
            SWT.PASSWORD | SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    fdSecretKey = new GridData();
    fdSecretKey.widthHint = 300;
    wSecretKey.setLayoutData(fdSecretKey);
    wSecretKey.setText(Encr.decryptPasswordOptionallyEncrypted(
            Props.getInstance().getCustomParameter("S3VfsFileChooserDialog.SecretKey", "")));

    wSecretKey.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent arg0) {
            handleConnectionButton();
        }
    });

    // bucket
    // wlBucket = new Label(textFieldPanel, SWT.RIGHT);
    //    wlBucket.setText(BaseMessages.getString(PKG, "S3VfsFileChooserDialog.Bucket.Label")); //$NON-NLS-1$
    // fdlBucket = new GridData();
    // fdlBucket.widthHint = 75;
    // wlBucket.setLayoutData(fdlBucket);
    //
    // wBucket = new Text(textFieldPanel, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    // fdBucket = new GridData();
    // fdBucket.widthHint = 150;
    // wBucket.setLayoutData(fdBucket);
    // wBucket.addKeyListener(new KeyAdapter() {
    // public void keyPressed(KeyEvent e) {
    // handleConnectionButton();
    // }
    // });

    // Connection button
    wConnectionButton = new Button(textFieldPanel, SWT.CENTER);
    fdConnectionButton = new GridData();
    fdConnectionButton.widthHint = 75;
    wConnectionButton.setLayoutData(fdConnectionButton);

    wConnectionButton.setText(BaseMessages.getString(PKG, "S3VfsFileChooserDialog.ConnectionButton.Label"));
    wConnectionButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {

            try {
                // let's verify the accessKey/secretKey
                AmazonS3 s3Client = new AmazonS3Client(new AWSCredentials() {

                    public String getAWSSecretKey() {
                        return Encr.decryptPasswordOptionallyEncrypted(
                                environmentSubstitute(wSecretKey.getText()));
                    }

                    public String getAWSAccessKeyId() {
                        return Encr.decryptPasswordOptionallyEncrypted(
                                environmentSubstitute(wAccessKey.getText()));
                    }
                });
                s3Client.getS3AccountOwner();

                // s3 credentials valid, continue
                Props.getInstance().setCustomParameter("S3VfsFileChooserDialog.AccessKey",
                        Encr.encryptPasswordIfNotUsingVariables(wAccessKey.getText()));
                Props.getInstance().setCustomParameter("S3VfsFileChooserDialog.SecretKey",
                        Encr.encryptPasswordIfNotUsingVariables(wSecretKey.getText()));

                try {
                    FileObject root = rootFile;
                    root = resolveFile(buildS3FileSystemUrlString());
                    vfsFileChooserDialog.setSelectedFile(root);
                    vfsFileChooserDialog.setRootFile(root);
                    rootFile = root;
                } catch (FileSystemException e1) {
                    MessageBox box = new MessageBox(getShell());
                    box.setText(BaseMessages.getString(PKG, "S3VfsFileChooserDialog.error")); //$NON-NLS-1$
                    box.setMessage(e1.getMessage());
                    log.logError(e1.getMessage(), e1);
                    box.open();
                    return;
                }

            } catch (AmazonS3Exception ex) {
                // if anything went wrong, we have to show an error dialog
                MessageBox box = new MessageBox(getShell());
                box.setText(BaseMessages.getString(PKG, "S3VfsFileChooserDialog.error")); //$NON-NLS-1$
                box.setMessage(ex.getMessage());
                log.logError(ex.getMessage(), ex);
                box.open();
                return;
            }
        }
    });

    // set the tab order
    textFieldPanel.setTabList(new Control[] { wAccessKey, wSecretKey, wConnectionButton });
    // textFieldPanel.setTabList(new Control[] { wAccessKey, wBucket, wSecretKey, wPassword, wConnectionButton });
}

From source file:org.rifidi.app.amazonsample.DynamoDBApp.java

License:Open Source License

/**
 * //from ww  w.j  ava 2 s  . c om
 * 
 * @param group
 * @param name
 */
public DynamoDBApp(String group, String name) {
    super(group, name);

    AWSCredentials cred = new AWSCredentials() {

        @Override
        public String getAWSSecretKey() {
            return "PUT SECRET HERE";
        }

        @Override
        public String getAWSAccessKeyId() {
            return "PUT KEY HERE";
        }
    };

    dynamoDB = new AmazonDynamoDBClient(cred);
}

From source file:org.sfs.encryption.AwsKms.java

License:Apache License

public Observable<Void> start(VertxContext<Server> vertxContext, JsonObject config) {
    AwsKms _this = this;
    SfsVertx sfsVertx = vertxContext.vertx();
    Context context = sfsVertx.getOrCreateContext();
    return Defer.aVoid().filter(aVoid -> started.compareAndSet(false, true)).flatMap(aVoid -> {
        String keyStoreAwsKmsEndpoint = ConfigHelper.getFieldOrEnv(config, "keystore.aws.kms.endpoint");
        Preconditions.checkArgument(keyStoreAwsKmsEndpoint != null, "keystore.aws.kms.endpoint is required");

        _this.keyId = ConfigHelper.getFieldOrEnv(config, "keystore.aws.kms.key_id");
        Preconditions.checkArgument(_this.keyId != null, "keystore.aws.kms.key_id is required");

        _this.accessKeyId = ConfigHelper.getFieldOrEnv(config, "keystore.aws.kms.access_key_id");
        Preconditions.checkArgument(_this.accessKeyId != null, "keystore.aws.kms.access_key_id is required");

        _this.secretKey = ConfigHelper.getFieldOrEnv(config, "keystore.aws.kms.secret_key");
        Preconditions.checkArgument(_this.secretKey != null, "keystore.aws.kms.secret_key is required");

        return RxHelper.executeBlocking(context, sfsVertx.getBackgroundPool(), () -> {
            kms = new AWSKMSClient(new AWSCredentials() {
                @Override/*from w w  w . j  a va 2  s.c  om*/
                public String getAWSAccessKeyId() {
                    return _this.accessKeyId;
                }

                @Override
                public String getAWSSecretKey() {
                    return _this.secretKey;
                }
            });
            kms.setEndpoint(keyStoreAwsKmsEndpoint);
            return (Void) null;
        });
    }).singleOrDefault(null);
}

From source file:org.traccar.database.DataManager.java

License:Apache License

/**
 * Initialize database/*from   www  .j av a2 s .  com*/
 */
private void initDatabase(Properties properties) throws Exception {

    // Load driver
    String driver = properties.getProperty("database.driver");
    if (driver != null) {
        String driverFile = properties.getProperty("database.driverFile");

        if (driverFile != null) {
            URL url = new URL("jar:file:" + new File(driverFile).getAbsolutePath() + "!/");
            URLClassLoader cl = new URLClassLoader(new URL[] { url });
            Driver d = (Driver) Class.forName(driver, true, cl).newInstance();
            DriverManager.registerDriver(new DriverDelegate(d));
        } else {
            Class.forName(driver);
        }
    }

    // Initialize data source
    ComboPooledDataSource ds = new ComboPooledDataSource();
    ds.setDriverClass(properties.getProperty("database.driver"));
    ds.setJdbcUrl(properties.getProperty("database.url"));
    ds.setUser(properties.getProperty("database.user"));
    ds.setPassword(properties.getProperty("database.password"));
    ds.setIdleConnectionTestPeriod(600);
    ds.setTestConnectionOnCheckin(true);
    dataSource = ds;

    // Load statements from configuration
    String query;

    query = properties.getProperty("database.selectDevice");
    if (query != null) {
        queryGetDevices = new NamedParameterStatement(query, dataSource);
    }

    awsAccessKeyId = properties.getProperty("aws.accessKey");
    awsSecretAccessKey = properties.getProperty("aws.accessSecret");
    String awsSQSQueueName = properties.getProperty("aws.queueName");

    if (awsAccessKeyId != null && awsSecretAccessKey != null) {
        AWSCredentialsProvider credentialsProvider = new AWSCredentialsProvider() {
            @Override
            public AWSCredentials getCredentials() {
                return new AWSCredentials() {
                    @Override
                    public String getAWSAccessKeyId() {
                        return awsAccessKeyId;
                    }

                    @Override
                    public String getAWSSecretKey() {
                        return awsSecretAccessKey;
                    }
                };
            }

            @Override
            public void refresh() {

            }
        };
        snsClient = new AmazonSNSClient(credentialsProvider);
        snsClient.setRegion(Region.getRegion(Regions.AP_SOUTHEAST_1));
        GsonBuilder builder = new GsonBuilder();
        gson = builder.create();

        if (awsSQSQueueName != null) {
            // Create the connection factory using the environment variable credential provider.
            // Connections this factory creates can talk to the queues in us-east-1 region.
            SQSConnectionFactory connectionFactory = SQSConnectionFactory.builder()
                    .withRegion(Region.getRegion(Regions.AP_SOUTHEAST_1))
                    .withAWSCredentialsProvider(credentialsProvider).build();

            // Create the connection.
            SQSConnection connection = connectionFactory.createConnection();

            // Get the wrapped client
            AmazonSQSMessagingClientWrapper client = connection.getWrappedAmazonSQSClient();

            // Create an SQS queue named 'TestQueue'  if it does not already exist.
            if (!client.queueExists(awsSQSQueueName)) {
                client.createQueue(awsSQSQueueName);
            }

            // Create the non-transacted session with AUTO_ACKNOWLEDGE mode
            Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

            // Create a queue identity with name 'TestQueue' in the session
            Queue queue = session.createQueue(awsSQSQueueName);

            // Create a consumer for the 'TestQueue'.
            MessageConsumer consumer = session.createConsumer(queue);

            // Instantiate and set the message listener for the consumer.
            consumer.setMessageListener(new AWSSqsMessageListener());

            // Start receiving incoming messages.
            connection.start();
        }
    }

    query = properties.getProperty("database.insertPosition");
    if (query != null) {
        queryAddPosition = new NamedParameterStatement(query, dataSource, Statement.RETURN_GENERATED_KEYS);
    }

    query = properties.getProperty("database.updatePosition");
    if (query != null) {
        queryUpdatePosition = new NamedParameterStatement(query, dataSource);
    }

    query = properties.getProperty("database.updateLatestPosition");
    if (query != null) {
        queryUpdateLatestPosition = new NamedParameterStatement(query, dataSource);
    }
}