最近更新时间:2023-01-12 11:52:17
以下代码用于获取桶策略:
GetBucketPolicyRequest request = new GetBucketPolicyRequest("<bucketName>");
client.getBucketPolicy(request, new GetBucketPolicyResponceHandler() {
@Override
public void onFailure(int statesCode, Ks3Error error, Header[] responceHeaders, String response, Throwable paramThrowable) {
// 请求失败
}
@Override
public void onSuccess(int statesCode, Header[] responceHeaders, String policy) {
// 请求成功
}
});
注:此接口的请求者需要是Bucket的所有者,若无权限获取BucketPolicy,则返回403 Access Denied;若不存在BucketPolicy配置,则返回404 Policy Not Found
以下代码用于更新桶策略:
// 创建策略对象 设置相应参数 【需要配合控制台进行设置】
BucketPolicyRule policyRule = new BucketPolicyRule()
.addAllAction()
// 添加被授权人
.addPrincipalByAccountId("2000090561")
// 策略针对哪些资源起作用
.addBucketResource("jiangrantest")
// 指定IP地址
.addConditionSouceIp("11.11.11.11", true)
// 设置条件规则
.addSourceHeader("Connection: keep-alivE", BucketPolicyConditionRule.StringLike)
.addSourceHeader("Connection: keep-alivE123", BucketPolicyConditionRule.StringEquals)
// 设置效果
.setEffect("Allow");
PutBuckePolicyRequest putBuckePolicyRequest = new PutBuckePolicyRequest("<bucketName>", policyRule);
client.putBucketPolicy(putBuckePolicyRequest, new Ks3HttpResponceHandler() {
@Override
public void onSuccess(int statesCode, Header[] responceHeaders, byte[] response) {
//请求成功
}
@Override
public void onFailure(int statesCode, Header[] responceHeaders, byte[] response, Throwable throwable) {
//请求失败
}
});
注:详细参数介绍请参考空间策略
以下代码用于删除桶策略:
// 创建删除策略对象
DeleteBucketPolicyRequest request = new DeleteBucketPolicyRequest("<bucketName>");
client.deleteBucketPolicy(request, new Ks3HttpResponceHandler() {
@Override
public void onSuccess(int statesCode, Header[] responceHeaders, byte[] response) {
//请求成功
}
@Override
public void onFailure(int statesCode, Header[] responceHeaders, byte[] response, Throwable throwable){
//请求失败
}
});
注:此接口可以删除某个Bucket的Policy配置,Bucket的所有者才有权限调用此接口,调用成功后会返回204
纯净模式