全部文档
当前文档

暂无内容

如果没有找到您期望的内容,请尝试其他搜索词

文档中心

授权策略(Android)

最近更新时间:2023-01-12 11:52:17

Get Bucket Policy 获取桶策略

以下代码用于获取桶策略:

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

Put Bucket Policy 添加桶策略

以下代码用于更新桶策略:

// 创建策略对象 设置相应参数 【需要配合控制台进行设置】
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) {
        //请求失败
    }
});

注:详细参数介绍请参考空间策略

Delete Bucket Policy 删除桶策略

以下代码用于删除桶策略:

// 创建删除策略对象
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

文档导读
纯净模式常规模式

纯净模式

点击可全屏预览文档内容
文档反馈