1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/media/CredentialManager.h
12 #ifndef ZYPP_MEDIA_CREDENTIALMANAGER_H
13 #define ZYPP_MEDIA_CREDENTIALMANAGER_H
17 #include "zypp/Pathname.h"
18 #include "zypp/media/MediaUserAuth.h"
20 //////////////////////////////////////////////////////////////////////
22 { ////////////////////////////////////////////////////////////////////
26 //////////////////////////////////////////////////////////////////////
28 { ////////////////////////////////////////////////////////////////////
31 //////////////////////////////////////////////////////////////////////
33 // CLASS NAME : CredManagerOptions
36 * \todo configurable cred file locations
38 struct CredManagerOptions
40 CredManagerOptions(const Pathname & rootdir = "");
42 Pathname globalCredFilePath;
43 Pathname userCredFilePath;
44 Pathname customCredFileDir;
46 //////////////////////////////////////////////////////////////////////
48 // comparator for CredentialSet
49 struct AuthDataComparator
51 bool operator()(const AuthData_Ptr & lhs, const AuthData_Ptr & rhs);
54 //////////////////////////////////////////////////////////////////////
56 // CLASS NAME : CredentialManager
59 * \todo better method names
60 * \todo delete(AuthData) method
62 class CredentialManager
65 typedef std::set<AuthData_Ptr, AuthDataComparator> CredentialSet;
66 typedef CredentialSet::size_type CredentialSize;
67 typedef CredentialSet::const_iterator CredentialIterator;
70 CredentialManager(const CredManagerOptions & opts = CredManagerOptions());
77 * Get credentials for the specified \a url.
79 * If the URL contains also username, it will be used to find the match
80 * for this user (in case mutliple are available).
82 * \param url URL to find credentials for.
83 * \return Pointer to retrieved authentication data on success or an empty
84 * AuthData_Ptr otherwise.
85 * \todo return a copy instead?
87 AuthData_Ptr getCred(const Url & url);
90 * Read credentials from a file.
92 AuthData_Ptr getCredFromFile(const Pathname & file);
95 * Add new global credentials.
97 void addGlobalCred(const AuthData & cred);
100 * Add new user credentials.
102 void addUserCred(const AuthData & cred);
105 * Add new credentials with user callbacks.
107 * If the cred->url() contains 'credentials' query parameter, the
108 * credentials will be automatically saved to the specified file using the
109 * \ref saveInFile() method.
111 * Otherwise a callback will be called asking whether to save to custom
112 * file, or to global or user's credentials catalog.
114 * \todo Currently no callback is called, credentials are automatically
115 * saved to user's credentials.cat if no 'credentials' parameter
118 void addCred(const AuthData & cred);
121 * Saves any unsaved credentials added via \ref addUserCred() or
122 * \a addGlobalCred() methods.
127 * Saves given \a cred to global credentials file.
129 * \note Use this method to add just one piece of credentials. To add
130 * multiple items at once, use addGlobalCred() followed
133 void saveInGlobal(const AuthData & cred);
136 * Saves given \a cred to user's credentials file.
138 * \note Use this method to add just one piece of credentials. To add
139 * multiple items at once, use addUserCred() followed
142 void saveInUser(const AuthData & cred);
145 * Saves given \a cred to user specified credentials file.
147 * If the credFile path is absolute, it will be saved at that precise
148 * location. If \a credFile is just a filename, it will be saved
149 * in \ref CredManagerOptions::customCredFileDir. Otherwise the current
150 * working directory will be prepended to the file path.
152 void saveInFile(const AuthData &, const Pathname & credFile);
155 * Remove all global or user credentials from memory and disk.
157 * \param global Whether to remove global or user credentials.
159 void clearAll(bool global = false);
162 CredentialIterator credsGlobalBegin() const;
163 CredentialIterator credsGlobalEnd() const;
164 CredentialSize credsGlobalSize() const;
165 bool credsGlobalEmpty() const;
167 CredentialIterator credsUserBegin() const;
168 CredentialIterator credsUserEnd() const;
169 CredentialSize credsUserSize() const;
170 bool credsUserEmpty() const;
174 RW_pointer<Impl> _pimpl;
176 //////////////////////////////////////////////////////////////////////
179 ////////////////////////////////////////////////////////////////////
181 //////////////////////////////////////////////////////////////////////
182 ////////////////////////////////////////////////////////////////////
184 //////////////////////////////////////////////////////////////////////
186 #endif /* ZYPP_MEDIA_CREDENTIALMANAGER_H */