Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

rest api basic authorization via java http.client stopped working when upgrading confluence

Javier Perez
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 28, 2019

We've upgraded from confluence 6.6 to 6.15.1

Issue

We're using following code to run REST API calls within a java app

String cred = java.util.Base64.getEncoder().encodeToString(("usr:passwd").getBytes());
HttpGet httpget = new HttpGet(restApiQuery);
httpget.addHeader("Authorization: Basic ", cred);
httpclient.execute(httpget);

 This used to work in 6.6, however this is throwing an error in 6.15.1

<!doctype html><html lang="en"><head><title>HTTP Status 500 \u2013 Internal Server Error</title><style type="text/css">h1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} h2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} h3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} body {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} b {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} p {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;} a {color:black;} a.name {color:black;} .line {height:1px;background-color:#525D76;border:none;}</style></head><body><h1>HTTP Status 500 \u2013 Internal Server Error</h1><hr class="line" /><p><b>Type</b> Exception Report</p><p><b>Message</b> Illegal base64 character 3a</p><p><b>Description</b> The server encountered an unexpected condition that prevented it from fulfilling the request.</p><p><b>Exception</b></p><pre>java.lang.IllegalArgumentException: Illegal base64 character 3a
java.util.Base64$Decoder.decode0(Base64.java:714)
java.util.Base64$Decoder.decode(Base64.java:526)
java.util.Base64$Decoder.decode(Base64.java:549)
com.atlassian.seraph.util.SecurityUtils.decodeBasicAuthorizationCredentials(SecurityUtils.java:49)
com.atlassian.seraph.auth.DefaultAuthenticator.getUserFromBasicAuthentication(DefaultAuthenticator.java:510)
com.atlassian.crowd.integration.seraph.CrowdAuthenticator.checkAuthenticated(CrowdAuthenticator.java:296)
com.atlassian.crowd.integration.seraph.CrowdAuthenticator.getUser(CrowdAuthenticator.java:397)
com.atlassian.confluence.user.ConfluenceCrowdSSOAuthenticator.lambda$getUser$3(ConfluenceCrowdSSOAuthenticator.java:102)
....

I've notice that the encoding includes character = which apparently is for padding (for the sake of testing I also encoded user:passwd with withoutPadding, with no effect

Question

How to fix this?

1 answer

1 accepted

0 votes
Answer accepted
Javier Perez
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 29, 2019

The header was badly constructed, it should be

httpget.addHeader("Authorization", "Basic " + cred);

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events