@@ -172,51 +172,58 @@ public HttpRequest signRequest(Signer signer, AlibabaCloudCredentials credential
172
172
}
173
173
}
174
174
if (null != signer && null != credentials && !(credentials instanceof AnonymousCredentials )) {
175
- String accessKeyId = credentials .getAccessKeyId ();
176
- String accessSecret = credentials .getAccessKeySecret ();
177
- if (credentials instanceof BasicSessionCredentials ) {
178
- String sessionToken = ((BasicSessionCredentials ) credentials ).getSessionToken ();
179
- if (null != sessionToken ) {
180
- imutableMap .put ("SecurityToken" , sessionToken );
181
- headerMap .put ("x-acs-security-token" , sessionToken );
182
- }
183
- }
184
175
if (credentials instanceof BearerTokenCredentials ) {
185
176
String bearerToken = ((BearerTokenCredentials ) credentials ).getBearerToken ();
186
- if (null != (( BearerTokenCredentials ) credentials ). getBearerToken () ) {
177
+ if (null != bearerToken ) {
187
178
imutableMap .put ("BearerToken" , bearerToken );
179
+ imutableMap .put ("SignatureType" , "BEARERTOKEN" );
188
180
headerMap .put ("x-acs-bearer-token" , bearerToken );
189
181
}
190
- }
191
- if (signer .getContent () != null && hashedRequestPayload != null ) {
192
- headerMap .put (signer .getContent (), hashedRequestPayload );
193
- }
194
- imutableMap .put ("AccessKeyId" , accessKeyId );
195
- if (this .getSysSignatureVersion () == SignatureVersion .V3 ) {
196
- String strToSign = this .composer .composeStringToSign (this .getSysMethod (), null , signer ,
197
- this .getSysQueryParameters (), headerMap , null ) + "\n " + hashedRequestPayload ;
198
- this .strToSign = strToSign ;
199
- strToSign = signer .getSignerName () + "\n " + hexEncode (signer .hash (strToSign .getBytes ("UTF-8" )));
200
- String signature = signer .signString (strToSign , accessSecret );
201
- headerMap .put ("Authorization" , this .composer .getAuthorization (signer , accessKeyId , signature )
202
- + ",SignedHeaders=" + this .getSysSignedHeaders (headerMap ));
203
- imutableMap = this .getSysQueryParameters ();
182
+ } else if (credentials instanceof IDTokenCredentials ) {
183
+ String idToken = ((IDTokenCredentials ) credentials ).getIDToken ();
184
+ if (null != idToken ) {
185
+ headerMap .put ("x-acs-zero-trust-idtoken" , idToken );
186
+ }
204
187
} else {
205
- Map <String , String > paramsToSign = new HashMap <String , String >();
206
- paramsToSign .putAll (bodyParams );
207
- paramsToSign .putAll (imutableMap );
208
- String strToSign = this .composer .composeStringToSign (
209
- this .getSysMethod (), null , signer , paramsToSign , null , null );
210
- this .strToSign = strToSign ;
211
- String signature ;
212
- if (credentials instanceof KeyPairCredentials ) {
213
- signature = signer .signString (strToSign , credentials );
188
+ String accessKeyId = credentials .getAccessKeyId ();
189
+ String accessSecret = credentials .getAccessKeySecret ();
190
+ if (credentials instanceof BasicSessionCredentials ) {
191
+ String sessionToken = ((BasicSessionCredentials ) credentials ).getSessionToken ();
192
+ if (null != sessionToken ) {
193
+ imutableMap .put ("SecurityToken" , sessionToken );
194
+ headerMap .put ("x-acs-security-token" , sessionToken );
195
+ }
196
+ }
197
+ if (signer .getContent () != null && hashedRequestPayload != null ) {
198
+ headerMap .put (signer .getContent (), hashedRequestPayload );
199
+ }
200
+ imutableMap .put ("AccessKeyId" , accessKeyId );
201
+ if (this .getSysSignatureVersion () == SignatureVersion .V3 ) {
202
+ String strToSign = this .composer .composeStringToSign (this .getSysMethod (), null , signer ,
203
+ this .getSysQueryParameters (), headerMap , null ) + "\n " + hashedRequestPayload ;
204
+ this .strToSign = strToSign ;
205
+ strToSign = signer .getSignerName () + "\n " + hexEncode (signer .hash (strToSign .getBytes ("UTF-8" )));
206
+ String signature = signer .signString (strToSign , accessSecret );
207
+ headerMap .put ("Authorization" , this .composer .getAuthorization (signer , accessKeyId , signature )
208
+ + ",SignedHeaders=" + this .getSysSignedHeaders (headerMap ));
209
+ imutableMap = this .getSysQueryParameters ();
214
210
} else {
215
- signature = signer .signString (strToSign , accessSecret + "&" );
211
+ Map <String , String > paramsToSign = new HashMap <String , String >();
212
+ paramsToSign .putAll (bodyParams );
213
+ paramsToSign .putAll (imutableMap );
214
+ String strToSign = this .composer .composeStringToSign (
215
+ this .getSysMethod (), null , signer , paramsToSign , null , null );
216
+ this .strToSign = strToSign ;
217
+ String signature ;
218
+ if (credentials instanceof KeyPairCredentials ) {
219
+ signature = signer .signString (strToSign , credentials );
220
+ } else {
221
+ signature = signer .signString (strToSign , accessSecret + "&" );
222
+ }
223
+ imutableMap .put ("Signature" , this .composer .getAuthorization (signer , accessKeyId , signature ));
224
+ headerMap .clear ();
225
+ headerMap .putAll (this .getSysHeaders ());
216
226
}
217
- imutableMap .put ("Signature" , this .composer .getAuthorization (signer , accessKeyId , signature ));
218
- headerMap .clear ();
219
- headerMap .putAll (this .getSysHeaders ());
220
227
}
221
228
}
222
229
this .setSysUrl (this .composeUrl (domain .getDomainName (), imutableMap ));
0 commit comments