Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This provides a shared authentication object allowing modification of authentication information on the fly. In the future we might want to include locking here for thread safety. This isn't necessary yet. Change-Id: I77f9b901ef466fe7227ceeb9b7326bec7b8a0c1f Reviewed-on: http://review.couchbase.org/66467 Tested-by: buildbot <build@couchbase.com> Reviewed-by: Sergey Avseyev <sergey.avseyev@gmail.com>
- Loading branch information
Showing
13 changed files
with
254 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
#ifndef LCB_AUTH_H | ||
#define LCB_AUTH_H | ||
|
||
#ifdef __cplusplus | ||
namespace lcb { class Authenticator; } | ||
typedef lcb::Authenticator lcb_AUTHENTICATOR; | ||
extern "C" { | ||
#else /* C only! */ | ||
typedef struct lcb_AUTHENTICATOR_Cdummy lcb_AUTHENTICATOR; | ||
#endif | ||
|
||
/** | ||
* @class lcb_AUTHENTICATOR | ||
* | ||
* The lcb_AUTHENTICATOR object allows greater flexibility with regard to | ||
* adding more than a single bucket/password credential pair. It also restores | ||
* the ability to use "true" usernames (though these are not used at present | ||
* yet). | ||
*/ | ||
|
||
/** | ||
* @volatile | ||
* Creates a new authenticator object. You may destroy it using lcbauth_unref(). | ||
* The returned object initially has a refcount of 1. | ||
* | ||
* @return A new authenticator object. | ||
*/ | ||
LIBCOUCHBASE_API | ||
lcb_AUTHENTICATOR * | ||
lcbauth_new(void); | ||
|
||
/** | ||
* Flags to use when adding a new set of credentials to lcbauth_add_pass | ||
*/ | ||
typedef enum { | ||
/** User/Password is administrative; for cluster */ | ||
LCBAUTH_F_CLUSTER = 1<<1, | ||
|
||
/** User is bucket name. Password is bucket password */ | ||
LCBAUTH_F_BUCKET = 1<<2 | ||
} lcbauth_ADDPASSFLAGS; | ||
|
||
/** | ||
* @volatile | ||
* | ||
* Add a set of credentials | ||
* @param auth | ||
* @param user the username (or bucketname, if LCBAUTH_F_BUCKET is passed) | ||
* @param pass the password. If the password is NULL, the credential is removed | ||
* @param flags one of @ref LCBAUTH_F_CLUSTER or @ref LCBAUTH_F_BUCKET. | ||
*/ | ||
LIBCOUCHBASE_API | ||
lcb_error_t | ||
lcbauth_add_pass(lcb_AUTHENTICATOR *auth, const char *user, const char *pass, int flags); | ||
|
||
/** | ||
* @volatile | ||
* | ||
* Gets the global username and password. This is either the lone bucket | ||
* password, or an explicit cluster password. | ||
* @param auth | ||
* @param[out] u Global username | ||
* @param[out] p Global password | ||
*/ | ||
void | ||
lcbauth_get_upass(const lcb_AUTHENTICATOR *auth, const char **u, const char **p); | ||
|
||
|
||
/** | ||
* @private | ||
* | ||
* Get a user/bucket password | ||
* @param auth the authenticator | ||
* @param name the name of the bucket | ||
* @return the password for the bucket, or NULL if the bucket has no password | ||
* (or is unknown to the authenticator) | ||
*/ | ||
const char * | ||
lcbauth_get_bpass(const lcb_AUTHENTICATOR *auth, const char *name); | ||
|
||
/** | ||
* @uncomitted | ||
* Increments the refcount on the authenticator object | ||
* @param auth | ||
*/ | ||
LIBCOUCHBASE_API | ||
void | ||
lcbauth_ref(lcb_AUTHENTICATOR *auth); | ||
|
||
/** | ||
* Decrements the refcount on the authenticator object | ||
* @param auth | ||
*/ | ||
LIBCOUCHBASE_API | ||
void | ||
lcbauth_unref(lcb_AUTHENTICATOR *auth); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
#endif /* LCB_AUTH_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#ifndef LCB_AUTH_PRIV_H | ||
#define LCB_AUTH_PRIV_H | ||
#include <libcouchbase/auth.h> | ||
|
||
#ifdef __cplusplus | ||
#include <string> | ||
#include <map> | ||
|
||
namespace lcb { | ||
class Authenticator { | ||
public: | ||
typedef std::map<std::string,std::string> Map; | ||
const std::string& username() const { return m_username; } | ||
const std::string& password() const { return m_password; } | ||
const Map& buckets() const { return m_buckets; } | ||
Authenticator() : m_refcount(1) {} | ||
|
||
size_t refcount() const { return m_refcount; } | ||
void incref() { ++m_refcount; } | ||
void decref() { if (!--m_refcount) { delete this; } } | ||
lcb_error_t add(const char *user, const char *pass, int flags); | ||
lcb_error_t init(const std::string& username_, const std::string& bucket, | ||
const std::string& password, lcb_type_t conntype); | ||
|
||
private: | ||
// todo: refactor these out | ||
Map m_buckets; | ||
std::string m_username; | ||
std::string m_password; | ||
size_t m_refcount; | ||
}; | ||
} | ||
#endif | ||
#endif /* LCB_AUTH_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.