Jira throws error user exists but has no unique key mapping on login

Still need help?

The Atlassian Community is here for you.

Ask the community


Problem

Login attempts into JIRA fail with the following error, 'User exists but has no unique key mapping'

Symptoms 1

  • Login to JIRA fails after upgrade to JIRA 6.x;
  • JIRA Agile (Greenhopper) upgrades fail to complete;

The following appears in the atlassian-jira.log whan an affected user tries to login.

java.lang.IllegalStateException: User 'xxxx' exists but has no unique key mapping.
	at com.atlassian.jira.user.util.DefaultUserManager.getUserByName(DefaultUserManager.java:262)
	at com.atlassian.jira.security.login.JiraSeraphAuthenticator.getUser(JiraSeraphAuthenticator.java:36)
	at com.atlassian.seraph.auth.DefaultAuthenticator.login(DefaultAuthenticator.java:101)
	at com.atlassian.seraph.filter.PasswordBasedLoginFilter.runAuthentication(PasswordBasedLoginFilter.java:127)

The below appears during a GreenHopper upgrade.

2013-08-05 17:45:50,034 http-bio-8090-exec-14 ERROR potatobake 1065x2431x1 b4cq2t 192.168.131.14 /rest/plugins/1.0/com.pyxis.greenhopper.jira-key [sal.core.upgrade.PluginUpgrader] Upgrade failed: null
java.lang.NullPointerException
	at com.atlassian.greenhopper.upgrade.GhUpgradeTask003.movePreferencesToSettings(GhUpgradeTask003.java:90)
	at com.atlassian.greenhopper.upgrade.GhUpgradeTask003.doUpgrade(GhUpgradeTask003.java:63)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)

The below message can also appear in other logs for operations that require a login.

com.atlassian.jira.util.dbc.Assertions$NullArgumentException :key should not be null!

Symptoms 2

Login to JIRA fails after upgrade to JIRA 7.x;

The following error is shown in JIRA's UI when user tries to enter license:

Cause
Referer URL: http://192.168.178.30:1337/secure/ConfirmNewInstallationWithOldLicense.jspa
java.lang.IllegalStateException: User 'vicky' has no unique key mapping.
java.lang.IllegalStateException: User 'vicky' has no unique key mapping.
        at com.atlassian.jira.user.ApplicationUsers.from(ApplicationUsers.java:46) [classes/:?]
        at com.atlassian.jira.web.action.admin.ConfirmNewInstallationWithOldLicense.getCrowdUser(ConfirmNewInstallationWithOldLicense.java:229) [classes/:?]
        at com.atlassian.jira.web.action.admin.ConfirmNewInstallationWithOldLicense.doValidation(ConfirmNewInstallationWithOldLicense.java:197) [classes/:?]

Symptoms 3

Searching some user in the project roles but hit into the following errors:

2016-09-16 12:26:42,144 http-nio-8080-exec-5 ERROR xxxx xxx xxxxxx xx.x.x.x /rest/api/2/groupuserpicker [c.a.j.rest.exception.ExceptionInterceptor] Returning internal server error in response
java.lang.reflect.InvocationTargetException
...
Caused by: java.lang.IllegalStateException: User 'xxxx' has no unique key mapping. 

Symptoms 4

Searching for a user in any User Picker field will pop-up an error 'The JIRA server was contacted but has returned an error response. We are unsure of the result of this operation' as shown below:

With stack trace inside atlassian-jira.log

2016-11-09 15:27:22,469 http-nio-8723-exec-10 ERROR admin 927x6717x1 1h7zv5i 10.60.6.142 /rest/api/1.0/users/picker [c.a.p.r.c.error.jersey.ThrowableExceptionMapper] Uncaught exception thrown by REST service: User 'Usersatu' has no unique key mapping.
java.lang.IllegalStateException: User 'Usersatu' has no unique key mapping.
	at com.atlassian.jira.user.ApplicationUsers.from(ApplicationUsers.java:46)
	at com.atlassian.jira.user.ApplicationUsers.from(ApplicationUsers.java:143)
	at com.atlassian.jira.bc.user.search.DefaultUserPickerSearchService$ApplicationUserResultType.convertCrowdResults(DefaultUserPickerSearchService.java:689)


Cause

Cause 1

JIRA 6.0 introduced the "Rename User" feature which added a new app_user table to store the user name mappings. The failure reported here appears to be caused by an error during an upgrade task, which was tracked in the below bug report.

JRA-33557 - Getting issue details... STATUS

This can also be caused if any modification to data in either the app_user or the cwd_user tables was made directly on JIRA's database.

Cause 2

The user cache is not flushed successfully. 

Cause for Symptoms 4

It is a bug which will happen when renaming a username with Mixed Case. The bug in mention is  JRA-63109 - Getting issue details... STATUS  with a workaround inside the bug report.

Workaround

Cause 1

Always back up your data before performing any modification to the database. If possible, try your modifications on a test server.

  1. Stop JIRA;
  2. Execute the below SQL to identify the problematic user/s;

    SELECT
        lower_user_name
    FROM
        cwd_user
    WHERE
        lower_user_name NOT IN (
            SELECT lower_user_name FROM app_user
    );

    Postgres: If you have a large number of users and the above query is non performant, try this:

    SELECT u.lower_user_name FROM cwd_user u WHERE NOT EXISTS (SELECT a.lower_user_name FROM app_user a where u.lower_user_name = a.lower_user_name);

    Additionally, sometimes the atlassian-jira.log will show the name of users affected by the problem in the aforementioned errors . For example: "User 'problem.user' has no unique key mapping" can indicate a user that is contributing to this problem. If the preceding query does not return any results, looking for the errors in your logs might also yield problematic usernames.

    The query above does not work? Click here...

    As pointed out in the comments, the statement may not work on MySQL DBMS, in that case run the below instead.


    SELECT
        lower_user_name
    FROM
        cwd_user
    WHERE
        BINARY lower_user_name NOT IN (
            SELECT BINARY lower_user_name FROM app_user
    );
  3. Check if the user(s) retrieved with the query above have an existing entry;

    SELECT * FROM app_user WHERE lower_user_name = '<username_identified>' OR user_key = '<username_identified>';

    If the username already has an entry, update that entry so that both user_key and lower_user_name values match the expected username instead of adding a new entry with the step below.

    (In a later Jira version where user_key has value like JIRAUSER10200, update the entry so that lower_user_name in app_user table matches the lower_user_name in cwd_user table)

  4. Execute the appropriate SQL query below,  replacing <username_identified> with the affected username; 

    PostgreSQL
    INSERT INTO app_user 
    VALUES (
    	(SELECT max(id) + 1 FROM app_user),
    	'username_identified',
    	'username_identified'
    ); 
    
    # The below query only applies to JIRA 6.1 and above, in order to 
    update the sequence value and ensure we don't get duplicate ID's. 
    If above version 6.1, you'll run this query after the first query 
    has added the user to the 'app_user' table.

    UPDATE sequence_value_item 
    SET seq_id = (SELECT max(id) FROM app_user) + 10 
    WHERE seq_name = 'ApplicationUser';
    MySQL
    INSERT INTO app_user 
    SELECT (max(id) + 1),
        'username_identified',
        'username_identified'
    FROM app_user;

    # The below query only applies to JIRA 6.1 and above, in order to 
    update the sequence value and ensure we don't get duplicate ID's. 
    If above version 6.1, you'll run this query after the first query 
    has added the user to the 'app_user' table.

    UPDATE SEQUENCE_VALUE_ITEM 
    SET seq_id = (SELECT max(id) FROM app_user) + 10 
    WHERE seq_name = 'ApplicationUser'; 
    SQL Server
    # Fetch the ID to use. This ID will be used in the next SQL query.
    SELECT max(id) FROM app_user;
     
    INSERT INTO app_user 
    VALUES ('<id from previous query + 1>',
           'username_identified', 
           'username_identified');
     
    # The below query only applies to JIRA 6.1 and above, in order to 
    update the sequence value and ensure we don't get duplicate ID's. 
    If above version 6.1, you'll run this query after the first query 
    has added the user to the 'app_user' table.

    UPDATE sequence_value_item 
    SET seq_id = <id from previous query + 10> 
    WHERE seq_name = 'ApplicationUser';
    Oracle

    INSERT INTO app_user 

    VALUES (
    	(SELECT ( max(id) + 1 ) from app_user), 
    	'username_identified', 
    	'username_identified'
    );
     
    # The below query only applies to JIRA 6.1 and above, in order to 
    update the sequence value and ensure we don't get duplicate ID's. 
    If above version 6.1, you'll run this query after the first query 
    has added the user to the 'app_user' table.

    UPDATE sequence_value_item 
    SET seq_id=(SELECT ((MAX(id)+10)) FROM app_user) 
    WHERE seq_name = 'ApplicationUser';	
     
    # commit the changes
    COMMIT;

    In case the above query does not return any results and JIRA is integrated with a LDAP server or Crowd, there could be a similar user mapping problem with installing/upgrading JIRA Agile. Then, the workaround is to add a Internal Directory user, disable the external User Directory and try installing JIRA Agile again.

  5. Start JIRA.
  6. Test by logging in as that user or re-enabling the JIRA Agile plugin, so the upgrade tasks fire again;

Second Workaround for Cause 1

There can be 2 workarounds for the error after entering the license:

1)

  • Please chose to start with ”Evaluation Terms”
  • Create a new Evaluation License and proceed to access your JIRA.

  • Please navigate to *Versions and Licensing* page (Type {{gg}} and enter {{Versions and Licensing}} to access the page).

  • Enter you JIRA's commercial license key.

or

2) Insert your JIRA's license directly to your JIRA's database by following instruction from here.

Workaround for Cause 2 and Symptom 3

Refresh the User's Cache

  1. Restarting Jira will clear the user's cache and recreate it once the application is started again.
    (info) If you have a Data Center installation, all Nodes must be stopped and then started one by one, otherwise the problematic cache can be replicated back to the starting Nodes.
  2. Alternatively, the following Endpoint can delete the existing cache and recreate without needing to restart:

    curl -v -X DELETE -u username:password https://base.url/rest/internal/1.0/cache/app

    (info) Make sure to run the DELETE outside of business hours to avoid any user impact, and adjust to command with your Instance base URL and any admin user account and password.



Workaround for Symptoms 4

Upgrade to the bug fix version 7.2.6. Otherwise:

Workaround

  • Rename the user twice to a temporary username that had all lowercase character and then to the desired username. For example: _userOne > oneuser > userone_
  • Restart JIRA

Resolution

JIRA Portfolio

For errors from JIRA Portfolio, the problem is tracked at the below bug report. For now, the workaround steps above are necessary.

JPO-105 - Getting issue details... STATUS

JIRA Agile

Errors on JIRA Agile (GreenHopper), were resolved on JIRA 6.1 and above, as described on the below bug report.

JRA-33557 - Getting issue details... STATUS

DescriptionLogin attempts into JIRA fail with the following error, 'User exists but has no unique key mapping'
ProductJira
PlatformServer



Last modified on Sep 2, 2021

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.