Package com.amazonaws.util.json

Examples of com.amazonaws.util.json.JSONObject


    private static Map<String, String> convertJSONToMap(String descriptionJSONString) {
        if (descriptionJSONString == null) {
            return null;
        }
        try {
            JSONObject descriptionJSON = new JSONObject(descriptionJSONString);
            Iterator<String> keysIterator = descriptionJSON.keys();
            Map<String, String> materialsDescription = new HashMap<String, String>();
            while(keysIterator.hasNext()) {
                String key = keysIterator.next();
                materialsDescription.put(key, descriptionJSON.getString(key));
            }
            return materialsDescription;
        } catch (JSONException e) {
            throw new AmazonClientException("Unable to parse encryption materials description from metadata :" + e.getMessage());
        }
View Full Code Here


        // Put the cipher initialization vector (IV) into the object metadata
        metadata.addUserMetadata(Headers.CRYPTO_IV,
                Base64.encodeAsString(symmetricCipher.getIV()));

        // Put the materials description into the object metadata as JSON
        JSONObject descriptionJSON = new JSONObject(materialsDescription);
        metadata.addUserMetadata(Headers.MATERIALS_DESCRIPTION, descriptionJSON.toString());
    }
View Full Code Here

     * Returns a JSONObject representation of the instruction object.
     * @deprecated no longer used and will be removed in the future
     */
    @Deprecated
    private static JSONObject convertInstructionToJSONObject(EncryptionInstruction instruction) {
        JSONObject instructionJSON = new JSONObject();
        try {
            JSONObject materialsDescriptionJSON = new JSONObject(
                    instruction.getMaterialsDescription());
            instructionJSON.put(Headers.MATERIALS_DESCRIPTION,
                    materialsDescriptionJSON.toString());
            instructionJSON.put(Headers.CRYPTO_KEY,
                Base64.encodeAsString(instruction.getEncryptedSymmetricKey()));
            byte[] iv = instruction.getSymmetricCipher().getIV();
            instructionJSON.put(Headers.CRYPTO_IV, Base64.encodeAsString(iv));
        } catch (JSONException e) {} // Keys are never null, so JSONException will never be thrown.
View Full Code Here

     */
    @Deprecated
    private static JSONObject parseJSONInstruction(S3Object instructionObject) {
        try {
            String instructionString = convertStreamToString(instructionObject.getObjectContent());
            return new JSONObject(instructionString);
        } catch (Exception e) {
            throw new AmazonClientException("Error parsing JSON instruction file: " + e.getMessage());
        }
    }
View Full Code Here

        }
    }


    private void assignContent(Request request, Object representation) {
        String contentString = new JSONObject(representation).toString();

        if (contentString == null) {
            throw new AmazonClientException("Unable to marshall representation to JSON: " + representation);
        }
View Full Code Here

        }

        Policy policy = new Policy();
        List<Statement> statements = new LinkedList<Statement>();
        try {
            JSONObject jPolicy = new JSONObject(jsonString);

            if (Arrays.asList(JSONObject.getNames(jPolicy)).contains(JsonDocumentFields.POLICY_ID)) {
                policy.setId(jPolicy.getString(JsonDocumentFields.POLICY_ID));
            }

            JSONArray jStatements = jPolicy.getJSONArray(JsonDocumentFields.STATEMENT);

            for (int index = 0 ; index < jStatements.length() ; index++) {
                Statement statement = convertStatement(jStatements.getJSONObject(index));
                if (statement != null) {
                statements.add(statement);
View Full Code Here

        if (statement.getPrincipals() == null) {
            statement.setPrincipals(new LinkedList<Principal>());
        }

        JSONObject jPrincipals = jStatement.getJSONObject(JsonDocumentFields.PRINCIPAL);
        String[] fields = JSONObject.getNames(jPrincipals);
        for (String field : fields) {
            String serviceId = jPrincipals.optString(field);
            if (serviceId != null && serviceId.length() > 0) {
                if (field.equalsIgnoreCase("AWS")) {
                statement.getPrincipals().add(new Principal(serviceId));
                } else if (field.equalsIgnoreCase("Service")) {
                    statement.getPrincipals().add(new Principal(Services.fromString(serviceId)));
                }
            } else {
                JSONArray jPrincipal = jPrincipals.getJSONArray(field);
                convertPrincipalRecord(field, statement, jPrincipal);
            }
        }
    }
View Full Code Here

    private void convertCondition(Statement statement, JSONObject jStatement) throws JSONException {
        if (!Arrays.asList(JSONObject.getNames(jStatement)).contains(JsonDocumentFields.CONDITION)) {
            return;
        }
        JSONObject jConditions = jStatement.getJSONObject(JsonDocumentFields.CONDITION);
        List<Condition> conditions = new LinkedList<Condition>();
        String[] types = JSONObject.getNames(jConditions);
        for (String type : types) {
             JSONObject jCondition = jConditions.getJSONObject(type);
             convertConditionRecord(conditions, type, jCondition);
        }
        statement.setConditions(conditions);
    }
View Full Code Here

        if (!messageBody.startsWith("{")) {
          messageBody = new String(BinaryUtils.fromBase64(messageBody));
        }

        try {
          JSONObject json = new JSONObject(messageBody);
          String jsonMessage = json.getString("Message").replace("\\\"", "\"");

          json = new JSONObject(jsonMessage);
          String messageJobId = json.getString("JobId");
          String messageStatus = json.getString("StatusMessage");

          // Don't process this message if it wasn't the job we were looking for
          if (!jobId.equals(messageJobId)) continue;

          try {
View Full Code Here

     *      The crypto provider whose encryption implementation will be used to encrypt and decrypt data.
     * @return
     *      An instruction object containing encryption information
     */
    public static EncryptionInstruction buildInstructionFromInstructionFile(S3Object instructionFile, EncryptionMaterials materials, Provider cryptoProvider) {
        JSONObject instructionJSON = parseJSONInstruction(instructionFile);
        try {
            // Get fields from instruction object           
            byte[] encryptedSymmetricKeyBytes = instructionJSON.getString(Headers.CRYPTO_KEY).getBytes();           
            byte[] initVectorBytes = instructionJSON.getString(Headers.CRYPTO_IV).getBytes();
            String materialsDescriptionString = instructionJSON.getString(Headers.MATERIALS_DESCRIPTION);
            Map<String, String> materialsDescription = convertJSONToMap(materialsDescriptionString);
           
            // Decode from Base 64 to standard binary bytes
            encryptedSymmetricKeyBytes = Base64.decodeBase64(encryptedSymmetricKeyBytes);
            initVectorBytes = Base64.decodeBase64(initVectorBytes);
View Full Code Here

TOP

Related Classes of com.amazonaws.util.json.JSONObject

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.