All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.opensearch.commons.authuser.AuthUserRequestBuilder Maven / Gradle / Ivy

There is a newer version: 2.17.0.0
Show newest version
/*
 * Copyright OpenSearch Contributors
 * SPDX-License-Identifier: Apache-2.0
 */

package org.opensearch.commons.authuser;

import org.opensearch.client.Request;
import org.opensearch.client.RequestOptions;
import org.opensearch.common.Strings;
import org.opensearch.commons.ConfigConstants;

public class AuthUserRequestBuilder {
    private final String auth;

    public AuthUserRequestBuilder(String auth) {
        if (Strings.isNullOrEmpty(auth)) {
            throw new IllegalArgumentException("Authorization token cannot be null");
        }
        this.auth = auth;
    }

    public Request build() {
        Request request = new Request("GET", "/_opendistro/_security/authinfo");
        request
            .setOptions(
                RequestOptions.DEFAULT
                    .toBuilder()
                    .addHeader(ConfigConstants.CONTENT_TYPE, ConfigConstants.CONTENT_TYPE_DEFAULT)
                    .addHeader(ConfigConstants.AUTHORIZATION, auth)
            );
        return request;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy