org.openapitools.client.auth.HttpBasicAuth Java Examples

The following examples show how to use org.openapitools.client.auth.HttpBasicAuth. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ApiClient.java    From openapi-generator with Apache License 2.0 7 votes vote down vote up
protected void init() {
    // Use RFC3339 format for date and datetime.
    // See http://xml2rfc.ietf.org/public/rfc/html/rfc3339.html#anchor14
    this.dateFormat = new RFC3339DateFormat();

    // Use UTC as the default time zone.
    this.dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));

    // Set default User-Agent.
    setUserAgent("Java-SDK");

    // Setup authentications (key: authentication name, value: authentication).
    authentications = new HashMap<String, Authentication>();
    authentications.put("api_key", new ApiKeyAuth("header", "api_key"));
    authentications.put("api_key_query", new ApiKeyAuth("query", "api_key_query"));
    authentications.put("http_basic_test", new HttpBasicAuth());
    authentications.put("petstore_auth", new OAuth());
    // Prevent the authentications from being modified.
    authentications = Collections.unmodifiableMap(authentications);
}
 
Example #2
Source File: ApiClient.java    From openapi-generator with Apache License 2.0 6 votes vote down vote up
protected void init() {
    // Use RFC3339 format for date and datetime.
    // See http://xml2rfc.ietf.org/public/rfc/html/rfc3339.html#anchor14
    this.dateFormat = new RFC3339DateFormat();

    // Use UTC as the default time zone.
    this.dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));

    // Set default User-Agent.
    setUserAgent("Java-SDK");

    // Setup authentications (key: authentication name, value: authentication).
    authentications = new HashMap<String, Authentication>();
    authentications.put("api_key", new ApiKeyAuth("header", "api_key"));
    authentications.put("api_key_query", new ApiKeyAuth("query", "api_key_query"));
    authentications.put("http_basic_test", new HttpBasicAuth());
    authentications.put("petstore_auth", new OAuth());
    // Prevent the authentications from being modified.
    authentications = Collections.unmodifiableMap(authentications);
}
 
Example #3
Source File: ApiClient.java    From openapi-generator with Apache License 2.0 6 votes vote down vote up
/**
 * Helper method to configure the username/password for basic auth or password oauth
 * @param username Username
 * @param password Password
 * @return ApiClient
 */
public ApiClient setCredentials(String username, String password) {
  for(Interceptor apiAuthorization : apiAuthorizations.values()) {
    if (apiAuthorization instanceof HttpBasicAuth) {
      HttpBasicAuth basicAuth = (HttpBasicAuth) apiAuthorization;
      basicAuth.setCredentials(username, password);
      return this;
    }
    if (apiAuthorization instanceof OAuth) {
      OAuth oauth = (OAuth) apiAuthorization;
      oauth.getTokenRequestBuilder().setUsername(username).setPassword(password);
      return this;
    }
  }
  return this;
}
 
Example #4
Source File: ApiClient.java    From openapi-generator with Apache License 2.0 6 votes vote down vote up
public ApiClient() {
  json = new JSON();
  httpClient = buildHttpClient(debugging);

  this.dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX", Locale.ROOT);

  // Use UTC as the default time zone.
  this.dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));

  this.json.setDateFormat((DateFormat) dateFormat.clone());

  // Set default User-Agent.
  setUserAgent("OpenAPI-Generator/1.0.0/java");

  // Setup authentications (key: authentication name, value: authentication).
  authentications = new HashMap<String, Authentication>();
  authentications.put("api_key", new ApiKeyAuth("header", "api_key"));
  authentications.put("api_key_query", new ApiKeyAuth("query", "api_key_query"));
  authentications.put("http_basic_test", new HttpBasicAuth());
  authentications.put("petstore_auth", new OAuth());
  // Prevent the authentications from being modified.
  authentications = Collections.unmodifiableMap(authentications);
}
 
Example #5
Source File: ApiClient.java    From openapi-generator with Apache License 2.0 6 votes vote down vote up
/**
 * Helper method to configure the username/password for basic auth or password oauth
 * @param username Username
 * @param password Password
 * @return ApiClient
 */
public ApiClient setCredentials(String username, String password) {
  for(Interceptor apiAuthorization : apiAuthorizations.values()) {
    if (apiAuthorization instanceof HttpBasicAuth) {
      HttpBasicAuth basicAuth = (HttpBasicAuth) apiAuthorization;
      basicAuth.setCredentials(username, password);
      return this;
    }
    if (apiAuthorization instanceof OAuth) {
      OAuth oauth = (OAuth) apiAuthorization;
      oauth.getTokenRequestBuilder().setUsername(username).setPassword(password);
      return this;
    }
  }
  return this;
}
 
Example #6
Source File: ApiClient.java    From openapi-generator with Apache License 2.0 6 votes vote down vote up
/**
 * Helper method to configure the username/password for basic auth or password oauth
 * @param username Username
 * @param password Password
 * @return ApiClient
 */
public ApiClient setCredentials(String username, String password) {
  for(Interceptor apiAuthorization : apiAuthorizations.values()) {
    if (apiAuthorization instanceof HttpBasicAuth) {
      HttpBasicAuth basicAuth = (HttpBasicAuth) apiAuthorization;
      basicAuth.setCredentials(username, password);
      return this;
    }
    if (apiAuthorization instanceof OAuth) {
      OAuth oauth = (OAuth) apiAuthorization;
      oauth.getTokenRequestBuilder().setUsername(username).setPassword(password);
      return this;
    }
  }
  return this;
}
 
Example #7
Source File: ApiClient.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method to set username for the first HTTP basic authentication.
 * @param username Username
 */
public void setUsername(String username) {
  for (Authentication auth : authentications.values()) {
    if (auth instanceof HttpBasicAuth) {
      ((HttpBasicAuth) auth).setUsername(username);
      return;
    }
  }
  throw new RuntimeException("No HTTP basic authentication configured!");
}
 
Example #8
Source File: ApiClient.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method to set username for the first HTTP basic authentication.
 * @param username Username
 */
public void setUsername(String username) {
  for (Authentication auth : authentications.values()) {
    if (auth instanceof HttpBasicAuth) {
      ((HttpBasicAuth) auth).setUsername(username);
      return;
    }
  }
  throw new RuntimeException("No HTTP basic authentication configured!");
}
 
Example #9
Source File: ApiClient.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method to set password for the first HTTP basic authentication.
 * @param password Password
 */
public void setPassword(String password) {
  for (Authentication auth : authentications.values()) {
    if (auth instanceof HttpBasicAuth) {
      ((HttpBasicAuth) auth).setPassword(password);
      return;
    }
  }
  throw new RuntimeException("No HTTP basic authentication configured!");
}
 
Example #10
Source File: ApiClient.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
public ApiClient() {
    init();
    initHttpClient();

    // Setup authentications (key: authentication name, value: authentication).
    authentications.put("api_key", new ApiKeyAuth("header", "api_key"));
    authentications.put("api_key_query", new ApiKeyAuth("query", "api_key_query"));
    authentications.put("http_basic_test", new HttpBasicAuth());
    authentications.put("petstore_auth", new OAuth());
    // Prevent the authentications from being modified.
    authentications = Collections.unmodifiableMap(authentications);
}
 
Example #11
Source File: ApiClient.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
public ApiClient(OkHttpClient client) {
    init();

    httpClient = client;

    // Setup authentications (key: authentication name, value: authentication).
    authentications.put("api_key", new ApiKeyAuth("header", "api_key"));
    authentications.put("api_key_query", new ApiKeyAuth("query", "api_key_query"));
    authentications.put("http_basic_test", new HttpBasicAuth());
    authentications.put("petstore_auth", new OAuth());
    // Prevent the authentications from being modified.
    authentications = Collections.unmodifiableMap(authentications);
}
 
Example #12
Source File: ApiClient.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
public ApiClient(String basePath, String clientId, String clientSecret, Map<String, String> parameters) {
    init();
    if (basePath != null) {
        this.basePath = basePath;
    }

    String tokenUrl = "";
    if (!"".equals(tokenUrl) && !URI.create(tokenUrl).isAbsolute()) {
        URI uri = URI.create(getBasePath());
        tokenUrl = uri.getScheme() + ":" +
            (uri.getAuthority() != null ? "//" + uri.getAuthority() : "") +
            tokenUrl;
        if (!URI.create(tokenUrl).isAbsolute()) {
            throw new IllegalArgumentException("OAuth2 token URL must be an absolute URL");
        }
    }
    RetryingOAuth retryingOAuth = new RetryingOAuth(tokenUrl, clientId, OAuthFlow.implicit, clientSecret, parameters);
    authentications.put(
            "petstore_auth",
            retryingOAuth
    );
    initHttpClient(Collections.<Interceptor>singletonList(retryingOAuth));
    // Setup authentications (key: authentication name, value: authentication).
    authentications.put("api_key", new ApiKeyAuth("header", "api_key"));
    authentications.put("api_key_query", new ApiKeyAuth("query", "api_key_query"));
    authentications.put("http_basic_test", new HttpBasicAuth());

    // Prevent the authentications from being modified.
    authentications = Collections.unmodifiableMap(authentications);
}
 
Example #13
Source File: ApiClient.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method to set username for the first HTTP basic authentication.
 *
 * @param username Username
 */
public void setUsername(String username) {
    for (Authentication auth : authentications.values()) {
        if (auth instanceof HttpBasicAuth) {
            ((HttpBasicAuth) auth).setUsername(username);
            return;
        }
    }
    throw new RuntimeException("No HTTP basic authentication configured!");
}
 
Example #14
Source File: ApiClient.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method to set password for the first HTTP basic authentication.
 *
 * @param password Password
 */
public void setPassword(String password) {
    for (Authentication auth : authentications.values()) {
        if (auth instanceof HttpBasicAuth) {
            ((HttpBasicAuth) auth).setPassword(password);
            return;
        }
    }
    throw new RuntimeException("No HTTP basic authentication configured!");
}
 
Example #15
Source File: ApiClient.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
public ApiClient() {
  objectMapper = new ObjectMapper();
  objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
  objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
  objectMapper.configure(DeserializationFeature.FAIL_ON_INVALID_SUBTYPE, false);
  objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
  objectMapper.enable(SerializationFeature.WRITE_ENUMS_USING_TO_STRING);
  objectMapper.enable(DeserializationFeature.READ_ENUMS_USING_TO_STRING);
  ThreeTenModule module = new ThreeTenModule();
  module.addDeserializer(Instant.class, CustomInstantDeserializer.INSTANT);
  module.addDeserializer(OffsetDateTime.class, CustomInstantDeserializer.OFFSET_DATE_TIME);
  module.addDeserializer(ZonedDateTime.class, CustomInstantDeserializer.ZONED_DATE_TIME);
  objectMapper.registerModule(module);
  objectMapper.setDateFormat(ApiClient.buildDefaultDateFormat());

  dateFormat = ApiClient.buildDefaultDateFormat();

  // Set default User-Agent.
  setUserAgent("OpenAPI-Generator/1.0.0/java");

  // Setup authentications (key: authentication name, value: authentication).
  authentications = new HashMap<String, Authentication>();
  authentications.put("api_key", new ApiKeyAuth("header", "api_key"));
  authentications.put("api_key_query", new ApiKeyAuth("query", "api_key_query"));
  authentications.put("http_basic_test", new HttpBasicAuth());
  authentications.put("petstore_auth", new OAuth());
  // Prevent the authentications from being modified.
  authentications = Collections.unmodifiableMap(authentications);

  rebuildHttpClient();
}
 
Example #16
Source File: ApiClient.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method to set username for the first HTTP basic authentication.
 * @param username Username
 */
public void setUsername(String username) {
  for (Authentication auth : authentications.values()) {
    if (auth instanceof HttpBasicAuth) {
      ((HttpBasicAuth) auth).setUsername(username);
      return;
    }
  }
  throw new RuntimeException("No HTTP basic authentication configured!");
}
 
Example #17
Source File: ApiClient.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method to set password for the first HTTP basic authentication.
 * @param password Password
 */
public void setPassword(String password) {
  for (Authentication auth : authentications.values()) {
    if (auth instanceof HttpBasicAuth) {
      ((HttpBasicAuth) auth).setPassword(password);
      return;
    }
  }
  throw new RuntimeException("No HTTP basic authentication configured!");
}
 
Example #18
Source File: ApiInvoker.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method to set username for the first HTTP basic authentication.
 */
public void setUsername(String username) {
  for (Authentication auth : authentications.values()) {
     if (auth instanceof HttpBasicAuth) {
         ((HttpBasicAuth) auth).setUsername(username);
         return;
     }
  }
  throw new RuntimeException("No HTTP basic authentication configured!");
}
 
Example #19
Source File: ApiInvoker.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method to set password for the first HTTP basic authentication.
 */
public void setPassword(String password) {
  for (Authentication auth : authentications.values()) {
     if (auth instanceof HttpBasicAuth) {
        ((HttpBasicAuth) auth).setPassword(password);
        return;
     }
  }
  throw new RuntimeException("No HTTP basic authentication configured!");
}
 
Example #20
Source File: ApiInvoker.java    From swaggy-jenkins with MIT License 5 votes vote down vote up
public static void initializeInstance(Cache cache, Network network, int threadPoolSize, ResponseDelivery delivery, int connectionTimeout) {
  INSTANCE = new ApiInvoker(cache, network, threadPoolSize, delivery, connectionTimeout);
  setUserAgent("OpenAPI-Generator/1.0.0/android");

  // Setup authentications (key: authentication name, value: authentication).
  INSTANCE.authentications = new HashMap<String, Authentication>();
  INSTANCE.authentications.put("jenkins_auth", new HttpBasicAuth());
  INSTANCE.authentications.put("jwt_auth", new ApiKeyAuth("header", "Authorization"));
  // Prevent the authentications from being modified.
  INSTANCE.authentications = Collections.unmodifiableMap(INSTANCE.authentications);
}
 
Example #21
Source File: ApiInvoker.java    From swaggy-jenkins with MIT License 5 votes vote down vote up
/**
 * Helper method to set username for the first HTTP basic authentication.
 */
public void setUsername(String username) {
  for (Authentication auth : authentications.values()) {
     if (auth instanceof HttpBasicAuth) {
         ((HttpBasicAuth) auth).setUsername(username);
         return;
     }
  }
  throw new RuntimeException("No HTTP basic authentication configured!");
}
 
Example #22
Source File: ApiInvoker.java    From swaggy-jenkins with MIT License 5 votes vote down vote up
/**
 * Helper method to set password for the first HTTP basic authentication.
 */
public void setPassword(String password) {
  for (Authentication auth : authentications.values()) {
     if (auth instanceof HttpBasicAuth) {
        ((HttpBasicAuth) auth).setPassword(password);
        return;
     }
  }
  throw new RuntimeException("No HTTP basic authentication configured!");
}
 
Example #23
Source File: ApiInvoker.java    From swagger-aem with Apache License 2.0 5 votes vote down vote up
public static void initializeInstance(Cache cache, Network network, int threadPoolSize, ResponseDelivery delivery, int connectionTimeout) {
  INSTANCE = new ApiInvoker(cache, network, threadPoolSize, delivery, connectionTimeout);
  setUserAgent("OpenAPI-Generator/1.0.0/android");

  // Setup authentications (key: authentication name, value: authentication).
  INSTANCE.authentications = new HashMap<String, Authentication>();
  INSTANCE.authentications.put("aemAuth", new HttpBasicAuth());
  // Prevent the authentications from being modified.
  INSTANCE.authentications = Collections.unmodifiableMap(INSTANCE.authentications);
}
 
Example #24
Source File: ApiInvoker.java    From swagger-aem with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method to set username for the first HTTP basic authentication.
 */
public void setUsername(String username) {
  for (Authentication auth : authentications.values()) {
     if (auth instanceof HttpBasicAuth) {
         ((HttpBasicAuth) auth).setUsername(username);
         return;
     }
  }
  throw new RuntimeException("No HTTP basic authentication configured!");
}
 
Example #25
Source File: ApiInvoker.java    From swagger-aem with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method to set password for the first HTTP basic authentication.
 */
public void setPassword(String password) {
  for (Authentication auth : authentications.values()) {
     if (auth instanceof HttpBasicAuth) {
        ((HttpBasicAuth) auth).setPassword(password);
        return;
     }
  }
  throw new RuntimeException("No HTTP basic authentication configured!");
}
 
Example #26
Source File: ApiClient.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method to set password for the first HTTP basic authentication.
 *
 * @param password Password
 */
public ApiClient setPassword(String password) {
    for (Authentication auth : authentications.values()) {
        if (auth instanceof HttpBasicAuth) {
            ((HttpBasicAuth) auth).setPassword(password);
            return this;
        }
    }
    throw new RuntimeException("No HTTP basic authentication configured!");
}
 
Example #27
Source File: ApiClient.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method to set username for the first HTTP basic authentication.
 *
 * @param username Username
 */
public ApiClient setUsername(String username) {
  for (Authentication auth : authentications.values()) {
    if (auth instanceof HttpBasicAuth) {
      ((HttpBasicAuth) auth).setUsername(username);
      return this;
    }
  }
  throw new RuntimeException("No HTTP basic authentication configured!");
}
 
Example #28
Source File: ApiClient.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method to set password for the first HTTP basic authentication.
 *
 * @param password Password
 */
public ApiClient setPassword(String password) {
  for (Authentication auth : authentications.values()) {
    if (auth instanceof HttpBasicAuth) {
      ((HttpBasicAuth) auth).setPassword(password);
      return this;
    }
  }
  throw new RuntimeException("No HTTP basic authentication configured!");
}
 
Example #29
Source File: ApiClient.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method to set username for the first HTTP basic authentication.
 * @param username the username
 */
public void setUsername(String username) {
  for (Authentication auth : authentications.values()) {
    if (auth instanceof HttpBasicAuth) {
      ((HttpBasicAuth) auth).setUsername(username);
      return;
    }
  }
  throw new RuntimeException("No HTTP basic authentication configured!");
}
 
Example #30
Source File: ApiClient.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method to set password for the first HTTP basic authentication.
 * @param password the password
 */
public void setPassword(String password) {
  for (Authentication auth : authentications.values()) {
    if (auth instanceof HttpBasicAuth) {
      ((HttpBasicAuth) auth).setPassword(password);
      return;
    }
  }
  throw new RuntimeException("No HTTP basic authentication configured!");
}