Search in sources :

Example 1 with GetFederationTokenRequest

use of com.tencentcloudapi.sts.v20180813.models.GetFederationTokenRequest in project cloud-sdk by mizhousoft.

the class TencentOCRServiceImpl method getTempCredential.

/**
 * {@inheritDoc}
 */
@Override
public TempCredential getTempCredential(long durationSecond) throws CloudSDKException {
    GetFederationTokenRequest request = new GetFederationTokenRequest();
    request.setName("ocr");
    request.setDurationSeconds(durationSecond);
    request.setPolicy("{\"version\": \"2.0\", \"statement\": [{\"action\": [\"ocr:*\"], \"resource\": \"*\", \"effect\": \"allow\"}]}");
    try {
        GetFederationTokenResponse response = cosClient.GetFederationToken(request);
        Credentials credential = response.getCredentials();
        TempCredential tempCredential = new TempCredential();
        tempCredential.setSecretId(credential.getTmpSecretId());
        tempCredential.setSecretKey(credential.getTmpSecretKey());
        tempCredential.setToken(credential.getToken());
        tempCredential.setExpiredTime(response.getExpiredTime());
        return tempCredential;
    } catch (TencentCloudSDKException e) {
        throw new CloudSDKException(e.getMessage(), e);
    }
}
Also used : TencentCloudSDKException(com.tencentcloudapi.common.exception.TencentCloudSDKException) CloudSDKException(com.mizhousoft.cloudsdk.CloudSDKException) TencentCloudSDKException(com.tencentcloudapi.common.exception.TencentCloudSDKException) TempCredential(com.mizhousoft.cloudsdk.TempCredential) GetFederationTokenResponse(com.tencentcloudapi.sts.v20180813.models.GetFederationTokenResponse) GetFederationTokenRequest(com.tencentcloudapi.sts.v20180813.models.GetFederationTokenRequest) Credentials(com.tencentcloudapi.sts.v20180813.models.Credentials)

Aggregations

CloudSDKException (com.mizhousoft.cloudsdk.CloudSDKException)1 TempCredential (com.mizhousoft.cloudsdk.TempCredential)1 TencentCloudSDKException (com.tencentcloudapi.common.exception.TencentCloudSDKException)1 Credentials (com.tencentcloudapi.sts.v20180813.models.Credentials)1 GetFederationTokenRequest (com.tencentcloudapi.sts.v20180813.models.GetFederationTokenRequest)1 GetFederationTokenResponse (com.tencentcloudapi.sts.v20180813.models.GetFederationTokenResponse)1