Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SASL EXTERNAL authentication mechanism #93

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 46 additions & 5 deletions include/login.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ namespace AMQP {
class Login
{
private:
/**
* The login mechanism
* @var LoginMechanism
*/
LoginMechanism _mechanism;

/**
* The username
* @var string
Expand All @@ -41,18 +47,32 @@ 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") {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use delegating constructor instead of copy-pasting


/**
* Constructor
* @param user
* @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
Expand All @@ -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;
}
};

Expand Down
5 changes: 3 additions & 2 deletions src/connectionstartframe.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down