List of usage examples for com.amazonaws.services.s3 AmazonS3 getS3AccountOwner
public Owner getS3AccountOwner() throws SdkClientException, AmazonServiceException;
Gets the current owner of the AWS account that the authenticated sender of the request is using.
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 w w . ja v a 2 s . c o 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 }); }