2 * Copyright (c) 2010-2020 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.io.mqttembeddedbroker.internal;
15 import java.util.Arrays;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
20 import io.moquette.broker.security.IAuthenticator;
23 * Provides a {@link IAuthenticator} for the Moquette server, that accepts given user name and password.
24 * If ESH gains user credentials at some point, those should be accepted as well.
26 * @author David Graeff - Initial contribution
29 public class MqttEmbeddedBrokerUserAuthenticator implements IAuthenticator {
30 final String username;
31 final byte[] password;
33 public MqttEmbeddedBrokerUserAuthenticator(String username, byte[] password) {
34 this.username = username;
35 this.password = password;
39 public boolean checkValid(@Nullable String clientId, @Nullable String username, byte @Nullable [] password) {
40 return this.username.equals(username) && Arrays.equals(this.password, password);