allowRestrictedWriteStatement

allowRestrictedWriteStatement

如何使用Java在S3中组合策略?

Statement allowRestrictedWriteStatement = new Statement(Effect.Allow)
        .withPrincipals(new Principal("1234567"))
        .withActions(S3Actions.DeleteObject)
        .withResources(new S3ObjectResource(myBucketName, "demoFolder1"));


Statement allowRestrictedWriteStatement2 = new Statement(Effect.Deny)
        .withPrincipals(new Principal("1234567"))
        .withActions(S3Actions.DeleteObject)
        .withResources(new S3ObjectResource(myBucketName, "demoFolder2"));

Policy policy2 = new Policy()
        .withStatements(allowRestrictedWriteStatement2)
        .withStatements(allowRestrictedWriteStatement);


它仅设置allowRestrictedWriteStatement语句或Policy对象(在我们的情况下为allowRestrictedWriteStatement)中倒数第二个。有没有一种方法可以使用一个Policy对象将两个或多个策略组合在一起,请提出任何建议。

最佳答案

您需要调用一次withStatements并传递多个Statement实例(JavaDoc):

new Policy().withStatements(allowRestrictedWriteStatement, allowRestrictedWriteStatement2);

10-01 08:33