File indexing completed on 2024-05-05 05:30:28
0001 /* 0002 SPDX-FileCopyrightText: 2023 Janet Blackquill <uhhadd@gmail.com> 0003 0004 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0005 */ 0006 0007 #pragma once 0008 0009 #include "pamauthenticator.h" 0010 #include <QObject> 0011 #include <memory> 0012 0013 class PamAuthenticators : public QObject 0014 { 0015 Q_OBJECT 0016 0017 // these properties delegate to the interactive authenticator 0018 Q_PROPERTY(bool busy READ isBusy NOTIFY busyChanged) 0019 0020 Q_PROPERTY(QString prompt READ prompt NOTIFY promptChanged) 0021 Q_PROPERTY(QString promptForSecret READ promptForSecret NOTIFY promptForSecretChanged) 0022 0023 Q_PROPERTY(QString infoMessage READ infoMessage NOTIFY infoMessageChanged) 0024 Q_PROPERTY(QString errorMessage READ errorMessage NOTIFY errorMessageChanged) 0025 0026 // this property true if any of the authenticators' unlocked properties are true 0027 Q_PROPERTY(bool unlocked READ isUnlocked NOTIFY succeeded) 0028 0029 // this property is a sum of the noninteractive authenticators' flags 0030 Q_PROPERTY(PamAuthenticator::NoninteractiveAuthenticatorTypes authenticatorTypes READ authenticatorTypes NOTIFY authenticatorTypesChanged) 0031 0032 Q_PROPERTY(AuthenticatorsState state READ state NOTIFY stateChanged) 0033 0034 public: 0035 PamAuthenticators(std::unique_ptr<PamAuthenticator> &&interactive, 0036 std::vector<std::unique_ptr<PamAuthenticator>> &&noninteractive, 0037 QObject *parent = nullptr); 0038 ~PamAuthenticators() override; 0039 0040 enum AuthenticatorsState { 0041 Idle, 0042 Authenticating, 0043 }; 0044 Q_ENUM(AuthenticatorsState) 0045 0046 AuthenticatorsState state() const; 0047 Q_SIGNAL void stateChanged(); 0048 Q_INVOKABLE void startAuthenticating(); 0049 Q_INVOKABLE void stopAuthenticating(); 0050 0051 // these properties delegate to the interactive authenticator 0052 bool isBusy() const; 0053 Q_SIGNAL void busyChanged(); 0054 0055 QString prompt() const; 0056 Q_SIGNAL void promptChanged(); 0057 QString promptForSecret() const; 0058 Q_SIGNAL void promptForSecretChanged(); 0059 QString infoMessage() const; 0060 Q_SIGNAL void infoMessageChanged(); 0061 QString errorMessage() const; 0062 Q_SIGNAL void errorMessageChanged(); 0063 0064 // these delegate to interactive authenticator 0065 Q_INVOKABLE void respond(const QByteArray &response); 0066 Q_INVOKABLE void cancel(); 0067 0068 // this property is true if any of the authenticators' unlocked properties are true 0069 bool isUnlocked() const; 0070 Q_SIGNAL void succeeded(); 0071 0072 PamAuthenticator::NoninteractiveAuthenticatorTypes authenticatorTypes() const; 0073 Q_SIGNAL void authenticatorTypesChanged(); 0074 0075 Q_SIGNAL void failed(PamAuthenticator::NoninteractiveAuthenticatorTypes what, PamAuthenticator *authenticator); 0076 Q_SIGNAL void noninteractiveError(PamAuthenticator::NoninteractiveAuthenticatorTypes what, PamAuthenticator *authenticator); 0077 Q_SIGNAL void noninteractiveInfo(PamAuthenticator::NoninteractiveAuthenticatorTypes what, PamAuthenticator *authenticator); 0078 0079 private: 0080 struct Private; 0081 QScopedPointer<Private> d; 0082 0083 // convenience internal function for setting state, 0084 // should not be exposed to outsiders 0085 void setState(AuthenticatorsState state); 0086 };