@@ -26,17 +26,19 @@ public enum AwsCredentialsUtils {
2626    /** 
2727     * @return an authorization predicate that ensures the authorization header matches the given access key, region and service name. 
2828     * @see <a href="https://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-auth-using-authorization-header.html">AWS v4 Signatures</a> 
29+      * @param region the name of the AWS region used to sign the request, or {@code *} to skip validation of the region parameter 
2930     */ 
30-     public  static  BiPredicate <String , String > fixedAccessKey (String  accessKey , String  region , String  service ) {
31-         return  mutableAccessKey (() -> accessKey , region , service );
31+     public  static  BiPredicate <String , String > fixedAccessKey (String  accessKey , String  region , String  serviceName ) {
32+         return  mutableAccessKey (() -> accessKey , region , serviceName );
3233    }
3334
3435    /** 
3536     * @return an authorization predicate that ensures the authorization header matches the access key supplied by the given supplier, 
3637     *         and also matches the given region and service name. 
3738     * @see <a href="https://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-auth-using-authorization-header.html">AWS v4 Signatures</a> 
39+      * @param region the name of the AWS region used to sign the request, or {@code *} to skip validation of the region parameter 
3840     */ 
39-     public  static  BiPredicate <String , String > mutableAccessKey (Supplier <String > accessKeySupplier , String  region , String  service ) {
41+     public  static  BiPredicate <String , String > mutableAccessKey (Supplier <String > accessKeySupplier , String  region , String  serviceName ) {
4042        return  (authorizationHeader , sessionTokenHeader ) -> {
4143            if  (authorizationHeader  == null ) {
4244                return  false ;
@@ -50,21 +52,27 @@ public static BiPredicate<String, String> mutableAccessKey(Supplier<String> acce
5052
5153            if  (region .equals ("*" )) {
5254                // skip region validation; TODO eliminate this when region is fixed in all tests 
53-                 return  authorizationHeader .contains ("/"  + service  + "/aws4_request, " );
55+                 return  authorizationHeader .contains ("/"  + serviceName  + "/aws4_request, " );
5456            }
5557
56-             final  var  remainder  = authorizationHeader .substring (expectedPrefix .length () + 8  /* YYYYMMDD  not validated */ );
57-             return  remainder .startsWith ("/"  + region  + "/"  + service  + "/aws4_request, " );
58+             final  var  remainder  = authorizationHeader .substring (expectedPrefix .length () + "YYYYMMDD" . length ()  /* date  not validated */ );
59+             return  remainder .startsWith ("/"  + region  + "/"  + serviceName  + "/aws4_request, " );
5860        };
5961    }
6062
6163    /** 
6264     * @return an authorization predicate that ensures the access key, session token, region and service name all match the given values. 
6365     * @see <a href="https://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-auth-using-authorization-header.html">AWS v4 Signatures</a> 
66+      * @param region the name of the AWS region used to sign the request, or {@code *} to skip validation of the region parameter 
6467     */ 
65-     public  static  BiPredicate <String , String > fixedAccessKeyAndToken (String  accessKey , String  sessionToken , String  region , String  service ) {
68+     public  static  BiPredicate <String , String > fixedAccessKeyAndToken (
69+         String  accessKey ,
70+         String  sessionToken ,
71+         String  region ,
72+         String  serviceName 
73+     ) {
6674        Objects .requireNonNull (sessionToken );
67-         final  var  accessKeyPredicate  = fixedAccessKey (accessKey , region , service );
75+         final  var  accessKeyPredicate  = fixedAccessKey (accessKey , region , serviceName );
6876        return  (authorizationHeader , sessionTokenHeader ) -> accessKeyPredicate .test (authorizationHeader , sessionTokenHeader )
6977            && sessionToken .equals (sessionTokenHeader );
7078    }
0 commit comments