org.elasticsearch.client.security.HasPrivilegesRequest Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of elasticsearch-rest-high-level-client Show documentation
Show all versions of elasticsearch-rest-high-level-client Show documentation
Elasticsearch subproject :client:rest-high-level
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
package org.elasticsearch.client.security;
import org.elasticsearch.client.Validatable;
import org.elasticsearch.client.security.user.privileges.ApplicationResourcePrivileges;
import org.elasticsearch.client.security.user.privileges.IndicesPrivileges;
import org.elasticsearch.core.Nullable;
import org.elasticsearch.xcontent.ToXContentObject;
import org.elasticsearch.xcontent.XContentBuilder;
import java.io.IOException;
import java.util.Objects;
import java.util.Set;
import static java.util.Collections.emptySet;
import static java.util.Collections.unmodifiableSet;
/**
* Request to determine whether the current user has a list of privileges.
*/
public final class HasPrivilegesRequest implements Validatable, ToXContentObject {
private final Set clusterPrivileges;
private final Set indexPrivileges;
private final Set applicationPrivileges;
public HasPrivilegesRequest(
@Nullable Set clusterPrivileges,
@Nullable Set indexPrivileges,
@Nullable Set applicationPrivileges
) {
this.clusterPrivileges = clusterPrivileges == null ? emptySet() : unmodifiableSet(clusterPrivileges);
this.indexPrivileges = indexPrivileges == null ? emptySet() : unmodifiableSet(indexPrivileges);
this.applicationPrivileges = applicationPrivileges == null ? emptySet() : unmodifiableSet(applicationPrivileges);
if (this.clusterPrivileges.isEmpty() && this.indexPrivileges.isEmpty() && this.applicationPrivileges.isEmpty()) {
throw new IllegalArgumentException("At last 1 privilege must be specified");
}
}
public Set getClusterPrivileges() {
return clusterPrivileges;
}
public Set getIndexPrivileges() {
return indexPrivileges;
}
public Set getApplicationPrivileges() {
return applicationPrivileges;
}
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
return builder.startObject()
.field("cluster", clusterPrivileges)
.field("index", indexPrivileges)
.field("application", applicationPrivileges)
.endObject();
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
final HasPrivilegesRequest that = (HasPrivilegesRequest) o;
return Objects.equals(clusterPrivileges, that.clusterPrivileges)
&& Objects.equals(indexPrivileges, that.indexPrivileges)
&& Objects.equals(applicationPrivileges, that.applicationPrivileges);
}
@Override
public int hashCode() {
return Objects.hash(clusterPrivileges, indexPrivileges, applicationPrivileges);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy