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

io.tarantool.driver.auth.SimpleTarantoolCredentials Maven / Gradle / Ivy

Go to download

Tarantool Cartridge driver for Tarantool versions 1.10+ based on Netty framework

There is a newer version: 0.14.0
Show newest version
package io.tarantool.driver.auth;

import io.tarantool.driver.utils.Assert;

/**
 * Container for plain user and password data for authentication
 *
 * @author Alexey Kuzin
 */
public class SimpleTarantoolCredentials implements TarantoolCredentials {

    private static final String DEFAULT_USER = "guest";
    private static final String DEFAULT_PASSWORD = "";

    private final String user;
    private final String password;

    /**
     * Basic constructor.
     *
     * @param user     non-empty username
     * @param password non-null password
     */
    public SimpleTarantoolCredentials(String user, String password) {
        Assert.notNull(user, "User must not be null");
        Assert.notNull(password, "Password must not be null");

        this.user = user;
        this.password = password;
    }

    /**
     * Simple constructor which uses the default guest credentials
     */
    public SimpleTarantoolCredentials() {
        this.user = DEFAULT_USER;
        this.password = DEFAULT_PASSWORD;
    }

    @Override
    public String getUsername() {
        return user;
    }

    public String getPassword() {
        return password;
    }

    public boolean isValid() {
        return !user.isEmpty();
    }

    public boolean isGuest() {
        return (user.isEmpty() || user.equals(DEFAULT_USER)) && password.isEmpty();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy