Configuring Basic Authentication by using the Broker Connection Descriptor
Use the awSetDescriptorAuthInfo function to enable basic authentication for your C client, prior to creating a Broker client. When a BrokerConnectionDescriptor is created, the authentication information will be set to null by default. Therefore, you must use the awSetDescriptorAuthInfo function before creating a Broker client if you want to enable basic authentication.
Function Signature | Description |
BrokerError awSetDescriptorAuthInfo(BrokerConnectionDescriptor desc,const char *auth_username,const char *auth_password); |
| Sets the basic authentication information, that is user name and password on the specified Broker connection descriptor. desc is the Broker connection descriptor on which you want to set the basic authentication user name and password. auth_username is the user name for basic authentication. auth_password is the password for the basic authentication user. |
BrokerError awGetDescriptorAuthUserName(BrokerConnectionDescriptor desc,char **user_name); |
| Returns the user name of the basic authentication user available in the specified Broker connection descriptor. desc is the Broker connection descriptor from which you want to get the basic authentication user name. user_name is the basic authentication user name. |
The following code sample shows how to configure the basic authentication settings for Broker using the awSetDescriptorAuthInfo function, passing in the arguments described in the table above.
char *broker_host = "localhost";
char *broker_name = NULL;
char *basic_auth_username = "";
char *basic_auth_password = "";
BrokerConnectionDescriptor br_cdesc;
BrokerClient client;
BrokerError err;
/* Create a Broker connection descriptor*/
br_cdesc = awNewBrokerConnectionDescriptor();
/* Set the basic authentication user neame and password in the
* Broker connection descriptor
* br_cdesc - The Broker connection descriptor on which
* you want to set the basic authentication user name and password.
* basic_auth_username - The basic authentication user name to be set
* on the br_cdesc.
* basic_auth_password - The basic authentication password to be set
* on the br_cdesc.
*/
err = awSetDescriptorAuthInfo(br_cdesc, basic_auth_username,
basic_auth_password);
/* Create a new Broker client using the basic authentication settings
* defined in the Broker connection descriptor
* broker_host - The name of the host running the Broker that the
* new Broker client will use.
* broker_name - The name of the Broker to which the new Broker client will
* be connected.
* client_id - A string containing a unique identifier for the
* new Broker client to be used when disconnecting or reconnecting.
* client_group - The name of the client group for the new Broker client.
* app_name - The name of the application that will contain the
* new Broker client.
* br_cdesc - The Broker connection descriptor to be used by the
* new Broker client.
* client - A pointer to the newly created BrokerClient.
*/
err = awNewBrokerClient(broker_host, broker_name, client_id,
client_group, app_name, br_cdesc, &client);