Unable to Add Confluence as A Trusted Application
Symptoms
Adding Confluence to JIRA as a trusted application fails. Visiting http://<confluence url>/admin/appTrustCertificate produces the following stack trace:
java.lang.NullPointerException
org.apache.commons.codec.digest.DigestUtils.md5(DigestUtils.java:86)
com.atlassian.confluence.security.trust.DefaultTrustedApplicationsManager.getAliasForSid(DefaultTrustedApplicationsManager.java:141)
com.atlassian.confluence.security.trust.DefaultTrustedApplicationsManager.getSystemAlias(DefaultTrustedApplicationsManager.java:135)
com.atlassian.confluence.security.trust.DefaultTrustedApplicationsManager.getCurrentApplication(DefaultTrustedApplicationsManager.java:115)
sun.reflect.GeneratedMethodAccessor1001.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:585)
java.lang.NullPointerException
at com.atlassian.confluence.applinks.ConfluenceInternalHostApplication.getId(ConfluenceInternalHostApplication.java:212)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at com.atlassian.plugin.osgi.hostcomponents.impl.DefaultComponentRegistrar$ContextClassLoaderSettingInvocationHandler.invoke(DefaultComponentRegistrar.java:129)
at $Proxy154.getId(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
Diagnosis
When going to Confluence license key panel, the Server ID looks like:
Server ID $action.serverId
Cause
Trusted application works by retrieving a Public Key from the application it's going to trust. In this case, Confluence failed to produce a public key because it does not have a server id in the database.
Resolution
First Step: Restore the Server ID
You will need to retrieve the server ID from <confluence data>/confluence.cfg.xml
into the database. This can be done by executing a java script from CONF-10576.
Please follow the instruction here (applies for Confluence 3.x as well).
Second Step: Initialize KEYSTORE table in Confluence database
Newer Confluence versions (7.19.X and 8.5.X) do no longer allow JSP files to be loaded from the <confluence-install-dir>. Hence, you need to follow the steps in CONFSERVER-93646 - Getting issue details... STATUS for this resolution.
- Download a JSP file called initKeyStore_2_10.jsp from CONF-11074. Despite its name, it works with Confluence 3.x.
- Place it in your
<confluence install>/confluence/admin
folder - Restart Confluence
- Open a browser to
http://<confluence url>/admin/initKeyStore_2_10.jsp
- Click on the 'Proceed' button
Confirm by visiting http://<confluence url>/admin/appTrustCertificate. Some text with an encoded key should appear, rather than the stacktrace above.
If you are running on Confluence 4 and later, you may instead download a JSP file called initKeyStore_4_2.jsp from CONF-11074 and follow the same instructions above.