如何使用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);