Commit 6e9543c2 authored by Rustam Lotsmanenko (EPAM)'s avatar Rustam Lotsmanenko (EPAM)
Browse files

Fix service gaps

parent 5bd8d981
......@@ -35,7 +35,7 @@
<dependency>
<groupId>org.opengroup.osdu</groupId>
<artifactId>os-core-common</artifactId>
<version>0.0.18</version>
<version>0.3.8</version>
</dependency>
<dependency>
......
package org.opengroup.osdu.search.provider.reference.di;
import static org.opengroup.osdu.search.provider.reference.provider.persistence.ElasticRepositoryReference.SEARCH_DATABASE;
import com.google.gson.Gson;
import com.mongodb.client.FindIterable;
import com.mongodb.client.MongoCollection;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import org.bson.Document;
import org.bson.types.ObjectId;
import org.opengroup.osdu.core.common.cache.ICache;
import org.opengroup.osdu.core.common.model.tenant.TenantInfo;
import org.opengroup.osdu.core.common.provider.interfaces.ITenantFactory;
import org.opengroup.osdu.search.provider.reference.model.TenantInfoDocument;
import org.opengroup.osdu.search.provider.reference.provider.persistence.MongoDdmsClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -23,7 +23,8 @@ import org.springframework.stereotype.Component;
public class TenantFactoryImpl implements ITenantFactory {
private static final Logger LOG = LoggerFactory.getLogger(TenantFactoryImpl.class);
public static final String TENANT_INFO = "TenantInfo";
public static final String TENANT_INFO = "tenantinfo";
public static final String MAIN_DATABASE = "main";
@Autowired
private MongoDdmsClient mongoClient;
......@@ -62,23 +63,18 @@ public class TenantFactoryImpl implements ITenantFactory {
private void initTenants() {
this.tenants = new HashMap<>();
MongoCollection<Document> mongoCollection = mongoClient
.getMongoCollection(SEARCH_DATABASE, TENANT_INFO);
.getMongoCollection(MAIN_DATABASE, TENANT_INFO);
FindIterable<Document> results = mongoCollection.find();
if (Objects.isNull(results) && Objects.isNull(results.first())) {
LOG.error(String.format("Collection \'%s\' is empty.", results));
}
for (Document document : results) {
TenantInfoDocument tenantInfoDocument = new Gson()
.fromJson(document.toJson(), TenantInfoDocument.class);
TenantInfo tenantInfo = convertToTenantInfo(tenantInfoDocument);
TenantInfo tenantInfo = new Gson().fromJson(document.toJson(),TenantInfo.class);
ObjectId id = (ObjectId) document.get("_id");
tenantInfo.setId((long) id.getCounter());
tenantInfo.setCrmAccountIds((ArrayList<String>) document.get("crmAccountID"));
this.tenants.put(tenantInfo.getName(), tenantInfo);
}
}
private TenantInfo convertToTenantInfo(TenantInfoDocument tenantInfoDocument) {
TenantInfo tenantInfo = new TenantInfo();
tenantInfo.setName(tenantInfoDocument.getId());
return tenantInfo;
}
}
......@@ -40,7 +40,7 @@ public class ElasticRepositoryReference implements IElasticRepository {
private static final Logger logger = LoggerFactory.getLogger(ElasticRepositoryReference.class);
public static final String SEARCH_STORAGE = "SearchSettings";
public static final String SEARCH_DATABASE = "search";
public static final String SEARCH_DATABASE = "local";
@Override
public ClusterSettings getElasticClusterSettings(TenantInfo tenantInfo) {
......@@ -57,7 +57,7 @@ public class ElasticRepositoryReference implements IElasticRepository {
Document record = (Document) collection.find(eq("_id", settingId)).first();
if (Objects.isNull(record)) {
logger.warn(settingId + " credentials not found at database.");
return new ClusterSettings(ELASTIC_HOST, Integer.parseInt(ELASTIC_PORT), ELASTIC_USER_PASSWORD, true, false);
return new ClusterSettings(ELASTIC_HOST, Integer.parseInt(ELASTIC_PORT), ELASTIC_USER_PASSWORD, false, false);
}
ElasticSettingsDoc elasticSettingsDoc = new Gson()
......
package org.opengroup.osdu.search.provider.reference.security;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity httpSecurity) throws Exception {
httpSecurity
.httpBasic().disable()
.csrf().disable(); //disable default authN. AuthN handled by endpoints proxy
}
}
\ No newline at end of file
......@@ -47,4 +47,6 @@ ENVIRONMENT=dev
REDIS_GROUP_HOST=${REDIS_GROUP_HOST}
REDIS_STORAGE_HOST=${REDIS_STORAGE_HOST}
REDIS_SEARCH_HOST=${REDIS_SEARCH_HOST}
REDIS_SEARCH_PORT=${REDIS_SEARCH_PORT}
\ No newline at end of file
REDIS_SEARCH_PORT=${REDIS_SEARCH_PORT}
AUTHORIZE_API=${AUTHORIZE_API}
\ No newline at end of file
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