Package org.jets3t.service.security

Examples of org.jets3t.service.security.ProviderCredentials


        // Download the encrypted credentials object.
        S3Object retrievedCredsObject = s3Service.getObject(bucket, credentialObjectName);

        // Decrypt the credentials object.
        ProviderCredentials retrievedCreds = AWSCredentials.load(password,
            new BufferedInputStream(retrievedCredsObject.getDataInputStream()));

        System.out.println("Retrieved credentials from S3: "
            + retrievedCreds.getAccessKey() + " : " + retrievedCreds.getSecretKey());
    }
View Full Code Here


        // Save credentials to an encrypted file protected with a password.
        File credFile = new File("awscredentials.enc");
        awsCredentials.save("password", credFile);

        // Load encrypted credentials from a file.
        ProviderCredentials loadedCredentials = AWSCredentials.load("password", credFile);
        System.out.println("AWS Key loaded from file: " + loadedCredentials.getAccessKey());

        // You won't get far if you use the wrong password...
        try {
            loadedCredentials = AWSCredentials.load("wrongPassword", credFile);
        } catch (S3ServiceException e) {
View Full Code Here

    private void storeCredentialsInStorageService(String passphrase, String password) {
        if (!validPassphraseInputs(passphrase, password)) {
            return;
        }

        final ProviderCredentials credentials =
            CredentialsDialog.showDialog(ownerFrame,
                (loginMode == LOGIN_MODE_LOCAL_FOLDER),
                this.isTargetS3(),
                myProperties, hyperlinkListener);
        if (credentials == null) {
            return;
        }

        final String[] bucketName = new String[1];
        final String[] credentialObjectKey = new String[1];

        try {
            bucketName[0] = generateBucketNameFromPassphrase(passphrase);
            credentialObjectKey[0] = generateObjectKeyFromPassphrase(passphrase, password);
        } catch (Exception e) {
            String message = "Unable to generate bucket name or object key";
            log.error(message, e);
            ErrorDialog.showDialog(this, hyperlinkListener, message, e);
            return;
        }

        final ByteArrayInputStream[] bais = new ByteArrayInputStream[1];
        try {
            // Convert credentials into a readable input stream.
            String algorithm = myProperties.getStringProperty("crypto.algorithm", "PBEWithMD5AndDES");
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            credentials.save(password, baos, algorithm);
            bais[0] = new ByteArrayInputStream(baos.toByteArray());
        } catch (RuntimeException e) {
            throw e;
        } catch (Exception e) {
            String message = "Unable to encrypt your credentials";
View Full Code Here

        }
        if (EMPTY_PASSWORD_SURROGATE.equals(password.trim())) {
            password = "";
        }

        ProviderCredentials myCredentials =
            CredentialsDialog.showDialog(ownerFrame, true, this.isTargetS3(),
                myProperties, hyperlinkListener);
        if (myCredentials == null) {
            return;
        }
        if (myCredentials.getFriendlyName() == null || myCredentials.getFriendlyName().length() == 0) {
            String message = "You must enter a nickname when storing your credentials";
            log.error(message);
            ErrorDialog.showDialog(this, hyperlinkListener, message, null);
            return;
        }

        File credentialsFile = new File(directory, myCredentials.getFriendlyName() + ".enc");

        try {
            String algorithm = myProperties.getStringProperty("crypto.algorithm", "PBEWithMD5AndDES");
            myCredentials.save(password, credentialsFile, algorithm);
            loginLocalFolderPanel.clearPassword();
            loginLocalFolderPanel.refreshStoredCredentialsTable();

            JOptionPane.showMessageDialog(ownerFrame, "Your credentials have been stored in the file:\n" +
                credentialsFile.getAbsolutePath());
View Full Code Here

        };

        StartupDialog startupDialog = new StartupDialog(f,
            Jets3tProperties.getInstance(Constants.JETS3T_PROPERTIES_FILENAME), listener);
        startupDialog.setVisible(true);
        ProviderCredentials credentials = startupDialog.getProviderCredentials();
        startupDialog.dispose();

        if (credentials != null) {
            System.out.println("Credentials: " + credentials.getLogString());
        } else {
            System.out.println("Credentials: null");
        }

        f.dispose();
View Full Code Here

            File[] files = cockpitHomeFolder.listFiles();
            for (int i = 0; files != null && i < files.length; i++) {
                File candidateFile = files[i];
                if (candidateFile.getName().endsWith(".enc")) {
                    // Load partial details from credentials file.
                    ProviderCredentials credentials = ProviderCredentials.load(null, candidateFile);
                    nicknamesTableModel.addCredentialsFile(
                        credentials, candidateFile);
                }
            }
        } catch (Exception e) {
View Full Code Here

    {
        CredentialsDialog dialog = new CredentialsDialog(
            ownerFrame, askForFriendlyName, jets3tProperties, hyperlinkListener);
        dialog.setVisible(true);

        ProviderCredentials credentials = null;
        if (dialog.isConfirmed()) {
            // Handle Google Storage endpoint
            if  (!isTargetS3) {
                credentials = new GSCredentials(
                    dialog.getAccessKey(),
View Full Code Here

            loginEvent(null);
        } else if ("LogoutEvent".equals(event.getActionCommand())) {
            logoutEvent();
        } else if (event.getActionCommand() != null && event.getActionCommand().startsWith("LoginSwitch")) {
            String loginName = event.getActionCommand().substring("LoginSwitch:".length());
            ProviderCredentials credentials = loginAwsCredentialsMap.get(loginName);
            loginEvent(credentials);
        } else if ("QuitEvent".equals(event.getActionCommand())) {
            System.exit(0);
        }
View Full Code Here

     * This method should always be invoked within the event dispatching thread.
     */
    private void logoutEvent() {
        log.debug("Logging out");
        try {
            ProviderCredentials credentials = s3ServiceMulti.getAWSCredentials();
            String loginName = (credentials.hasFriendlyName()
                ? credentials.getFriendlyName()
                : credentials.getAccessKey());
            if (loginAwsCredentialsMap.containsKey(loginName)) {
                Component[] components = loginSwitchMenu.getMenuComponents();
                for (int i = 0; i < components.length; i++) {
                    JMenuItem menuItem = (JMenuItem)components[i];
                    if (loginName.equals(menuItem.getText())) {
View Full Code Here

        boolean isEncryptionEnabled = false;
        boolean isMoveEnabled = false;
        boolean isBatchMode = false;
        String aclString = null;
        int reportLevel = REPORT_LEVEL_ALL;
        ProviderCredentials providerCredentials = null;
        String providerId = "S3";

        // Parse arguments.
        for (int i = 0; i < args.length; i++) {
            String arg = args[i];
            if (arg.startsWith("-")) {
                // Argument is an option.
                if (arg.equalsIgnoreCase("-h") || arg.equalsIgnoreCase("--help")) {
                    printHelpAndExit(true);
                } else if (arg.equalsIgnoreCase("-n") || arg.equalsIgnoreCase("--noaction")) {
                    doAction = false;
                } else if (arg.equalsIgnoreCase("-q") || arg.equalsIgnoreCase("--quiet")) {
                    isQuiet = true;
                } else if (arg.equalsIgnoreCase("-p") || arg.equalsIgnoreCase("--noprogress")) {
                    isNoProgress = true;
                } else if (arg.equalsIgnoreCase("-f") || arg.equalsIgnoreCase("--force")) {
                    isForce = true;
                } else if (arg.equalsIgnoreCase("-k") || arg.equalsIgnoreCase("--keepfiles")) {
                    isKeepFiles = true;
                } else if (arg.equalsIgnoreCase("-d") || arg.equalsIgnoreCase("--nodelete")) {
                    isNoDelete = true;
                } else if (arg.equalsIgnoreCase("-g") || arg.equalsIgnoreCase("--gzip")) {
                    isGzipEnabled = true;
                } else if (arg.equalsIgnoreCase("-c") || arg.equalsIgnoreCase("--crypto")) {
                    isEncryptionEnabled = true;
                } else if (arg.equalsIgnoreCase("-m") || arg.equalsIgnoreCase("--move")) {
                    isMoveEnabled = true;
                } else if (arg.equalsIgnoreCase("-s") || arg.equalsIgnoreCase("--skipmetadata")) {
                    System.err.println("WARNING: --skipmetadata is obsolete since JetS3t 0.8.1, it has no effect");
                } else if (arg.equalsIgnoreCase("-b") || arg.equalsIgnoreCase("--batch")) {
                    isBatchMode = true;
                } else if (arg.equalsIgnoreCase("--provider")) {
                    if (i + 1 < args.length) {
                        // Read custom Synchronize properties file from the specified file
                        i++;
                        providerId = args[i];
                        if (!"S3".equalsIgnoreCase(providerId)
                            && !"GS".equalsIgnoreCase(providerId))
                        {
                            System.err.println("ERROR: --provider option must be one of 'S3' or 'GS'");
                            printHelpAndExit(false);
                        }
                    } else {
                        System.err.println("ERROR: --provider option must be followed by a provider ID 'S3' or 'GS'");
                        printHelpAndExit(false);
                    }
                } else if (arg.equalsIgnoreCase("--properties")) {
                    if (i + 1 < args.length) {
                        // Read custom Synchronize properties file from the specified file
                        i++;
                        propertiesFileName = args[i];
                        File propertiesFile = new File(propertiesFileName);
                        if (!propertiesFile.canRead()) {
                            System.err.println("ERROR: The properties file " + propertiesFileName + " could not be found");
                            System.exit(2);
                        }
                        myProperties.loadAndReplaceProperties(
                            new FileInputStream(propertiesFileName), propertiesFile.getName());
                    } else {
                        System.err.println("ERROR: --properties option must be followed by a file path");
                        printHelpAndExit(false);
                    }
                } else if (arg.equalsIgnoreCase("--acl")) {
                    if (i + 1 < args.length) {
                        // Read the acl setting string
                        i++;
                        aclString = args[i];

                        if (!"PUBLIC_READ".equalsIgnoreCase(aclString)
                            && !"PUBLIC_READ_WRITE".equalsIgnoreCase(aclString)
                            && !"PRIVATE".equalsIgnoreCase(aclString))
                        {
                            System.err.println("ERROR: Acess Control List setting \"acl\" must have one of the values "
                                + "PRIVATE, PUBLIC_READ, PUBLIC_READ_WRITE");
                            printHelpAndExit(false);
                        }
                    } else {
                        System.err.println("ERROR: --acl option must be followed by an ACL string");
                        printHelpAndExit(false);
                    }
                } else if (arg.equalsIgnoreCase("--reportlevel")) {
                    if (i + 1 < args.length) {
                        // Read the report level integer
                        i++;
                        try {
                            reportLevel = Integer.parseInt(args[i]);

                            if (reportLevel < 0 || reportLevel > 3) {
                                System.err.println("ERROR: Report Level setting \"reportlevel\" must have one of the values "
                                    + "0 (no reporting), 1 (actions only), 2 (differences only), 3 (DEFAULT - all reporting)");
                                printHelpAndExit(false);
                            }
                        } catch (NumberFormatException e) {
                            System.err.println("ERROR: --reportlevel option must be followed by 0, 1, 2 or 3");
                            printHelpAndExit(false);
                        }
                    } else {
                        System.err.println("ERROR: --reportlevel option must be followed by 0, 1, 2 or 3");
                        printHelpAndExit(false);
                    }
                } else if (arg.equalsIgnoreCase("--credentials")) {
                    if (i + 1 < args.length) {
                        // Read the credentials file location
                        i++;
                        File credentialsFile = new File(args[i]);
                        if (!credentialsFile.canRead()) {
                            System.err.println("ERROR: Cannot read credentials file '" + credentialsFile + "'");
                            printHelpAndExit(false);
                        }
                        while (providerCredentials == null) {
                            String credentialsPassword = PasswordInput.getPassword(
                                "Password for credentials file '" + credentialsFile + "'");
                            try {
                                providerCredentials = ProviderCredentials.load(credentialsPassword, credentialsFile);
                                // Set dummy accesskey and secretkey property values, to avoid prompting for these values later on.
                                myProperties.setProperty("accesskey", "");
                                myProperties.setProperty("secretkey", "");
                            } catch (ServiceException e) {
                                System.out.println("Failed to read credentials from the file '" + credentialsFile + "'");
                            }
                        }
                    } else {
                        System.err.println("ERROR: --credentials option must be followed by a file path");
                        printHelpAndExit(false);
                    }
                } else {
                    System.err.println("ERROR: Invalid option: " + arg);
                    printHelpAndExit(false);
                }
            } else {
                // Argument is one of the required parameters.
                if (reqArgCount == 0) {
                    actionCommand = arg.toUpperCase(Locale.getDefault());
                    if (!"UP".equals(actionCommand) && !"DOWN".equals(actionCommand)) {
                        System.err.println("ERROR: Invalid action command " + actionCommand
                            + ". Valid values are 'UP' or 'DOWN'");
                        printHelpAndExit(false);
                    }
                } else if (reqArgCount == 1) {
                    servicePath = arg;
                } else if (reqArgCount > 1) {
                    File file = new File(arg);

                    if ("DOWN".equals(actionCommand)) {
                        if (reqArgCount > 2) {
                            System.err.println("ERROR: Only one target directory may be specified"
                                + " for " + actionCommand);
                            printHelpAndExit(false);
                        }
                        if (!file.exists()) {
                            // Create missing target directory
                            if (!file.mkdirs()) {
                                System.err.println(
                                    "ERROR: Target download directory does not exist and could not be created: " + file);
                                System.exit(1);
                            }
                        }
                        if (file.exists() && !file.isDirectory()) {
                            System.err.println(
                                "ERROR: Target download location already exists but is not a directory: " + file);
                            System.exit(1);
                        }
                        if (!file.canWrite() || !file.canWrite()) {
                            System.err.println(
                                "ERROR: Invalid permissions on target download location, cannot "
                                + (!file.canRead()
                                    ? "read from" + (!file.canWrite()? " or " : "")
                                    : "")
                                + (!file.canWrite() ? "write to" : "")
                                + " directory: " + file.getAbsolutePath());
                            System.exit(1);
                        }
                        if (!file.canWrite()) {
                            System.err.println(
                                "ERROR: Cannot write to target download location: " + file);
                            System.exit(1);
                        }
                    } else {
                        if (!file.canRead()) {
                            if (myProperties != null && myProperties.getBoolProperty("upload.ignoreMissingPaths", false)) {
                                System.err.println("WARN: Ignoring missing upload path: " + file);
                                continue;
                            } else {
                                System.err.println(
                                    "ERROR: Cannot read upload file/directory: " + file + "\n" +
                                    "       To ignore missing paths set the property upload.ignoreMissingPaths");
                                printHelpAndExit(false);
                            }
                        }
                    }
                    fileSet.add(file);
                }
                reqArgCount++;
            }
        }

        if (fileSet.size() < 1
            && !myProperties.getBoolProperty("upload.ignoreMissingPaths", false))
        {
            // Missing one or more required parameters.
            System.err.println("ERROR: Missing required file path(s)");
            printHelpAndExit(false);
        }

        if (isKeepFiles && isNoDelete) {
            // Incompatible options.
            System.err.println("ERROR: Options --keepfiles and --nodelete cannot be used at the same time");
            printHelpAndExit(false);
        }

        if (isKeepFiles && isMoveEnabled) {
            // Incompatible options.
            System.err.println("ERROR: Options --keepfiles and --move cannot be used at the same time");
            printHelpAndExit(false);
        }

        // Ensure the Synchronize properties file contains everything we need, and prompt
        // for any required information that is missing.
        if (!myProperties.containsKey("accesskey")
            || !myProperties.containsKey("secretkey")
            || (isEncryptionEnabled && !myProperties.containsKey("password")))
        {
            System.out.println("Please enter the required properties that have not been provided in a properties file:");
            BufferedReader inputReader = new BufferedReader(new InputStreamReader(System.in));
            if (!myProperties.containsKey("accesskey")) {
                System.out.print("Acccess Key: ");
                myProperties.setProperty("accesskey", inputReader.readLine());
            }
            if (!myProperties.containsKey("secretkey")) {
                System.out.print("Secret Key: ");
                myProperties.setProperty("secretkey", inputReader.readLine());
            }
            if (isEncryptionEnabled && !myProperties.containsKey("password")) {
                String password1 = "password1";
                String password2 = "password2";
                while (!password1.equals(password2)) {
                    password1 = PasswordInput.getPassword("Encryption password");
                    password2 = PasswordInput.getPassword("Confirm password");
                    if (!password1.equals(password2)) {
                        System.out.println("The original and confirmation passwords do not match, try again.");
                    }
                }
                myProperties.setProperty("password", password1);
            }
        }

        // Use property values for the credentials, if we haven't already been
        // given the credentials through the --credentials argument.
        if (providerCredentials == null) {
            if ("S3".equalsIgnoreCase(providerId)) {
                providerCredentials = new AWSCredentials(
                    myProperties.getStringProperty("accesskey", null),
                    myProperties.getStringProperty("secretkey", null));
            } else if ("GS".equalsIgnoreCase(providerId)) {
                providerCredentials = new GSCredentials(
                    myProperties.getStringProperty("accesskey", null),
                    myProperties.getStringProperty("secretkey", null));
            }
        }

        // Sanity-check credentials -- if both are null or empty strings,
        // then nullify the credentials object to get an anonymous connection.
        if (providerCredentials.getAccessKey() == null || providerCredentials.getAccessKey().length() == 0
            || providerCredentials.getSecretKey() == null || providerCredentials.getSecretKey().length() == 0)
        {
            providerCredentials = null;
        }

        if (aclString == null) {
View Full Code Here

TOP

Related Classes of org.jets3t.service.security.ProviderCredentials

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.