]> git.basschouten.com Git - openhab-addons.git/blob
8c9c7b0690363d114b24e8579c7fe1507269779d
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2020 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.io.mqttembeddedbroker.internal;
14
15 import java.util.Arrays;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19
20 import io.moquette.broker.security.IAuthenticator;
21
22 /**
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.
25  *
26  * @author David Graeff - Initial contribution
27  */
28 @NonNullByDefault
29 public class MqttEmbeddedBrokerUserAuthenticator implements IAuthenticator {
30     final String username;
31     final byte[] password;
32
33     public MqttEmbeddedBrokerUserAuthenticator(String username, byte[] password) {
34         this.username = username;
35         this.password = password;
36     }
37
38     @Override
39     public boolean checkValid(@Nullable String clientId, @Nullable String username, byte @Nullable [] password) {
40         return this.username.equals(username) && Arrays.equals(this.password, password);
41     }
42 }