public String getV4Authorization ( String accessKey , String secretKey , String action , String url , String serviceId , Map < String , String > headers , String bodyHash ) throws InternalException { serviceId = serviceId . toLowerCase ( ) ; String regionId = "us-east-1" ; // default for IAM // if( ctx != null && ctx.getRegionId() != null && !ctx.getRegionId().isEmpty() && // !serviceId.equalsIgnoreCase(IAMMethod.SERVICE_ID) ) { // regionId = getContext().getRegionId(); // } else { String host = url . replaceAll ( "https?:\\/\\/" , "" ) ; if ( host . indexOf ( ' ' ) > 0 ) { host = host . substring ( 0 , host . indexOf ( ' ' , 1 ) ) ; } if ( ! IAMMethod . SERVICE_ID . equalsIgnoreCase ( serviceId ) ) { String [ ] urlParts = host . split ( "\\." ) ; // everywhere except s3 and iam this is: service.region.amazonaws.com or service.region.amazonaws.com.cn if ( urlParts . length > 2 ) { regionId = urlParts [ 1 ] ; if ( regionId . startsWith ( "s3-" ) ) { regionId = regionId . substring ( 3 ) ; } } } String amzDate = extractV4Date ( headers ) ; String credentialScope = getV4CredentialScope ( amzDate , regionId , serviceId ) ; String signedHeaders = getV4SignedHeaders ( headers ) ; String signature = signV4 ( secretKey , action , url , regionId , serviceId , headers , bodyHash ) ; return V4_ALGORITHM + " " + "Credential=" + accessKey + "/" + credentialScope + ", " + "SignedHeaders=" + signedHeaders + ", " + "Signature=" + signature ; }
Generates an AWS v4 signature authorization string