code: protected AWSCredentials sanitizeCredentials(AWSCredentials credentials) {
          String accessKeyId = null;
          String secretKey   = null;
          String token = null;
          synchronized (credentials) {
              accessKeyId = credentials.getAWSAccessKeyId();
              secretKey   = credentials.getAWSSecretKey();
              if ( credentials instanceof AWSSessionCredentials ) {
                  token = ((AWSSessionCredentials) credentials).getSessionToken();
              }
          }
          if (secretKey != null) secretKey = secretKey.trim();
          if (accessKeyId != null) accessKeyId = accessKeyId.trim();
          if (token != null) token = token.trim();
  
          if (credentials instanceof AWSSessionCredentials) {
              return new BasicSessionCredentials(accessKeyId, secretKey, token);
          }
  
          return new BasicAWSCredentials(accessKeyId, secretKey);
      }
docs: Loads the individual access key ID and secret key from the specified
  credentials, ensuring that access to the credentials is synchronized on
  the credentials object itself, and trimming any extra whitespace from the
  credentials.
  <p>
  Returns either a {@link BasicSessionCredentials} or a
  {@link BasicAWSCredentials} object, depending on the input type.
  
  @param credentials
  @return A new credentials object with the sanitized credentials.