Search in sources :

Example 1 with Authentication

use of com.baeldung.petstore.client.invoker.auth.Authentication in project tutorials by eugenp.

the class ApiClient method init.

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("petstore_auth", new OAuth());
    // Prevent the authentications from being modified.
    authentications = Collections.unmodifiableMap(authentications);
}
Also used : Authentication(com.baeldung.petstore.client.invoker.auth.Authentication) ApiKeyAuth(com.baeldung.petstore.client.invoker.auth.ApiKeyAuth) OAuth(com.baeldung.petstore.client.invoker.auth.OAuth)

Example 2 with Authentication

use of com.baeldung.petstore.client.invoker.auth.Authentication in project tutorials by eugenp.

the class ApiClient method updateParamsForAuth.

/**
 * Update query and header parameters based on authentication settings.
 *
 * @param authNames The authentications to apply
 * @param queryParams The query parameters
 * @param headerParams The header parameters
 */
private void updateParamsForAuth(String[] authNames, MultiValueMap<String, String> queryParams, HttpHeaders headerParams) {
    for (String authName : authNames) {
        Authentication auth = authentications.get(authName);
        if (auth == null) {
            throw new RestClientException("Authentication undefined: " + authName);
        }
        auth.applyToParams(queryParams, headerParams);
    }
}
Also used : Authentication(com.baeldung.petstore.client.invoker.auth.Authentication) RestClientException(org.springframework.web.client.RestClientException)

Aggregations

Authentication (com.baeldung.petstore.client.invoker.auth.Authentication)2 ApiKeyAuth (com.baeldung.petstore.client.invoker.auth.ApiKeyAuth)1 OAuth (com.baeldung.petstore.client.invoker.auth.OAuth)1 RestClientException (org.springframework.web.client.RestClientException)1