Switching users on a trusted connection through CLI
You can switch users on an explicit trusted connection through the command line
interface (CLI).
For a description of what it means to switch users using a trusted
connection see the topic in the related links.
Before you begin
- The connection must have been successfully created as an explicit trusted connection.
- The explicit trusted connection must not be in a transaction.
- The trusted context that allowed the explicit trusted connection to be created must be configured to allow switching to the authorization ID you are switching to.
About this task
If you are switching to a user based on a userid and password, follow steps 1 and 2 in the procedure below. If you are switching to a user based on an access token (available as an option starting from Db2® version 11.5.4), follow step 3.
Procedure
What to do next
Note:
- Important: Switching users without supplying a password or access token bypasses the database server’s authentication. Your application must not allow a switch to an authorization ID without a password or access token unless that application has already validated and authenticated that authorization ID. To do otherwise creates a security vulnerability.
- Specifying a NULL value for the SQL_ATTR_TRUSTED_CONTEXT_USERID attribute is equivalent to specifying the trusted context system authorization ID (the user ID used when the explicit trusted connection was created). When the original explicitly connection was established with TOKEN authentication a NULL value will only result in the system authorization ID being sent to the server to switch. This is only appropriate if the system authorization ID is allowed to switch to without authentication.
- Specifying a NULL value for the SQL_ATTR_TRUSTED_CONTEXT_ACCESSTOKEN attribute is equivalent to specifying the trusted context system authorization ID (the user id used when the explicit trusted connection was created) via the original access token. The access token will be authenticated by the server. Use SQL_ATTR_TRUSTED_CONTEXT_USERID if you wish to switch to the trusted context system authorization ID with a NULL value if you want to switch without authentication.
- When you successfully set the value of the SQL_ATTR_TRUSTED_CONTEXT_USERID or SQL_ATTR_TRUSTED_CONTEXT_ACCESSTOKEN connection attribute on an explicit trusted connection the connection is immediately reset. The result of resetting is as if a new connection were created using the original connection attributes of that connection. This reset happens even if the value you set the connection attribute to is the system authorization ID or NULL or the same value that the attribute currently holds.
- If the SQL_ATTR_TRUSTED_CONTEXT_PASSWORD attribute is set, the password will be authenticated during the switch user processing, even if the trusted context that allowed the trusted connection does not require authentication on a switch user for that authorization ID. This results in unnecessary processing time. This rule doesn’t apply to the trusted context system authorization ID. If the trusted context system authorization ID doesn’t require authentication when you switch to it then it is not authenticated even if a password is provided.
- If the SQL_ATTR_TRUSTED_CONTEXT_ACCESSTOKEN attribute is set, the access token will be authenticated during the switch user processing, even if the trusted context that allowed the trusted connection doesn’t require authentication on a switch user for the authorization ID identified by the access token. This results in unnecessary processing time.
- The type of token specified for the SQL_ATTR_TRUSTED_CONTEXT_ACCESSTOKEN attribute must be the same as the type of access token used to establish the original explicit trusted connection for the system authorization ID.
- Do not specify both the SQL_ATTR_TRUSTED_CONTEXT_USERID and SQL_ATTR_TRUSTED_CONTEXT_ACCESSTOKEN attributes at the same time, or it will result in two switch users, as these attributes are independent.