in aliyun-java-sdk-core/src/main/java/com/aliyuncs/RoaAcsRequest.java [161:218]
public HttpRequest signRequest(Signer signer, AlibabaCloudCredentials credentials, FormatType format,
ProductDomain domain) throws IllegalStateException,
UnsupportedEncodingException, NoSuchAlgorithmException {
this.resolveSignatureComposer();
Map<String, String> bodyParams = this.getSysBodyParameters();
String hashedRequestPayload = hexEncode(signer != null ? signer.hash("".getBytes("UTF-8")) : null);
if (bodyParams != null && !bodyParams.isEmpty()) {
byte[] data;
if (FormatType.JSON == this.getHttpContentType()) {
data = ParameterHelper.getJsonData(bodyParams);
} else if (FormatType.XML == this.getHttpContentType()) {
data = ParameterHelper.getXmlData(bodyParams);
} else {
// For contentType RAW and Form, the actual data format will be form
data = ParameterHelper.getFormData(bodyParams);
}
this.setHttpContent(data, "UTF-8", null);
hashedRequestPayload = hexEncode(signer != null ? signer.hash(data) : null);
}
Map<String, String> imutableMap = this.composer.refreshSignParameters(this.getSysHeaders(), signer, null,
format);
if (imutableMap.get("RegionId") == null) {
imutableMap.put("RegionId", getSysRegionId());
}
if (null != signer && null != credentials && !(credentials instanceof AnonymousCredentials)) {
String accessKeyId = credentials.getAccessKeyId();
if (credentials instanceof BasicSessionCredentials) {
String sessionToken = ((BasicSessionCredentials) credentials).getSessionToken();
if (null != sessionToken) {
imutableMap.put("x-acs-accesskey-id", accessKeyId);
imutableMap.put("x-acs-security-token", sessionToken);
}
}
if (credentials instanceof BearerTokenCredentials) {
String bearerToken = ((BearerTokenCredentials) credentials).getBearerToken();
if (null != ((BearerTokenCredentials) credentials).getBearerToken()) {
imutableMap.put("x-acs-bearer-token", bearerToken);
}
}
if (signer.getContent() != null && hashedRequestPayload != null) {
imutableMap.put(signer.getContent(), hashedRequestPayload);
}
String strToSign = this.composer.composeStringToSign(this.getSysMethod(), this.getSysUriPattern(), signer,
this.getSysQueryParameters(), imutableMap, this.getPathParameters());
if (this.getSysSignatureVersion() == SignatureVersion.V3) {
strToSign += "\n" + hashedRequestPayload;
strToSign = signer.getSignerName() + "\n" + hexEncode(signer.hash(strToSign.getBytes("UTF-8")));
}
this.strToSign = strToSign;
String signature = signer.signString(strToSign, credentials);
imutableMap.put("Authorization", this.composer.getAuthorization(signer, accessKeyId, signature)
+ (this.getSysSignatureVersion() == SignatureVersion.V3 ? ",SignedHeaders=" + this.getSysSignedHeaders(imutableMap) : ""));
}
this.setSysUrl(this.composeUrl(domain.getDomainName(), this.getSysQueryParameters()));
this.headers = imutableMap;
return this;
}