2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
11 #include "threads/CriticalSection.h"
21 \brief Password Manager class for saving authentication details
23 Handles access to previously saved passwords for paths, translating normal URLs
24 into authenticated URLs if the user has details about the username and password
25 for a path previously saved. Should be accessed via CPasswordManager::GetInstance()
27 class CPasswordManager
31 \brief The only way through which the global instance of the CPasswordManager should be accessed.
32 \return the global instance.
34 static CPasswordManager
&GetInstance();
37 \brief Authenticate a URL by looking the URL up in the temporary and permanent caches
38 First looks up based on host and share name. If that fails, it will try a match purely
39 on the host name (eg different shares on the same host with the same credentials)
40 \param url a CURL to authenticate
41 \return true if we have details in the cache, false otherwise.
44 bool AuthenticateURL(CURL
&url
);
47 \brief Prompt for a username and password for the particular URL.
49 This routine pops up a dialog, requesting the user enter a username and password
50 to access the given URL. The user may optionally save these details. If saved
51 we write the details into the users profile. If not saved, the details are temporarily
52 stored so that further access no longer requires prompting for authentication.
54 \param url the URL to authenticate.
55 \return true if the user entered details, false if the user cancelled the dialog.
56 \sa CURL, SaveAuthenticatedURL
58 bool PromptToAuthenticateURL(CURL
&url
);
61 \brief Save an authenticated URL.
63 This routine stores an authenticated URL in the temporary cache, and optionally
64 saves these details into the users profile.
66 \param url the URL to authenticate.
67 \param saveToProfile whether to save in the users profile, defaults to true.
68 \sa CURL, PromptToAuthenticateURL
70 void SaveAuthenticatedURL(const CURL
&url
, bool saveToProfile
= true);
73 \brief Is an URL is supported (by the manager)
75 This routine checks that an URL is supported by the manager
77 \param url the URL to check.
78 \return true if the URL is supported
79 \sa CURL, IsURLSupported
81 bool IsURLSupported(const CURL
&url
);
84 \brief Clear any previously cached passwords
89 // private construction, and no assignments; use the provided singleton methods
91 CPasswordManager(const CPasswordManager
&) = delete;
92 CPasswordManager
& operator=(CPasswordManager
const&) = delete;
93 ~CPasswordManager() = default;
97 std::string
GetLookupPath(const CURL
&url
) const;
98 std::string
GetServerLookup(const std::string
&path
) const;
100 std::map
<std::string
, std::string
> m_temporaryCache
;
101 std::map
<std::string
, std::string
> m_permanentCache
;
104 CCriticalSection m_critSection
;