vod普通加密

This commit is contained in:
wangjinlei
2024-07-18 13:29:22 +08:00
parent 64702a8184
commit 00b9f96dd1
8 changed files with 297 additions and 1 deletions

View File

@@ -5,6 +5,13 @@ import com.aliyun.teautil.models.RuntimeOptions;
import com.aliyun.vod20170321.Client;
import com.aliyun.vod20170321.models.GetVideoPlayAuthRequest;
import com.aliyun.vod20170321.models.GetVideoPlayAuthResponse;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.IClientProfile;
import com.aliyuncs.sts.model.v20150401.AssumeRoleRequest;
import com.aliyuncs.sts.model.v20150401.AssumeRoleResponse;
//import org.bytedeco.javacv.FFmpegFrameGrabber;
//import org.bytedeco.javacv.FrameGrabber;
@@ -59,4 +66,53 @@ public class SpdbUtil {
}
}
public static AssumeRoleResponse assumeRole() throws ClientException {
try {
String accessKeyId = "LTAI5tC9d38msYxw6RSEwJJR";
String accessKeySecret = "njJxkvrwBmbMfGyhAFeyjthodnwt58";
String roleArn = "acs:ram::1604740137891907:role/vodrole";
String roleSessionName = "testsession";
String policy = "{\n" +
" \"Version\": \"1\",\n" +
" \"Statement\": [\n" +
" {\n" +
" \"Action\": \"vod:*\",\n" +
" \"Resource\": \"*\",\n" +
" \"Effect\": \"Allow\"\n" +
" }\n" +
" ]\n" +
"}";
//构造default profile参数留空无需添加Region ID
/*
说明当设置SysEndpoint为sts.aliyuncs.com时regionId可填可不填反之regionId必填根据使用的服务区域填写例如cn-shanghai
详情参考STS各地域的Endpoint。
*/
IClientProfile profile = DefaultProfile.getProfile("", accessKeyId, accessKeySecret);
//用profile构造client
DefaultAcsClient client = new DefaultAcsClient(profile);
// 创建一个 AssumeRoleRequest 并设置请求参数
final AssumeRoleRequest request = new AssumeRoleRequest();
// request.setSysEndpoint("sts.aliyuncs.com");
// request.setSysMethod(MethodType.POST);
request.setRoleArn(roleArn);
request.setRoleSessionName(roleSessionName);
request.setPolicy(policy);
request.setRegionId("cn-shanghai");
// 发起请求并得到response
final AssumeRoleResponse response = client.getAcsResponse(request);
return response;
} catch (ClientException e) {
throw e;
}
}
}