Beispiel #1
0
        /**
         * Returns new object statements for given policy type.
         */
        private List <Statement> newObjectStatement(PolicyType policy, String prefix)
        {
            List <Statement> statements = new List <Statement>();

            if (policy.Equals(PolicyType.NONE) || bucketName == null || bucketName.Length == 0)
            {
                return(statements);
            }

            Resources resources = new Resources(PolicyConstants.AWS_RESOURCE_PREFIX + bucketName + "/" + prefix + "*");

            Statement statement = new Statement();

            statement.effect    = "Allow";
            statement.principal = new Principal("*");
            statement.resources = resources;
            statement.sid       = "";
            if (policy.Equals(PolicyType.READ_ONLY))
            {
                statement.actions = PolicyConstants.READ_ONLY_OBJECT_ACTIONS;
            }
            else if (policy.Equals(PolicyType.WRITE_ONLY))
            {
                statement.actions = PolicyConstants.WRITE_ONLY_OBJECT_ACTIONS;
            }
            else if (policy.Equals(PolicyType.READ_WRITE))
            {
                statement.actions = PolicyConstants.READ_WRITE_OBJECT_ACTIONS();
            }

            statements.Add(statement);
            return(statements);
        }
Beispiel #2
0
        /**
         * Returns new bucket statements for given policy type.
         */
        private List <Statement> newBucketStatement(PolicyType policy, String prefix)
        {
            List <Statement> statements = new List <Statement>();

            if (policy.Equals(PolicyType.NONE) || bucketName == null || bucketName.Length == 0)
            {
                return(statements);
            }

            Resources resources = new Resources(PolicyConstants.AWS_RESOURCE_PREFIX + bucketName);

            Statement statement = new Statement();

            statement.actions   = PolicyConstants.COMMON_BUCKET_ACTIONS;
            statement.effect    = "Allow";
            statement.principal = new Principal("*");
            statement.resources = resources;
            statement.sid       = "";

            statements.Add(statement);

            if (policy.Equals(PolicyType.READ_ONLY) || policy.Equals(PolicyType.READ_WRITE))
            {
                statement           = new Statement();
                statement.actions   = PolicyConstants.READ_ONLY_BUCKET_ACTIONS;
                statement.effect    = "Allow";
                statement.principal = new Principal("*");
                statement.resources = resources;
                statement.sid       = "";

                if (prefix != null && prefix.Length != 0)
                {
                    ConditionKeyMap map = new ConditionKeyMap();
                    map.Put("s3:prefix", prefix);
                    statement.conditions = new ConditionMap("StringEquals", map);
                }

                statements.Add(statement);
            }

            if (policy.Equals(PolicyType.WRITE_ONLY) || policy.Equals(PolicyType.READ_WRITE))
            {
                statement           = new Statement();
                statement.actions   = PolicyConstants.WRITE_ONLY_BUCKET_ACTIONS;
                statement.effect    = "Allow";
                statement.principal = new Principal("*");
                statement.resources = resources;
                statement.sid       = "";

                statements.Add(statement);
            }

            return(statements);
        }