Commit e48fc5c8 authored by Dmitriy Novikov's avatar Dmitriy Novikov
Browse files

Fixed TenantInfo initialization

parent 10d9b4e4
......@@ -18,6 +18,7 @@
package org.opengroup.osdu.indexer.di;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.opengroup.osdu.core.common.model.http.AppException;
import org.opengroup.osdu.core.common.model.tenant.TenantInfo;
import org.opengroup.osdu.core.common.provider.interfaces.ITenantFactory;
......@@ -31,9 +32,9 @@ import org.springframework.stereotype.Component;
* Prototype spring bean overriding @RequestScope TenantInfoFactory
*/
@Component("gcpTenantInfoFactory")
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
@Primary
@RequiredArgsConstructor
@Slf4j
public class TenantInfoFactory implements FactoryBean<TenantInfo> {
private final ITenantFactory tenantFactory;
......@@ -41,6 +42,11 @@ public class TenantInfoFactory implements FactoryBean<TenantInfo> {
public TenantInfo getObject() throws Exception {
String id = headers.getDataPartitionIdAtomic().get();
if (id == null) {
log.error("`data-partition-id` is not set. TenantInfo can't be fetched. Stub provided");
return new TenantInfo();
}
TenantInfo tenantInfo = this.tenantFactory.getTenantInfo(id);
if (tenantInfo == null) {
throw AppException.createUnauthorized(
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment