阿里云OSS上传文件STS鉴权配置过程 解决 You should be authorized by RAM 问题

目录

 

1.RAM访问控制

2.创建用户

3. 创建RAM角色

4.新添加自定义权限策略

5.给RAM授权

6.为用户授权

结束:

问题:


1.RAM访问控制

2.创建用户

  • 访问方式添加编程访问 (将生成的AccessKey ID与Secret 进行文本保留)

3. 创建RAM角色

 

4.新添加自定义权限策略

  1. 添加oss访问策略

2.添加STS访问策略 其中 155****0653为AccountID  aliyunoss为第三步创建的用户名字

5.给RAM授权

6.为用户授权

 

结束:

至此阿里云界面配置结束。

JAVA代码调用:

public static void main(String[] args) {
    String endpoint = "sts.aliyuncs.com";
    String accessKeyId = "子用户的accessKeyId";
    String accessKeySecret = "子用户的accessKeySecret";
    String roleArn = "角色的RoleArn";
    //roleSessionName时临时Token的会话名称,自己指定用于标识你的用户,或者用于区分Token颁发给谁
    //要注意roleSessionName的长度和规则,不要有空格,只能有'-'和'_'字母和数字等字符
    String roleSessionName = "session-name";
    String policy = null;
    ProtocolType protocolType = ProtocolType.HTTPS;
    try {
	    DefaultProfile.addEndpoint("", "", "Sts", endpoint);
	    IClientProfile profile = DefaultProfile.getProfile("", accessKeyId, accessKeySecret);
	    DefaultAcsClient client = new DefaultAcsClient(profile);
	    final AssumeRoleRequest request = new AssumeRoleRequest();
        request.setMethod(MethodType.POST);
        request.setRoleArn(roleArn);
        request.setRoleSessionName(roleSessionName);
        request.setPolicy(policy);
        request.setProtocol(protocolType);
        final AssumeRoleResponse response = client.getAcsResponse(request);
        System.out.println("=============" + response.getCredentials().getAccessKeyId());
        System.out.println("=============" + response.getCredentials().getAccessKeySecret());
        System.out.println("=============" + response.getCredentials().getSecurityToken());
    } catch (ClientException e) {
    	e.printStackTrace();
	}
}

问题:

  1. You should be authorized by RAM 是由于未给用户授权策略
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值