You could have multiple repositories configured in your .repo file, or even have multiple .repo files each containing the same baseURL with different credentials.
An example .repo file would look like this:
YUM aggregates all repository configurations in all .repo files under /etc/yum.repos.d/ so all these repositories will be available to YUM.
When you want to install an RPM package using a specific user's credentials, you need to disable all repositories and enable only the one relevant to that user, for example:
yum --disablerepo="*" --enablerepo="user2" install ant
In this example, YUM will search and install (if available) ant from a local yum repository in Artifactory using the credentials provided in the 'user2' repository configuration in your .repo file.