001/*
002 * Copyright (C) 2022-present The Prometheus jmx_exporter Authors
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package io.prometheus.jmx.common.http.authenticator;
018
019import java.util.Objects;
020
021/** Class to implement credentials */
022public class Credentials {
023
024    private final String username;
025    private final String password;
026
027    /**
028     * Constructor
029     *
030     * @param username username
031     * @param password password
032     */
033    public Credentials(String username, String password) {
034        this.username = username;
035        this.password = password;
036    }
037
038    /**
039     * Method to get the size (username length + password length) of the credentials
040     *
041     * @return the size of the credentials
042     */
043    public int size() {
044        return username.length() + password.length();
045    }
046
047    @Override
048    public String toString() {
049        return username + password;
050    }
051
052    @Override
053    public boolean equals(Object o) {
054        if (this == o) return true;
055        if (o == null || getClass() != o.getClass()) return false;
056        Credentials Credentials = (Credentials) o;
057        return Objects.equals(username, Credentials.username)
058                && Objects.equals(password, Credentials.password);
059    }
060
061    @Override
062    public int hashCode() {
063        return Objects.hash(username, password);
064    }
065}