001/*
002 * Copyright (c) 2023. Baidu, Inc. All Rights Reserved.
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 *    http://www.apache.org/licenses/LICENSE-2.0
008 * Unless required by applicable law or agreed to in writing,
009 * software distributed under the License is distributed on an "AS IS" BASIS,
010 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
011 * See the License for the specific language governing permissions and limitations under the License.
012 */
013
014package com.baidu.bifromq.plugin.authprovider;
015
016import com.baidu.bifromq.plugin.authprovider.type.MQTT3AuthData;
017import com.baidu.bifromq.plugin.authprovider.type.MQTT3AuthResult;
018import com.baidu.bifromq.plugin.authprovider.type.MQTTAction;
019import com.baidu.bifromq.type.ClientInfo;
020import java.util.concurrent.CompletableFuture;
021import org.pf4j.ExtensionPoint;
022
023public interface IAuthProvider extends ExtensionPoint {
024    /**
025     * Implement this method to hook authentication logic of mqtt3 client into BifroMQ.
026     *
027     * @param authData the authentication data
028     */
029    CompletableFuture<MQTT3AuthResult> auth(MQTT3AuthData authData);
030
031    /**
032     * Implement this method to hook action permission check logic.
033     *
034     * @param client the client to check permission
035     * @param action the action
036     */
037    CompletableFuture<Boolean> check(ClientInfo client, MQTTAction action);
038
039    /**
040     * This method will be called during broker shutdown
041     */
042    default void close() {
043    }
044}