Skip to content
Snippets Groups Projects
Commit 6bf98657 authored by Zhibin Mai's avatar Zhibin Mai Committed by David Diederich
Browse files

Add prefix 'Bearer' in the return of...

Add prefix 'Bearer' in the return of IServiceAccountJwtClient.getIdToken(String) for Azure and IBM implementation

(cherry picked from commit 20f868bf)
parent 000e26ed
No related branches found
No related tags found
2 merge requests!579Debug preship,!555Cherry-pick 'Insert token prefix 'Bearer ' when it is missed' into release/0.21
Pipeline #189503 skipped
......@@ -97,7 +97,7 @@ public class RequestInfoImpl implements IRequestInfo {
}
return authHeader;
} else {
return "Bearer " + this.serviceAccountJwtClient.getIdToken(tenantInfo.getName());
return this.serviceAccountJwtClient.getIdToken(tenantInfo.getName());
}
}
}
......@@ -14,6 +14,7 @@
package org.opengroup.osdu.indexer.azure.util;
import com.google.common.base.Strings;
import org.apache.http.HttpStatus;
import org.opengroup.osdu.azure.util.AzureServicePrincipleTokenService;
import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
......@@ -31,6 +32,7 @@ import javax.inject.Inject;
@Component
@RequestScope
public class ServiceAccountJwtClientImpl implements IServiceAccountJwtClient {
private final String BEARER = "Bearer";
@Inject
private ITenantFactory tenantInfoServiceProvider;
......@@ -55,6 +57,10 @@ public class ServiceAccountJwtClientImpl implements IServiceAccountJwtClient {
this.dpsHeaders.put(DpsHeaders.USER_EMAIL, tenant.getServiceAccount());
return this.tokenService.getAuthorizationToken();
String token = this.tokenService.getAuthorizationToken();
if(!Strings.isNullOrEmpty(token) && !token.startsWith(BEARER)) {
token = BEARER + " " + token;
}
return token;
}
}
......@@ -24,7 +24,7 @@ public class RequestInfoImplTest {
private static String deploymentEnvironmentValue = "LOCAL";
private static String deploymentEnvironmentValueCloud = "CLOUD";
private static String tenant = "tenant1";
private static String bearerToken = "bearerToken";
private static String bearerToken = "Bearer bearerToken";
private static String expectedToken = "Bearer bearerToken";
private static String partitionId = "opendes";
private static String owner = "owner";
......
......@@ -26,7 +26,7 @@ import static org.mockito.Mockito.*;
public class ServiceAccountJwtClientImplTest {
private String partitionId="opendes";
private static String authorizationToken = "authorizationToken";
private static String authorizationToken = "Bearer authorizationToken";
@Mock
private ITenantFactory tenantInfoServiceProvider;
......
......@@ -115,7 +115,7 @@ public class RequestInfoImpl implements IRequestInfo {
}
return "Bearer " + authHeader;
} else {
return "Bearer " + this.serviceAccountJwtClient.getIdToken(tenantInfo.getName());
return this.serviceAccountJwtClient.getIdToken(tenantInfo.getName());
}
}
......
......@@ -4,6 +4,7 @@ package org.opengroup.osdu.indexer.ibm.util;
import javax.inject.Inject;
import com.google.common.base.Strings;
import org.apache.http.HttpStatus;
import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
import org.opengroup.osdu.core.common.model.http.AppException;
......@@ -18,6 +19,7 @@ import org.springframework.web.context.annotation.RequestScope;
@Component
@RequestScope
public class ServiceAccountJwtClientImpl implements IServiceAccountJwtClient {
private final String BEARER = "Bearer";
@Inject
private ITenantFactory tenantInfoServiceProvider;
......@@ -65,6 +67,9 @@ public class ServiceAccountJwtClientImpl implements IServiceAccountJwtClient {
throw new AppException(HttpStatus.SC_INTERNAL_SERVER_ERROR, "Persistence error", "Error generating token", e);
}
if(!Strings.isNullOrEmpty(ACCESS_TOKEN) && !ACCESS_TOKEN.startsWith(BEARER)) {
ACCESS_TOKEN = BEARER + " " + ACCESS_TOKEN;
}
return ACCESS_TOKEN;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment