Package org.jets3t.service.security

Examples of org.jets3t.service.security.AWSCredentials


    /**
     * @param args
     */
    public static void main(String[] args) throws Exception {
        AWSCredentials fakeAwsCredentials = new AWSCredentials("fake-aws-access-key", "fake-aws-secret-key");
       
        int port = 443;
        ServerSocketFactory ssocketFactory = SSLServerSocketFactory.getDefault();
        ServerSocket ssocket = ssocketFactory.createServerSocket(port);
        System.out.println("Accepting connections on port 443");
   
        while (port == 443) {
            // Listen for connections
            Socket socket = ssocket.accept();
            System.out.println("Opened connection");
       
            // Create streams to securely send and receive data to the client
            InputStream in = socket.getInputStream();
            OutputStream out = socket.getOutputStream();
       
            byte[] buffer = new byte[1024];
            int read;
       
            while ((read = in.read(buffer)) != -1) {
                String receivedDataStr = new String(buffer, 0, read);
                String requestActionAndHeaders =
                    receivedDataStr.substring(0, receivedDataStr.indexOf("\r\n\r\n") + 4);
               
                System.out.println(requestActionAndHeaders);
               
                if (requestActionAndHeaders.startsWith("GET")) {
                    String path = requestActionAndHeaders.substring(4,
                        requestActionAndHeaders.indexOf(' ', 4));
                   
                    if (path.startsWith("/jets3t-")) {
                        // Return fake AWS credentials.
                        String headers =
                            "HTTP/1.1 200 OK\r\n" +
                            "x-amz-id-2: FakeAWSCredentials\r\n" +
                            "x-amz-request-id: FakeAWSCredentials\r\n" +
                            "Date: Thu, 24 May 2007 13:39:21 GMT\r\n" +
                            "Cache-Control: max-age=259200\r\n" +
                            "Last-Modified: Wed, 27 Dec 2006 02:37:58 GMT\r\n" +
                            "ETag: \"fa5d6b0ea9716cf692b286b6aa187f3d\"\r\n" +
                            "Content-Type: application/octet-stream\r\n" +
                            "Content-Length: 139\r\n" +
                            "Server: AmazonS3\r\n\r\n";
                       
                        out.write(headers.getBytes("UTF-8"));
                        fakeAwsCredentials.save("please", out);
                    }
                   
                    else if (path.equals("/")) {
                        // Return fake bucket listing.
                        String headers =
View Full Code Here


            System.err.println("ERROR: You are using encryption, so the properties file " + propertiesFileName + " must contain the property: password");
            System.exit(2);                       
        }
       
        // Load the AWS credentials from encrypted file.
        AWSCredentials awsCredentials = new AWSCredentials(
            myProperties.getStringProperty("accesskey", null),
            myProperties.getStringProperty("secretkey", null));      
       
        if (aclString == null) {
            aclString = myProperties.getStringProperty("acl", "PRIVATE");
View Full Code Here

                + TEST_PROPERTIES_FILENAME);
        }
       
        Properties testProperties = new Properties();       
        testProperties.load(propertiesIS);
        awsCredentials = new AWSCredentials(
            testProperties.getProperty("aws.accesskey"),
            testProperties.getProperty("aws.secretkey"));
    }
View Full Code Here

        boolean isMoveEnabled = false;
        boolean isBatchMode = false;
        boolean isSkipMetadata = false;
        String aclString = null;
        int reportLevel = REPORT_LEVEL_ALL;
        AWSCredentials awsCredentials = null;
               
        // 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")) {
                    isSkipMetadata = true;
                } else if (arg.equalsIgnoreCase("-b") || arg.equalsIgnoreCase("--batch")) {
                    isBatchMode = true;
                } else if (arg.equalsIgnoreCase("--properties")) {
                    if (i + 1 < args.length) {
                        // Read the 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());
                        synchronizePropertiesLoaded = true;
                    } 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);                           
                        }                       
                        BufferedReader inputReader = new BufferedReader(new InputStreamReader(System.in));
                        while (awsCredentials == null) {
                            System.out.print("Password for credentials file '" + credentialsFile + "': ");
                            String credentialsPassword = inputReader.readLine();
                            try {
                                awsCredentials = AWSCredentials.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 (S3ServiceException e) {
                                System.out.println("Failed to read AWS 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) {
                    s3Path = 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() && !file.isDirectory()) {
                            System.err.println("ERROR: Target download location already exists but is not a directory: "
                                + file);                               
                        }        
                    } 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);                           
                            }
                        }
                    }
                    fileList.add(file);
                }
                reqArgCount++;
            }
        }
       
        if (fileList.size() < 1) {
            // 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);           
        }
       
        if (isSkipMetadata && (isGzipEnabled || isEncryptionEnabled)) {
            // Incompatible options.
            System.err.println("ERROR: The --skipmetadata option cannot be used with the --gzip or --crypto options");
            printHelpAndExit(false);                       
        }
       
        if (!synchronizePropertiesLoaded) {       
            // Read the Synchronize properties file from the classpath
            Jets3tProperties synchronizeProperties =
                Jets3tProperties.getInstance(propertiesFileName);
            if (synchronizeProperties.isLoaded()) {
                myProperties.loadAndReplaceProperties(synchronizeProperties,
                    propertiesFileName + " in classpath");               
            }
        }
               
        // 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("AWS Acccess Key: ");
                myProperties.setProperty("accesskey", inputReader.readLine());
            }
            if (!myProperties.containsKey("secretkey")) {
                System.out.print("AWS Secret Key: ");
                myProperties.setProperty("secretkey", inputReader.readLine());
            }
            if (isEncryptionEnabled && !myProperties.containsKey("password")) {
                String password1 = "password1";               
                String password2 = "password2";
                while (!password1.equals(password2)) {
                    System.out.print("Encryption password: ");
                    password1 = inputReader.readLine();
                    System.out.print("Confirm password: ");
                    password2 = inputReader.readLine();
                    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 AWS credentials, if we haven't already been
        // given the credentials through the --credentials argument.
        if (awsCredentials == null) {
            awsCredentials = new AWSCredentials(
                myProperties.getStringProperty("accesskey", null),
                myProperties.getStringProperty("secretkey", null));
        }
       
        // Sanity-check AWS credentials -- if both are null or empty strings,
        // then nullify the AWSCredentials object to get an anonymous connection.
        if (awsCredentials.getAccessKey() == null || awsCredentials.getAccessKey().length() == 0
            || awsCredentials.getSecretKey() == null || awsCredentials.getSecretKey().length() == 0)
        {
            awsCredentials = null;
        }
       
        if (aclString == null) {
View Full Code Here

     * @return S3Service
     */
    private S3Service getS3Service() {
        S3Service s3Service = null;
        try {
            s3Service = new RestS3Service(new AWSCredentials(AmazonCredential.getInstance().getAwsAccessKeyId(),
                    AmazonCredential.getInstance().getAwsSecretAccessKey()));
        } catch (S3ServiceException s3ex) {
            xBayaEngine.getErrorWindow().error(s3ex);
        }
        return s3Service;
View Full Code Here

        throw new IllegalArgumentException("AWS " +
            "Secret Access Key must be specified " +
            "as the password of a s3 URL, or by setting the " +
            "fs.s3.awsSecretAccessKey property.");       
      }
      AWSCredentials awsCredentials = new AWSCredentials(accessKey, secretAccessKey);
      this.s3Service = new RestS3Service(awsCredentials);
    } catch (S3ServiceException e) {
      if (e.getCause() instanceof IOException) {
        throw (IOException) e.getCause();
      }
View Full Code Here

  @Override
  public void initialize(URI uri, Configuration conf) throws IOException {
    S3Credentials s3Credentials = new S3Credentials();
    s3Credentials.initialize(uri, conf);
    try {
      AWSCredentials awsCredentials =
        new AWSCredentials(s3Credentials.getAccessKey(),
            s3Credentials.getSecretAccessKey());
      this.s3Service = new RestS3Service(awsCredentials);
    } catch (S3ServiceException e) {
      handleS3ServiceException(e);
    }
View Full Code Here

        String accessKey = authenticationInfo.getUserName();
        String secretKey = authenticationInfo.getPassphrase();
        if (accessKey == null || secretKey == null) {
            throw new AuthenticationException("S3 requires a username and passphrase to be set");
        }
        return new AWSCredentials(accessKey, secretKey);
    }
View Full Code Here

  public RestS3Service getRestS3Service(AWSCredentialsProvider provider)
  {
    if(provider.getCredentials() instanceof com.amazonaws.auth.AWSSessionCredentials) {
      return new RestS3Service(new AWSSessionCredentialsAdapter(provider));
    } else {
      return new RestS3Service(new AWSCredentials(
          provider.getCredentials().getAWSAccessKeyId(),
          provider.getCredentials().getAWSSecretKey()
      ));
    }
  }
View Full Code Here

        throw new IllegalArgumentException("AWS " +
            "Secret Access Key must be specified " +
            "as the password of a s3 URL, or by setting the " +
            "fs.s3.awsSecretAccessKey property.");       
      }
      AWSCredentials awsCredentials = new AWSCredentials(accessKey, secretAccessKey);
      this.s3Service = new RestS3Service(awsCredentials);
    } catch (S3ServiceException e) {
      if (e.getCause() instanceof IOException) {
        throw (IOException) e.getCause();
      }
View Full Code Here

TOP

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

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.