diff --git a/include/login.h b/include/login.h index b82c7a95..ee4927f5 100644 --- a/include/login.h +++ b/include/login.h @@ -27,6 +27,12 @@ namespace AMQP { class Login { private: + /** + * The login mechanism + * @var LoginMechanism + */ + LoginMechanism _mechanism; + /** * The username * @var string @@ -41,10 +47,19 @@ class Login public: + /** + * Login mechanism enum + */ + typedef enum + { + LOGIN_PLAIN, + LOGIN_EXTERNAL + } LoginMechanism; + /** * Default constructor */ - Login() : _user("guest"), _password("guest") {} + Login() : _mechanism(LOGIN_PLAIN), _user("guest"), _password("guest") {} /** * Constructor @@ -52,7 +67,12 @@ class Login * @param password */ Login(std::string user, std::string password) : - _user(std::move(user)), _password(std::move(password)) {} + Login(), _user(std::move(user)), _password(std::move(password)) {} + + /** + * Constructor for EXTERNAL mechanism + */ + Login(LoginMechanism mechanism) : Login(), _mechanism(mechanism) {} /** * Destructor @@ -77,17 +97,38 @@ class Login return _password; } + /** + * Retrieve login mechanism string representation + * @return LoginMechanism + */ + std::string mechanismRepr() const + { + switch (_mechanism) + { + case LOGIN_PLAIN: + return "PLAIN"; + case LOGIN_EXTERNAL: + return "EXTERNAL"; + default: + return ""; + } + } + /** * String representation in SASL PLAIN mode * @return string */ - std::string saslPlain() const + std::string stringRepr() const { // we need an initial string std::string result("\0", 1); - // append other elements - return result.append(_user).append("\0",1).append(_password); + if (_mechanism == LOGIN_PLAIN) { + // append login and password info for plain login + return result.append(_user).append("\0",1).append(_password); + } + + return result; } }; diff --git a/src/connectionstartframe.h b/src/connectionstartframe.h index a8a08689..8d3c30c4 100644 --- a/src/connectionstartframe.h +++ b/src/connectionstartframe.h @@ -203,8 +203,9 @@ class ConnectionStartFrame : public ConnectionFrame // move connection to handshake mode connection->setProtocolOk(); - // send back a connection start ok frame - connection->send(ConnectionStartOKFrame(properties, "PLAIN", connection->login().saslPlain(), "en_US")); + // send back a connection start ok frame with authentication data + connection->send(ConnectionStartOKFrame(properties, connection->login().mechanismRepr(), + connection->login().stringRepr(), "en_US")); // done return true;