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

org.opensearch.identity.NamedPrincipal Maven / Gradle / Ivy

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

package org.opensearch.identity;

import java.security.Principal;
import java.util.Objects;

/**
 * Create a principal from a string
 *
 * @opensearch.experimental
 */
public class NamedPrincipal implements Principal {

    /**
     * Represents a principal which has not been authenticated
     */
    public static final NamedPrincipal UNAUTHENTICATED = new NamedPrincipal("Unauthenticated");

    private final String name;

    /**
     * Creates a principal for an identity specified as a string
     * @param name A persistent string that represent an identity
     */
    public NamedPrincipal(final String name) {
        this.name = name;
    }

    @Override
    public String getName() {
        return name;
    }

    @Override
    public boolean equals(final Object obj) {
        if (this == obj) return true;
        if (obj == null || getClass() != obj.getClass()) return false;
        final Principal that = (Principal) obj;
        return Objects.equals(name, that.getName());
    }

    @Override
    public int hashCode() {
        return Objects.hash(name);
    }

    @Override
    public String toString() {
        return "NamedPrincipal(" + "name=" + name + ")";
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy