Skip to content
Snippets Groups Projects
Commit 0de61aab authored by Zhibin Mai's avatar Zhibin Mai
Browse files

Merge branch 'add_bearer_prefix' into 'master'

Insert token prefix 'Bearer ' when it is missed

See merge request !547
parents dca02fff 47a70891
No related branches found
No related tags found
1 merge request!547Insert token prefix 'Bearer ' when it is missed
Pipeline #189688 failed
...@@ -97,7 +97,7 @@ public class RequestInfoImpl implements IRequestInfo { ...@@ -97,7 +97,7 @@ public class RequestInfoImpl implements IRequestInfo {
} }
return authHeader; return authHeader;
} else { } else {
return "Bearer " + this.serviceAccountJwtClient.getIdToken(tenantInfo.getName()); return this.serviceAccountJwtClient.getIdToken(tenantInfo.getName());
} }
} }
} }
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
package org.opengroup.osdu.indexer.azure.util; package org.opengroup.osdu.indexer.azure.util;
import com.google.common.base.Strings;
import org.apache.http.HttpStatus; import org.apache.http.HttpStatus;
import org.opengroup.osdu.azure.util.AzureServicePrincipleTokenService; import org.opengroup.osdu.azure.util.AzureServicePrincipleTokenService;
import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
...@@ -31,6 +32,7 @@ import javax.inject.Inject; ...@@ -31,6 +32,7 @@ import javax.inject.Inject;
@Component @Component
@RequestScope @RequestScope
public class ServiceAccountJwtClientImpl implements IServiceAccountJwtClient { public class ServiceAccountJwtClientImpl implements IServiceAccountJwtClient {
private final String BEARER = "Bearer";
@Inject @Inject
private ITenantFactory tenantInfoServiceProvider; private ITenantFactory tenantInfoServiceProvider;
...@@ -55,6 +57,10 @@ public class ServiceAccountJwtClientImpl implements IServiceAccountJwtClient { ...@@ -55,6 +57,10 @@ public class ServiceAccountJwtClientImpl implements IServiceAccountJwtClient {
this.dpsHeaders.put(DpsHeaders.USER_EMAIL, tenant.getServiceAccount()); 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 { ...@@ -24,7 +24,7 @@ public class RequestInfoImplTest {
private static String deploymentEnvironmentValue = "LOCAL"; private static String deploymentEnvironmentValue = "LOCAL";
private static String deploymentEnvironmentValueCloud = "CLOUD"; private static String deploymentEnvironmentValueCloud = "CLOUD";
private static String tenant = "tenant1"; 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 expectedToken = "Bearer bearerToken";
private static String partitionId = "opendes"; private static String partitionId = "opendes";
private static String owner = "owner"; private static String owner = "owner";
......
...@@ -26,7 +26,7 @@ import static org.mockito.Mockito.*; ...@@ -26,7 +26,7 @@ import static org.mockito.Mockito.*;
public class ServiceAccountJwtClientImplTest { public class ServiceAccountJwtClientImplTest {
private String partitionId="opendes"; private String partitionId="opendes";
private static String authorizationToken = "authorizationToken"; private static String authorizationToken = "Bearer authorizationToken";
@Mock @Mock
private ITenantFactory tenantInfoServiceProvider; private ITenantFactory tenantInfoServiceProvider;
......
...@@ -115,7 +115,7 @@ public class RequestInfoImpl implements IRequestInfo { ...@@ -115,7 +115,7 @@ public class RequestInfoImpl implements IRequestInfo {
} }
return "Bearer " + authHeader; return "Bearer " + authHeader;
} else { } 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; ...@@ -4,6 +4,7 @@ package org.opengroup.osdu.indexer.ibm.util;
import javax.inject.Inject; import javax.inject.Inject;
import com.google.common.base.Strings;
import org.apache.http.HttpStatus; import org.apache.http.HttpStatus;
import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
import org.opengroup.osdu.core.common.model.http.AppException; import org.opengroup.osdu.core.common.model.http.AppException;
...@@ -18,6 +19,7 @@ import org.springframework.web.context.annotation.RequestScope; ...@@ -18,6 +19,7 @@ import org.springframework.web.context.annotation.RequestScope;
@Component @Component
@RequestScope @RequestScope
public class ServiceAccountJwtClientImpl implements IServiceAccountJwtClient { public class ServiceAccountJwtClientImpl implements IServiceAccountJwtClient {
private final String BEARER = "Bearer";
@Inject @Inject
private ITenantFactory tenantInfoServiceProvider; private ITenantFactory tenantInfoServiceProvider;
...@@ -65,6 +67,9 @@ public class ServiceAccountJwtClientImpl implements IServiceAccountJwtClient { ...@@ -65,6 +67,9 @@ public class ServiceAccountJwtClientImpl implements IServiceAccountJwtClient {
throw new AppException(HttpStatus.SC_INTERNAL_SERVER_ERROR, "Persistence error", "Error generating token", e); 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; return ACCESS_TOKEN;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment